InstanceMap { public <T> T initialize(T o) { if (!initializing.add(o)) { throw new IllegalArgumentException( "Circular dependency at " + o + ", " + "try defining some properties as `late`"); } ObjectConfig config; try { config = config(o); for (Init i: config.injects) i.init(this); for (Init i: config.inits) i.init(this); if (!config.lateInits.isEmpty() || !config.lateInjects.isEmpty()) { lateInits.add(config); } } catch (IllegalArgumentException e) { if (e.getMessage().endsWith(IS_INITIALIZING)) { throw new IllegalArgumentException( "Circular dependency at " + o + ", " + "try defining some properties as `late`"); } throw e; } finally { initializing.remove(o); if (initializing.isEmpty()) lateInitialize(); } return o; } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})  InstanceMap(); @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  InstanceMap(InstanceMap source); Object put(String key, Object value); Object put(Class<?> clazz, Object value, Class... limit); Object put(Class<?> clazz, Object value); T replace(Class<T> clazz, Object value, Class... limit); T replace(Class<T> clazz, Object value); Object get(String key); T get(Class<T> clazz); T putNew(String key, Factory<? extends T> factory); T putNew(Class<?> clazz, Factory<? extends T> factory); T getOrCreate(String key, Factory<T> factory); T getOrCreate(String key, Class<T> impl); T getOrCreate(Class<T> clazz, Factory<? extends T> factory); T getOrCreate(Class<T> clazz, Class<? extends T> impl); T getOrCreate(Class<T> clazz); T get(Class<T> clazz, Inject inject); Object remove(String key); @SuppressWarnings("unchecked") T remove(Class<T> clazz); @SuppressWarnings("unchecked") T remove(Class<T> clazz, Class... limit); T initialize(T o); static Object getFactory(Class<?> clazz, String factory); static final Class<?> ANY_INTERFACE; static final Class[] NO_LIMIT; static final Class[] LIMIT_NO_INTERFACES; static final Class[] LIMIT_INTERFACES_ONLY; }
@Test public void test_inject_no_create() { InjectFoo iFoo = iMap.initialize(new InjectFoo()); assertThat(iFoo.foo, is(nullValue())); }