/*
   * Being a jpa object, IPolicy do not implement equals.
   * Nice read: http://www.onjava.com/lpt/a/6718
   */
  private boolean equalsPolicy(IPolicy p1, IPolicy p2) {
    if (p1 == null || p2 == null) {
      throw new NullPointerException();
    }

    return (p1.getCount() == p2.getCount() && p1.getTimeInterval().equals(p2.getTimeInterval()));
  }
 private void checkPolicyExists(IPolicy expected, List<IPolicy> actuals) {
   boolean found = false;
   for (IPolicy actual : actuals) {
     System.out.println(actual.getCount() + " " + actual.getTimeInterval());
     if (equalsPolicy(expected, actual)) {
       found = true;
       break;
     }
   }
   if (!found) {
     fail("Policy " + expected + " not found");
   }
 }