ScopeNode implements Scope { void removeChild(ScopeNode child) { if (child == null) { throw new IllegalArgumentException("Child must be non null."); } final ScopeNode parentScope = child.getParentScope(); if (parentScope == null) { throw new IllegalStateException(format("The scope has no parent: %s", child.getName())); } if (parentScope != this) { throw new IllegalStateException( format( "The scope %s has parent: different of this: %s", child.getName(), parentScope.getName(), getName())); } childrenScopes.remove(child.getName()); child.parentScopes.clear(); } 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(expected = IllegalArgumentException.class) public void testRemoveChild_shouldFail_whenChildIsNull() { ScopeNode parentScope = new ScopeImpl("root"); parentScope.removeChild(null); fail("Should throw an exception"); }
@Test(expected = IllegalStateException.class) public void testRemoveChild_shouldFail_whenChildHasNoParent() { ScopeNode parentScope = new ScopeImpl("root"); ScopeNode childScope = new ScopeImpl("child"); parentScope.removeChild(childScope); fail("Should throw an exception"); }
@Test public void testRemoveChild() { ScopeNode parentScope = new ScopeImpl("root"); ScopeNode childScope = new ScopeImpl("child"); parentScope.addChild(childScope); parentScope.removeChild(childScope); Collection<ScopeNode> childrenScopes = parentScope.getChildrenScopes(); assertThat(childrenScopes.isEmpty(), is(true)); }