Main.java

Download Main.java

 1: package com.wpollock.manualdidemo;
 2: 
 3: /**
 4:  * The calls to sayHello from main should all throw NullPointerException,
 5:  * since no GreetingService has been injected into any of these objects.
 6:  * In this demo, we are using (abusing actually) JUnit as the DI
 7:  * framework, so we need to run the controllers from a JUnit test and
 8:  * not from here.
 9:  */
10: public class Main {
11:     public static void main (String [] args) {
12:         try {
13:             PropInjectedController pic = new PropInjectedController();
14:             pic.sayHello();
15:         }
16:         catch (NullPointerException npe) {
17:             System.out.println("PropInjectedController sayHello threw NPE");
18:         }
19: 
20:         try {
21:             SetterInjectedController sic = new SetterInjectedController();
22:             sic.sayHello();
23:         }
24: 
25:         catch (NullPointerException npe) {
26:             System.out.println("SetterInjectedController sayHello threw NPE");
27:         }
28: 
29:         try {
30:             ConstructorInjectedController cic = new ConstructorInjectedController(null);
31:             cic.sayHello();
32:         }
33:         catch (NullPointerException npe) {
34:             System.out.println("ConstructorInjectedController sayHello threw NPE");
35:         }
36: 
37:     }
38: }