### Question:
Scope { public synchronized final void add(Scope<T> scope) { Ensure.not_null(scope); Ensure.is_null(scope.m_parent); Ensure.not_null(scope.m_name); if (m_objects.get(scope.m_name) != null) { throw new IllegalStateException("Scope already has an object " + "named '" + scope.m_name + "'."); } if (m_sub_scopes.get(scope.m_name) != null) { throw new IllegalStateException("Scope already has a sub scope " + "named '" + scope.m_name + "'."); } check_add(scope); m_sub_scopes.put(scope.m_name, scope); scope.m_parent = this; } Scope(String name); final String name(); final Scope<T> parent(); final HierarchicalName absolute_hname(); synchronized final void add(Scope<T> scope); synchronized final void add(T obj); synchronized T find(String name); synchronized Scope<T> find_scope(String name); synchronized T find(HierarchicalName hn); synchronized Scope<T> find_scope(HierarchicalName hn); synchronized Set<T> all(); synchronized final void link(Scope<T> scope); synchronized Set<T> all_recursive(); synchronized boolean child_scope_of(Scope<?> scope); static Scope<?> common_inner_most_parent_scope(
			Set<? extends Scope<?>> scopes);  }### Answer:
@Test(expected = AssertionError.class) public void global_scopes_cannot_be_added_to_other_scopes() throws Exception { TestScope gs = new TestScope(); TestScope gs2 = new TestScope(); gs.add(gs2); }
@Test public void adding_duplicate_objects_in_scope() throws Exception { TestScope s = new TestScope(); s.add(new ScopedObject("s1")); s.add(new Scope<>("s2")); try { s.add(new ScopedObject("s1")); fail(); } catch (IllegalStateException e) { } try { s.add(new TestScope("s1")); fail(); } catch (IllegalStateException e) { } try { s.add(new ScopedObject("s2")); fail(); } catch (IllegalStateException e) { } try { s.add(new TestScope("s2")); fail(); } catch (IllegalStateException e) { } }
@Test(expected = AssertionError.class) public void adding_null_scope_to_scope() throws Exception { TestScope s = new TestScope(); s.add((TestScope) null); }
@Test(expected = AssertionError.class) public void adding_null_scoped_object_to_scope() throws Exception { TestScope s = new TestScope(); s.add((ScopedObject) null); }
@Test public void check_object_in_its_own_scope() throws Exception { TestScope s0 = new TestScope(); ScopedObject o0 = new ScopedObject("x"); s0.add(o0); assertTrue(o0.in_scope(s0)); }
@Test public void check_object_in_its_parent_scope() throws Exception { TestScope s0 = new TestScope(); TestScope s1 = new TestScope("s"); s0.add(s1); ScopedObject o1 = new ScopedObject("x"); s1.add(o1); assertTrue(o1.in_scope(s0)); }
@Test public void check_object_not_in_sub_scope() throws Exception { TestScope s0 = new TestScope(); TestScope s1 = new TestScope("s"); s0.add(s1); ScopedObject o0 = new ScopedObject("x"); s0.add(o0); assertFalse(o0.in_scope(s1)); }