コード例 #1
0
  @Test(dataProvider = "builders")
  public void testUsingAnnotation(LifecycleInjectorBuilder lifecycleInjectorBuilder) {
    Injector injector = lifecycleInjectorBuilder.createInjector();

    Assert.assertEquals(AnnotatedLazySingletonObject.constructorCount.get(), 0);
    Assert.assertEquals(AnnotatedLazySingletonObject.postConstructCount.get(), 0);

    AnnotatedLazySingletonObject instance =
        injector.getInstance(AnnotatedLazySingletonObject.class);
    Assert.assertEquals(AnnotatedLazySingletonObject.constructorCount.get(), 1);
    Assert.assertEquals(AnnotatedLazySingletonObject.postConstructCount.get(), 1);

    AnnotatedLazySingletonObject instance2 =
        injector.getInstance(AnnotatedLazySingletonObject.class);
    Assert.assertEquals(AnnotatedLazySingletonObject.constructorCount.get(), 1);
    Assert.assertEquals(AnnotatedLazySingletonObject.postConstructCount.get(), 1);

    Assert.assertSame(instance, instance2);
  }