File tree Expand file tree Collapse file tree 8 files changed +146
-0
lines changed
main/java/guru/springframework/sfgdi
test/java/guru/springframework/sfgdi/controllers Expand file tree Collapse file tree 8 files changed +146
-0
lines changed Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .controllers ;
2+
3+ import guru .springframework .sfgdi .services .GreetingService ;
4+
5+ /**
6+ * Created by jt on 12/26/19.
7+ */
8+ public class ConstructorInjectedController {
9+ private final GreetingService greetingService ;
10+
11+ public ConstructorInjectedController (GreetingService greetingService ) {
12+ this .greetingService = greetingService ;
13+ }
14+
15+ public String getGreeting (){
16+ return greetingService .sayGreeting ();
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .controllers ;
2+
3+ import guru .springframework .sfgdi .services .GreetingService ;
4+
5+ /**
6+ * Created by jt on 12/26/19.
7+ */
8+ public class PropertyInjectedController {
9+
10+ public GreetingService greetingService ;
11+
12+ public String getGreeting (){
13+ return greetingService .sayGreeting ();
14+ }
15+
16+ }
Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .controllers ;
2+
3+ import guru .springframework .sfgdi .services .GreetingService ;
4+
5+ /**
6+ * Created by jt on 12/26/19.
7+ */
8+ public class SetterInjectedController {
9+
10+ private GreetingService greetingService ;
11+
12+ public void setGreetingService (GreetingService greetingService ) {
13+ this .greetingService = greetingService ;
14+ }
15+
16+ public String getGreeting (){
17+ return greetingService .sayGreeting ();
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .services ;
2+
3+ /**
4+ * Created by jt on 12/26/19.
5+ */
6+ public interface GreetingService {
7+
8+ String sayGreeting ();
9+ }
Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .services ;
2+
3+ /**
4+ * Created by jt on 12/26/19.
5+ */
6+ public class GreetingServiceImpl implements GreetingService {
7+ @ Override
8+ public String sayGreeting () {
9+ return "Hello World" ;
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .controllers ;
2+
3+ import guru .springframework .sfgdi .services .GreetingServiceImpl ;
4+ import org .junit .jupiter .api .BeforeEach ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ import static org .junit .jupiter .api .Assertions .*;
8+
9+ class ConstructorInjectedControllerTest {
10+
11+ ConstructorInjectedController controller ;
12+
13+ @ BeforeEach
14+ void setUp () {
15+ controller = new ConstructorInjectedController (new GreetingServiceImpl ());
16+ }
17+
18+ @ Test
19+ void getGreeting () {
20+
21+ System .out .println (controller .getGreeting ());
22+
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .controllers ;
2+
3+ import guru .springframework .sfgdi .services .GreetingServiceImpl ;
4+ import org .junit .jupiter .api .BeforeEach ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ import static org .junit .jupiter .api .Assertions .*;
8+
9+ class PropertyInjectedControllerTest {
10+
11+ PropertyInjectedController controller ;
12+
13+ @ BeforeEach
14+ void setUp () {
15+ controller = new PropertyInjectedController ();
16+
17+ controller .greetingService = new GreetingServiceImpl ();
18+ }
19+
20+ @ Test
21+ void getGreeting () {
22+
23+ System .out .println (controller .getGreeting ());
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package guru .springframework .sfgdi .controllers ;
2+
3+ import guru .springframework .sfgdi .services .GreetingServiceImpl ;
4+ import org .junit .jupiter .api .BeforeEach ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ import static org .junit .jupiter .api .Assertions .*;
8+
9+ class SetterInjectedControllerTest {
10+
11+ SetterInjectedController controller ;
12+
13+ @ BeforeEach
14+ void setUp () {
15+ controller = new SetterInjectedController ();
16+ controller .setGreetingService (new GreetingServiceImpl ());
17+ }
18+
19+ @ Test
20+ void getGreeting () {
21+ System .out .println (controller .getGreeting ());
22+
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments