File tree Expand file tree Collapse file tree
main/java/org/baeldung/boot
test/java/org/baeldung/boot Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import org .springframework .stereotype .Component ;
77
88@ Component
9- public class FooComponent {
9+ public class FooService {
1010
1111 @ Autowired
1212 private FooRepository fooRepository ;
Original file line number Diff line number Diff line change 11package org .baeldung .boot .service ;
22
3- import org .baeldung .boot .components .FooComponent ;
3+ import org .baeldung .boot .components .FooService ;
44import org .baeldung .boot .model .Foo ;
55import org .springframework .beans .factory .annotation .Autowired ;
66import org .springframework .http .HttpStatus ;
1111import org .springframework .web .bind .annotation .RestController ;
1212
1313@ RestController
14- public class FooService {
14+ public class FooController {
1515
1616 @ Autowired
17- private FooComponent fooComponent ;
17+ private FooService fooService ;
1818
1919 @ GetMapping ("/{id}" )
2020 public ResponseEntity <?> getFooWithId (@ PathVariable Integer id ) throws Exception {
2121
22- Foo foo = fooComponent .getFooWithId (id );
22+ Foo foo = fooService .getFooWithId (id );
2323
2424 return new ResponseEntity <>(foo , HttpStatus .OK );
2525 }
2626
2727 @ GetMapping ("/" )
2828 public ResponseEntity <?> getFooWithName (@ RequestParam String name ) throws Exception {
2929
30- Foo foo = fooComponent .getFooWithName (name );
30+ Foo foo = fooService .getFooWithName (name );
3131
3232 return new ResponseEntity <>(foo , HttpStatus .OK );
3333 }
Original file line number Diff line number Diff line change 11package org .baeldung .boot ;
22
3- import org .baeldung .boot .components .FooComponent ;
3+ import org .baeldung .boot .components .FooService ;
44import org .baeldung .boot .model .Foo ;
55import org .junit .Before ;
66import org .junit .Test ;
@@ -32,15 +32,15 @@ public class FooComponentTests {
3232 private TestRestTemplate testRestTemplate ;
3333
3434 @ SpyBean
35- private FooComponent fooComponent ;
35+ private FooService fooService ;
3636
3737 @ Before
3838 public void init () throws Exception {
3939 Foo foo = new Foo ();
4040 foo .setId (5 );
4141 foo .setName ("MOCKED_FOO" );
4242
43- doReturn (foo ).when (fooComponent ).getFooWithId (anyInt ());
43+ doReturn (foo ).when (fooService ).getFooWithId (anyInt ());
4444
4545 // doCallRealMethod().when(fooComponent).getFooWithName(anyString());
4646 }
You can’t perform that action at this time.
0 commit comments