Beispiel #1
0
  @Test
  public void testScope() {

    scope.enter();

    assertEquals(target, provider.get());

    scope.exit();
  }
Beispiel #2
0
  @Test
  public void testOutOfScope() {

    scope.enter();

    scope.exit();

    try {
      provider.get();
      assertTrue(false);
    } catch (OutOfScopeException e) {
      assertTrue(true);
    }
  }
Beispiel #3
0
  @Test
  public void testSeed() {
    scope.enter();

    try {
      scope.scope(Key.get(SeedTarget.class), new ThrowingProvider<SeedTarget>()).get();
      // should throw exception
      assertTrue(false);
    } catch (OutOfScopeException e) {
      assertTrue(true);
    }

    scope.seed(SeedTarget.class, new SeedTarget());

    assertNotNull(scope.scope(Key.get(SeedTarget.class), new ThrowingProvider<SeedTarget>()).get());

    scope.exit();
  }
Beispiel #4
0
  @Before
  public void setup() {
    scope = new MapScope();
    target = new ScopedTarget();

    provider =
        scope.scope(
            Key.get(ScopedTarget.class),
            new Provider<ScopedTarget>() {
              @Override
              public ScopedTarget get() {
                return target;
              }
            });
  }