@Test public void testScope() { scope.enter(); assertEquals(target, provider.get()); scope.exit(); }
@Test public void testOutOfScope() { scope.enter(); scope.exit(); try { provider.get(); assertTrue(false); } catch (OutOfScopeException e) { assertTrue(true); } }
@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(); }
@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; } }); }