### Question:
SolutionGroup { public boolean add(final Solution<T> sol, final long now) { if (sol.isExpired(now)) { throw new IllegalStateException("we shouldn't add an expired solution"); } LList<SolutionPattern> cur = solutions, prev = null; while (!cur.isNil()) { boolean removeOld = false; SolutionPattern curSol = cur.getValue(); if (curSol.isExpired(now)) { removeOld = true; } else { SolutionPattern.ContainmentRelation r = curSol.relateTo(sol); switch (r) { case Contains: if (SolutionPattern.compareExpirationTimes(curSol, sol) >= 0) { return false; } break; case ContainedIn: if (SolutionPattern.compareExpirationTimes(curSol, sol) <= 0) { removeOld = true; } break; case Equal: int cmp = SolutionPattern.compareExpirationTimes(curSol, sol); if (cmp < 0) { curSol.setExpirationTime(sol.expirationTime); return true; } else { return false; } case PartialIntersect: break; case Disjoint: break; } } if (removeOld) { if (null == prev) { solutions = cur.getRest(); } else { prev.setRest(cur.getRest()); } LList<SolutionPattern> tmp = cur.getRest(); cur.setRest(null); cur = tmp; continue; } prev = cur; cur = cur.getRest(); } solutions = solutions.push( new SolutionPattern(sol)); return true; } SolutionGroup(Bindings<T> bindings); Bindings<T> getBindings(); LList<SolutionPattern> getSolutions(); boolean add(final Solution<T> sol,
                       final long now); int removeExpired(final long now); @Override int hashCode(); @Override boolean equals(final Object other);  }### Answer:
@Test(expected = IllegalStateException.class) public void testCantAddExpired() throws Exception { Solution<String> solExp1 = new Solution<>(3, 0, bindings, 42); SolutionGroup<String> g = new SolutionGroup<>(bindings); g.add(solExp1, now); }