Guicer { public <T> T get(Class<T> serviceClass, ServiceLifecycleActions<?> withActions) { if(!serviceClass.isInterface()) { throw new IllegalArgumentException("Interface required"); } final T instance = _injector.getInstance(serviceClass); return startService(serviceClass, instance, withActions); } private  Guicer(Class<? extends ServiceManagerBase> serviceManagerInterfaceClass, ServiceManagerBase serviceManager,
                   Collection<ServiceBinding> serviceBindings, List<String> priorities,
                   Collection<? extends Module> modules); Collection<Class<?>> directlyRequiredClasses(); void stopAllServices(ServiceLifecycleActions<?> withActions); T get(Class<T> serviceClass, ServiceLifecycleActions<?> withActions); boolean serviceIsStarted(Class<?> serviceClass); boolean isRequired(Class<?> interfaceClass); boolean isBoundTo(Class<?> interfaceClass, Class<?> targetClass); List<?> dependenciesFor(Class<?> rootClass); static Guicer forServices(Collection<ServiceBinding> serviceBindings); static Guicer forServices(Class<M> serviceManagerInterfaceClass,
                                                                    M serviceManager,
                                                                    Collection<ServiceBinding> serviceBindings,
                                                                    List<String> priorities,
                                                                    Collection<? extends Module> modules); List<Class<?>> servicesClassesInStartupOrder();  }
@Test public void singletonNess() throws Exception { Guicer guicer = messageGuicer( bind(DummyInterfaces.Gamma.class, DummySimpleServices.SimpleGamma.class, false) ); guicer.get(DummyInterfaces.Gamma.class, MESSAGING_ACTIONS); guicer.get(DummyInterfaces.Gamma.class, MESSAGING_ACTIONS); assertEquals( "messages", joined( "starting SimpleGamma", "started SimpleGamma" ), Strings.join(DummyInterfaces.messages()) ); }
@Test(expected=IllegalArgumentException.class) public void getRequiresInterface() throws ClassNotFoundException { Guicer guicer = messageGuicer( bind(DummyInterfaces.Alpha.class, DummySimpleServices.SimpleAlpha.class, true), bind(DummyInterfaces.Beta.class, DummySimpleServices.SimpleBeta.class, false), bind(DummyInterfaces.Gamma.class, DummySimpleServices.SimpleGamma.class, false) ); startRequiredServices(guicer); Object a = guicer.get(DummyInterfaces.Alpha.class, MESSAGING_ACTIONS); Object b = guicer.get(DummyInterfaces.Alpha.class, MESSAGING_ACTIONS); assertEquals("two different gets", a, b); guicer.get(DummySimpleServices.SimpleAlpha.class, MESSAGING_ACTIONS); }