BeanFactory { public <T> T create(Class<T> instanceClass) { if (instanceClass.isInterface() || Modifier.isAbstract(instanceClass.getModifiers())) throw new Error("instance class must be concrete, class=" + instanceClass.getCanonicalName()); try { T instance = construct(instanceClass); inject(instance); return instance; } catch (ReflectiveOperationException e) { throw new Error(e); } }  void bind(Type type, @Nullable String name, Object instance); Object bean(Type type, String name); T create(Class<T> instanceClass); void inject(T instance);  }
@Test void create() { Dependency1 dependency1 = new Dependency1(); Dependency2<String> dependency2 = new Dependency2<>(); beanFactory.bind(Dependency1.class, null, dependency1); beanFactory.bind(Types.generic(Dependency2.class, String.class), "dep2", dependency2); Bean bean = beanFactory.create(Bean.class); assertThat(bean.dependency1).isSameAs(dependency1); assertThat(bean.dependency2).isSameAs(dependency2); }
@Test void injectStaticMembers() { assertThatThrownBy(() -> beanFactory.create(BeanWithInjectStaticField.class)) .isInstanceOf(Error.class) .hasMessageContaining("static field must not have @Inject"); }