use of eu.okaeri.injector.Injector in project okaeri-injector by OkaeriPoland.
the class TestInjector method test_always_provide_last.
@Test
public void test_always_provide_last() {
String string1 = "some value";
String string2 = "new value";
Injector injector = OkaeriInjector.create().registerInjectable("test1", string1).registerInjectable("test1", string2);
Optional<? extends Injectable<String>> injectable = injector.getInjectableExact("test1", String.class);
assertEquals(true, injectable.isPresent());
assertEquals(string2, injectable.get().getObject());
}
use of eu.okaeri.injector.Injector in project okaeri-injector by OkaeriPoland.
the class TestInjector method test_constructor.
@Test
public void test_constructor() {
String name = "some app";
Injector injector = OkaeriInjector.create().registerInjectable("name", name);
App app = injector.createInstance(App.class);
assertEquals(name, app.getName());
}
use of eu.okaeri.injector.Injector in project okaeri-injector by OkaeriPoland.
the class TestInjector method test_double_type_injector.
@Test
public void test_double_type_injector() {
Api api = new Api("test-api1");
Api api2 = new Api("test-api2");
Injector injector = OkaeriInjector.create().registerInjectable("api", api).registerInjectable("api2", api2);
Worker worker = injector.createInstance(Worker.class);
assertEquals(api, worker.getApi());
assertEquals(3, worker.getCounter());
Worker2 worker2 = injector.createInstance(Worker2.class);
assertEquals(api2, worker2.getApi());
}
use of eu.okaeri.injector.Injector in project okaeri-injector by OkaeriPoland.
the class TestInjector method test_simple_injector.
@Test
public void test_simple_injector() {
Api api = new Api("test-api");
Injector injector = OkaeriInjector.create().registerInjectable(api);
Worker worker = injector.createInstance(Worker.class);
assertEquals(api, worker.getApi());
assertEquals(3, worker.getCounter());
}
use of eu.okaeri.injector.Injector in project okaeri-platform by OkaeriPoland.
the class ListenerComponentResolver method make.
@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
long start = System.currentTimeMillis();
Class<?> manifestType = manifest.getType();
Object instance = injector.createInstance(manifestType);
Listener listener = (Listener) instance;
this.plugin.getProxy().getPluginManager().registerListener(this.plugin, listener);
long took = System.currentTimeMillis() - start;
creator.log(ComponentHelper.buildComponentMessage().type("Added listener").name(listener.getClass().getSimpleName()).took(took).meta("methods", Arrays.stream(listener.getClass().getDeclaredMethods()).filter(method -> method.getAnnotation(EventHandler.class) != null).map(Method::getName).collect(Collectors.toList())).build());
creator.increaseStatistics("listeners", 1);
return listener;
}
Aggregations