11package com .baeldung .protobuf ;
22
3- import java .util .ArrayList ;
4- import java .util .Arrays ;
5- import java .util .HashMap ;
6- import java .util .List ;
7- import java .util .Map ;
8-
3+ import com .baeldung .protobuf .BaeldungTraining .Course ;
4+ import com .baeldung .protobuf .BaeldungTraining .Student ;
5+ import com .baeldung .protobuf .BaeldungTraining .Student .PhoneNumber ;
6+ import com .baeldung .protobuf .BaeldungTraining .Student .PhoneType ;
97import org .springframework .boot .autoconfigure .SpringBootApplication ;
108import org .springframework .context .annotation .Bean ;
119import org .springframework .http .converter .protobuf .ProtobufHttpMessageConverter ;
1210import org .springframework .web .client .RestTemplate ;
1311
14- import com .baeldung .protobuf .BaeldungTraining .Course ;
15- import com .baeldung .protobuf .BaeldungTraining .Student ;
16- import com .baeldung .protobuf .BaeldungTraining .Student .PhoneNumber ;
17- import com .baeldung .protobuf .BaeldungTraining .Student .PhoneType ;
12+ import java .util .ArrayList ;
13+ import java .util .Arrays ;
14+ import java .util .HashMap ;
15+ import java .util .List ;
16+ import java .util .Map ;
1817
1918@ SpringBootApplication
2019public class Application {
20+
2121 @ Bean
2222 RestTemplate restTemplate (ProtobufHttpMessageConverter hmc ) {
2323 return new RestTemplate (Arrays .asList (hmc ));
@@ -29,21 +29,28 @@ ProtobufHttpMessageConverter protobufHttpMessageConverter() {
2929 }
3030
3131 @ Bean
32- public CourseRepository createDummyCourses () {
33- Map <Integer , Course > dummy = new HashMap <>();
34-
35- Course course1 = Course .newBuilder ().setId (1 ).setCourseName ("REST with Spring" ).addAllStudent (createDummyStudents ()).build ();
36- Course course2 = Course .newBuilder ().setId (2 ).setCourseName ("Learn Spring Security" ).addAllStudent (new ArrayList <Student >()).build ();
37-
38- dummy .put (course1 .getId (), course1 );
39- dummy .put (course2 .getId (), course2 );
40-
41- return new CourseRepository (dummy );
42- }
32+ public CourseRepository createStubCourses () {
33+ Map <Integer , Course > courses = new HashMap <>();
34+
35+ Course course1 = Course .newBuilder ()
36+ .setId (1 )
37+ .setCourseName ("REST with Spring" )
38+ .addAllStudent (createStubStudents ())
39+ .build ();
4340
44- private List <Student > createDummyStudents () {
45- List <Student > studentList = new ArrayList <>();
41+ Course course2 = Course .newBuilder ()
42+ .setId (2 )
43+ .setCourseName ("Learn Spring Security" )
44+ .addAllStudent (new ArrayList <>())
45+ .build ();
46+
47+ courses .put (course1 .getId (), course1 );
48+ courses .put (course2 .getId (), course2 );
49+
50+ return new CourseRepository (courses );
51+ }
4652
53+ private List <Student > createStubStudents () {
4754 PhoneNumber phone1 = createPhone ("123456" , PhoneType .MOBILE );
4855 Student student1 = createStudent (1 , "John" , "Doe" , "john.doe@baeldung.com" , Arrays .asList (phone1 ));
4956
@@ -54,8 +61,7 @@ private List<Student> createDummyStudents() {
5461 PhoneNumber phone3_2 = createPhone ("456789" , PhoneType .LANDLINE );
5562 Student student3 = createStudent (3 , "Jane" , "Doe" , "jane.doe@baeldung.com" , Arrays .asList (phone3_1 , phone3_2 ));
5663
57- studentList .addAll (Arrays .asList (student1 , student2 , student3 ));
58- return studentList ;
64+ return Arrays .asList (student1 , student2 , student3 );
5965 }
6066
6167 private Student createStudent (int id , String firstName , String lastName , String email , List <PhoneNumber > phones ) {
0 commit comments