Service.java
public interface Service { public void test(); }
AService.java
public class AService implements Service { public void test(){ System.out.println("A tested!"); } }
Module.java
import com.google.inject.AbstractModule; public class Module extends AbstractModule { public void configure() { bind(Service.class).to(AService.class); } }
TestGuice.java
import com.google.inject.Guice; import com.google.inject.Injector; import org.junit.Test; public class TestGuice { @Test public void test() { Injector injector = Guice.createInjector(new Module()); Service service = injector.getInstance(Service.class); service.test(); } }