/home/wpollock1/public_html/AJava/DIManual/Main.java

package com.wpollock.manualdidemo;

/**
 * The calls to sayHello from main should all throw NullPointerException,
 * since no GreetingService has been injected into any of these objects.
 * In this demo, we are using (abusing actually) JUnit as the DI
 * framework, so we need to run the controllers from a JUnit test and
 * not from here.
 */
public class Main {
    public static void main (String [] args) {
        try {
            PropInjectedController pic = new PropInjectedController();
            pic.sayHello();
        }
        catch (NullPointerException npe) {
            System.out.println("PropInjectedController sayHello threw NPE");
        }

        try {
            SetterInjectedController sic = new SetterInjectedController();
            sic.sayHello();
        }

        catch (NullPointerException npe) {
            System.out.println("SetterInjectedController sayHello threw NPE");
        }

        try {
            ConstructorInjectedController cic = new ConstructorInjectedController(null);
            cic.sayHello();
        }
        catch (NullPointerException npe) {
            System.out.println("ConstructorInjectedController sayHello threw NPE");
        }

    }
}