@Test public void testMatches() { ElementType type = mock(ElementType.class); ElementMetaData meta = mock(ElementMetaData.class); MatcherContext context = mock(MatcherContext.class); ReportElement node = mock(ReportElement.class); ElementType nodeElemType = mock(ElementType.class); ElementMetaData nodeMeta = mock(ElementMetaData.class); doReturn(meta).when(type).getMetaData(); doReturn(NAME).when(meta).getName(); doReturn(nodeElemType).when(node).getElementType(); doReturn(nodeMeta).when(nodeElemType).getMetaData(); doReturn(NAME + "_node").when(nodeMeta).getName(); ElementMatcher matcher = new ElementMatcher(type); assertThat(matcher.matches(context, node), is(equalTo(false))); doReturn(NAME).when(nodeMeta).getName(); assertThat(matcher.matches(context, node), is(equalTo(true))); AttributeMatcher attrMatcher = mock(AttributeMatcher.class); doReturn(true).when(attrMatcher).matches(context, node); matcher.add(attrMatcher); assertThat(matcher.matches(context, node), is(equalTo(true))); doReturn(false).when(attrMatcher).matches(context, node); assertThat(matcher.matches(context, node), is(equalTo(false))); }
@Override public boolean matches(T target) { return matcher.matches(target.getType()); }
@Test(expected = NullPointerException.class) public void testMatchesWithoutNode() { ElementMatcher matcher = new ElementMatcher(NAME); matcher.matches(mock(MatcherContext.class), null); }
@Override public boolean isCoveredBy(ElementMatcher elementMatcher) { return elementMatcher.matches(Element.WAY); }