### Question:
Scope { public synchronized final void link(Scope<T> scope) throws CyclicScopeLinkageException { Ensure.not_null(scope); Ensure.is_false(m_linked.contains(scope)); Set<Scope<T>> current = new HashSet<>(); current.addAll(m_linked); current.add(scope); Set<Scope<T>> seen = new HashSet<>(current); do { current = follow_set(current); if (current.contains(this)) { throw new CyclicScopeLinkageException("Scope '" + m_name + "' would be in a cyclic linkage graph if linked " + "with scope '" + scope.m_name + "'."); } current.removeAll(seen); seen.addAll(current); } while (current.size() > 0); check_link(scope); m_linked.add(scope); } 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 public void creating_cyclic_linkage_structures() throws Exception { TestScope s1 = new TestScope(); TestScope s2 = new TestScope(); TestScope s3 = new TestScope(); s1.link(s2); s3.link(s1); try { s2.link(s1); fail(); } catch (CyclicScopeLinkageException e) { } try { s2.link(s3); fail(); } catch (CyclicScopeLinkageException e) { } }
@Test(expected = AssertionError.class) public void linking_null_scope() throws Exception { TestScope s = new TestScope(); s.link(null); }
@Test(expected = AssertionError.class) public void linking_same_scope_twice() throws Exception { TestScope s1 = new TestScope(); TestScope l = new TestScope(); s1.link(l); s1.link(l); }