ScopeNode implements Scope { @Override public ScopeNode getParentScope() { Iterator<ScopeNode> parentIterator = parentScopes.iterator(); boolean hasParent = parentIterator.hasNext(); return hasParent ? parentIterator.next() : null; } ScopeNode(Object name); @Override Object getName(); @Override boolean equals(Object o); @Override int hashCode(); @Override ScopeNode getParentScope(); @SuppressWarnings({"unused", "used by generated code"}) @Override ScopeNode getParentScope(Class<A> scopeAnnotationClass); @SuppressWarnings({"unused", "used by generated code"}) @Override ScopeNode getRootScope(); @Override Scope supportScopeAnnotation(Class<? extends Annotation> scopeAnnotationClass); @Override boolean isScopeAnnotationSupported(Class<? extends Annotation> scopeAnnotationClass);  }
@Test public void testGetParentScope_shouldReturnRootScope_whenAskedForSingleton() { Scope parentScope = Toothpick.openScope("root"); Scope childScope = Toothpick.openScopes("root", "child"); Scope scope = childScope.getParentScope(Singleton.class); assertThat(scope, is(parentScope)); }
@Test(expected = IllegalStateException.class) public void testGetParentScope_shouldFail_whenNoParentSupportsScopeAnnotation() { Scope scope = Toothpick.openScope("root"); scope.getParentScope(CustomScope.class); fail("Should throw an exception"); }
@Test(expected = IllegalArgumentException.class) public void testGetParentScope_shouldFail_WhenAnnotationIsNotAScope() { Scope scope = Toothpick.openScope("root"); scope.getParentScope(NotAScope.class); fail("Should throw an exception"); }