@Test public void canReturnChildMatcher() { Matcher wrappedMatcher = new TestMatcher(true); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); assertSame("Should return child matcher.", wrappedMatcher, notMatcher.originalMatcher()); }
@Override public String toString() { Matcher invertedMatcher = childIterator().hasNext() ? childIterator().next() : null; String invertedMatcherString = invertedMatcher == null ? "" : invertedMatcher.toString(); return "Not(" + invertedMatcherString +")"; }
@Test public void invertsResultsFromWrappedMatcher_doesntMatchWhenWrappedDoesMatch() throws Exception { Matcher wrappedMatcher = new TestMatcher(true); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); assertFalse(notMatcher.match(bug)); }
@Test(expected=IllegalStateException.class) public void throwsExceptionWhenTryingToGetNonExistentChildMatcher() { new NotMatcher().originalMatcher(); }
@Test public void writeXMLOutputAddsNotTagsAroundWrappedMatchersOutput() throws Exception { Matcher wrappedMatcher = new TestMatcher(true); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); String xmlOutputCreated = writeXMLAndGetStringOutput(notMatcher); assertTrue(containsString("<Not>").matches(xmlOutputCreated)); assertTrue(containsString("<TestMatch>").matches(xmlOutputCreated)); assertTrue(containsString("</TestMatch>").matches(xmlOutputCreated)); assertTrue(containsString("</Not>").matches(xmlOutputCreated)); }
NotMatcher matcher = new NotMatcher(); pushCompoundMatcherAsChild(matcher); } else if ("Source".equals(qName)) {
private String writeXMLAndGetStringOutput(NotMatcher notMatcher) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLOutput xmlOutput = new OutputStreamXMLOutput(outputStream); notMatcher.writeXML(xmlOutput, false); xmlOutput.finish(); return outputStream.toString(StandardCharsets.UTF_8.name()); }
NotMatcher matcher = new NotMatcher(); pushCompoundMatcherAsChild(matcher); } else if ("Source".equals(qName)) {
public static Matcher invertMatcher(Matcher originalMatcher) { if (originalMatcher instanceof NotMatcher) { return ((NotMatcher) originalMatcher).originalMatcher(); } NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(originalMatcher); return notMatcher; }
@Test public void invertsResultsFromWrappedMatcher_doesMatchWhenWrappedDoesnt() throws Exception { Matcher wrappedMatcher = new TestMatcher(false); NotMatcher notMatcher = new NotMatcher(); notMatcher.addChild(wrappedMatcher); assertTrue(notMatcher.match(bug)); }
public Matcher originalMatcher() { Iterator<Matcher> childMatchers = childIterator(); if (childMatchers.hasNext()) { return childMatchers.next(); } else { throw new IllegalStateException("Tried to retrieve child matcher of empty NotMatcher"); } } }
@Override public boolean match(BugInstance bugInstance) { if(!childIterator().hasNext() ) { return false; } Matcher invertedMatcher = childIterator().next(); return ! invertedMatcher.match(bugInstance); }
@Override public void writeXML(XMLOutput xmlOutput, boolean disabled) throws IOException { if(childIterator().hasNext()) { xmlOutput.startTag("Not"); if (disabled) { xmlOutput.addAttribute("disabled","true"); } Matcher invertedMatcher = childIterator().next(); xmlOutput.stopTag(false); invertedMatcher.writeXML(xmlOutput, disabled); xmlOutput.closeTag("Not"); } }
@Override public String toString() { Matcher invertedMatcher = childIterator().hasNext() ? childIterator().next() : null; String invertedMatcherString = invertedMatcher == null ? "" : invertedMatcher.toString(); return "Not(" + invertedMatcherString +")"; }
public Matcher originalMatcher() { Iterator<Matcher> childMatchers = childIterator(); if (childMatchers.hasNext()) { return childMatchers.next(); } else { throw new IllegalStateException("Tried to retrieve child matcher of empty NotMatcher"); } } }
@Override public boolean match(BugInstance bugInstance) { if(!childIterator().hasNext() ) { return false; } Matcher invertedMatcher = childIterator().next(); return ! invertedMatcher.match(bugInstance); }
@Override public void writeXML(XMLOutput xmlOutput, boolean disabled) throws IOException { if(childIterator().hasNext()) { xmlOutput.startTag("Not"); if (disabled) { xmlOutput.addAttribute("disabled","true"); } Matcher invertedMatcher = childIterator().next(); xmlOutput.stopTag(false); invertedMatcher.writeXML(xmlOutput, disabled); xmlOutput.closeTag("Not"); } }