mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
added modules, classloading and view packages to sonia.scm.lifecycle
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package sonia.scm.lifecycle.modules;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sonia.scm.EagerSingleton;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class EagerSingletonModuleTest {
|
||||
|
||||
@Test
|
||||
void shouldInitializeEagerSingletons() {
|
||||
Injector injector = Guice.createInjector(new EagerSingletonModule(), new EagerTestModule());
|
||||
injector.getInstance(EagerSingletonModule.class).initialize(injector);
|
||||
|
||||
Capturer capturer = injector.getInstance(Capturer.class);
|
||||
assertThat(capturer.value).isEqualTo("eager!");
|
||||
}
|
||||
|
||||
public static class EagerTestModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Capturer.class);
|
||||
bind(Eager.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class Capturer {
|
||||
private String value;
|
||||
}
|
||||
|
||||
@EagerSingleton
|
||||
public static class Eager {
|
||||
|
||||
@Inject
|
||||
public Eager(Capturer capturer) {
|
||||
capturer.value = "eager!";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user