Requirement { public void setRequires(Requirement<T> req) { if (req.requires(this)) throw new RuntimeException("Requirement cycle detected"); requirements.add(req); } Requirement(T data); T getData(); void setRequires(Requirement<T> req); void setRequiredBy(Requirement<T> req); boolean requires(Requirement<T> req); boolean requiredBy(Requirement<T> req); Collection<Requirement<T>> listRequirements(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); String toStringWithReqs();  }
@Test public void testSelfCycles1() { Requirement self = new Requirement(null); thrown.expect(RuntimeException.class); thrown.expectMessage("Requirement cycle detected"); self.setRequires(self); }