### Question:
MappingPattern implements Serializable { @Override public boolean equals(Object obj) { if (obj instanceof MappingPattern) { MappingPattern otherPattern = (MappingPattern) obj; if (this.method.equals(otherPattern.getMethod()) && this.pattern.toString().equals(otherPattern.getPattern().toString())) { return true; } else { return false; } } else { return false; } } MappingPattern(Pattern pattern, String method); Pattern getPattern(); String getMethod(); @Override boolean equals(Object obj); @Override int hashCode();  }### Answer:
@Test public void when_path_and_method_equal_then_MappingPatterns_are_equal() throws Exception { String path = "/v0.1/me"; Pattern p1 = Pattern.compile(path); MappingPattern pattern1 = new MappingPattern(p1, "GET"); Pattern p2 = Pattern.compile(path); MappingPattern pattern2 = new MappingPattern(p2, "GET"); boolean equals = pattern1.equals(pattern2); assertTrue(equals); }
@Test public void when_path_equal_but_method_different_then_MappingPatterns_are_NOT_equal() throws Exception { String path = "/v0.1/me"; Pattern p1 = Pattern.compile(path); MappingPattern pattern1 = new MappingPattern(p1, "GET"); Pattern p2 = Pattern.compile(path); MappingPattern pattern2 = new MappingPattern(p2, "POST"); boolean equals = pattern1.equals(pattern2); assertFalse(equals); }
@Test public void when_path_different_and_method_equal_then_MappingPatterns_are_NOT_equal() throws Exception { String path = "/v0.1/me"; Pattern p1 = Pattern.compile(path); MappingPattern pattern1 = new MappingPattern(p1, "GET"); Pattern p2 = Pattern.compile(path + "/emails"); MappingPattern pattern2 = new MappingPattern(p2, "GET"); boolean equals = pattern1.equals(pattern2); assertFalse(equals); }