PatternHolder { @Override public boolean equals(Object obj) { if (obj instanceof PatternHolder) { return pattern.toString().equals(obj.toString()); } else { return false; } } PatternHolder(Pattern pattern); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); Pattern getPattern();  }
@Test public void testEquals(TestContext context) { PatternHolder pH = new PatternHolder(Pattern.compile("(mouse|cat|dog|wolf|bear|human)")); PatternHolder pH2 = new PatternHolder(Pattern.compile("(mouse|cat|dog|wolf|bear|human)")); PatternHolder pH3 = new PatternHolder(Pattern.compile("(wolf|bear|human)")); context.assertFalse(pH.equals(new Integer(1))); context.assertTrue(pH.equals(pH2)); context.assertFalse(pH.equals(pH3)); }