### Question:
KeyMatcher implements Matcher { public String match(Set<String> sources, String target ) { return sources.contains(target) || sources.isEmpty() ? target : matchMissingKey(sources,target); }  String match(Set<String> sources, String target );  }### Answer:
@Test public void matchNonExistentFirstLevel() { String nonExistentTarget = "A.X"; final String match = keyMatcher.match(listeners, nonExistentTarget); assertEquals("A.*", match); }
@Test public void matchExistentFirstLevel() { String existentTarget = "A.B"; final String match = keyMatcher.match(listeners, existentTarget); assertEquals("A.B", match); }
@Test public void matchNonExistentSecondLevel() { String nonExistentTarget = "A.B.X"; final String match = keyMatcher.match(listeners, nonExistentTarget); assertEquals("A.B.*", match); }
@Test public void matchExistentSecondLevel() { String existentTarget = "A.B.C"; final String match = keyMatcher.match(listeners, existentTarget); assertEquals("A.B.C", match); }
@Test public void matchNonExistentThirdLevel() { String nonExistentTarget = "A.B.X.D"; final String match = keyMatcher.match(listeners, nonExistentTarget); assertEquals("A.B.*.D", match); }
@Test public void matchExistentThirdLevel() { String existentTarget = "A.B.C.D"; final String match = keyMatcher.match(listeners, existentTarget); assertEquals("A.B.C.D", match); }
@Test public void matchDefaultForNonExistent() { String nonExistentTarget = "A.W.X.Y.Z"; final String match = keyMatcher.match(listeners, nonExistentTarget); assertEquals("A.*", match); }
@Test public void matchDefaultForNonExistentSecondLevel() { String nonExistentTarget = "A.B.X.Y.Z"; final String match = keyMatcher.match(listeners, nonExistentTarget); assertEquals("A.B.*", match); }