示例#1
0
  /** Tests that adding the whole annotation adds the class and string */
  @Test
  public void testDescWithAnnotationGivenDirectly() {
    AbstractActiveDescriptor<?> desc =
        BuilderHelper.activeLink(ServiceA.class)
            .in(ServiceLocatorUtilities.getSingletonAnnotation())
            .build();

    Assert.assertEquals(
        desc.getScopeAsAnnotation(), ServiceLocatorUtilities.getSingletonAnnotation());
    Assert.assertEquals(desc.getScopeAnnotation(), Singleton.class);
    Assert.assertEquals(desc.getScope(), Singleton.class.getName());
  }
示例#2
0
  /** Ensures we can add a scope to a service with no scope at all */
  @Test
  public void testGiveClassWithNoScopeAScope() {
    ServiceLocator locator = LocatorHelper.create();
    ServiceLocatorUtilities.enableLookupExceptions(locator);

    Descriptor desc =
        BuilderHelper.activeLink(NoScopeService.class)
            .to(NoScopeService.class)
            .in(ServiceLocatorUtilities.getSingletonAnnotation())
            .build();

    ServiceLocatorUtilities.addOneDescriptor(locator, desc);

    NoScopeService one = locator.getService(NoScopeService.class);
    NoScopeService two = locator.getService(NoScopeService.class);

    Assert.assertNotNull(one);
    Assert.assertEquals(one, two);
  }