-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose ContainAnalyzer as contain matcher
- Loading branch information
1 parent
c1d0924
commit 4e9a583
Showing
5 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
webtau-core/src/main/java/com/twosigma/webtau/expectation/contain/ContainMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.twosigma.webtau.expectation.contain; | ||
|
||
import com.twosigma.webtau.data.render.DataRenderers; | ||
import com.twosigma.webtau.expectation.ActualPath; | ||
import com.twosigma.webtau.expectation.ValueMatcher; | ||
|
||
public class ContainMatcher implements ValueMatcher { | ||
private ContainAnalyzer containAnalyzer; | ||
private final Object expected; | ||
|
||
public ContainMatcher(Object expected) { | ||
this.expected = expected; | ||
} | ||
|
||
@Override | ||
public String matchingMessage() { | ||
return "co contain " + DataRenderers.render(expected); | ||
} | ||
|
||
@Override | ||
public String matchedMessage(ActualPath actualPath, Object actual) { | ||
return "contains " + DataRenderers.render(expected); | ||
} | ||
|
||
@Override | ||
public String mismatchedMessage(ActualPath actualPath, Object actual) { | ||
return containAnalyzer.generateMismatchReport(); | ||
} | ||
|
||
@Override | ||
public boolean matches(ActualPath actualPath, Object actual) { | ||
containAnalyzer = ContainAnalyzer.containAnalyzer(); | ||
return analyzeContain(actualPath, actual); | ||
} | ||
|
||
@Override | ||
public String negativeMatchingMessage() { | ||
return "to not contain " + DataRenderers.render(expected); | ||
} | ||
|
||
@Override | ||
public String negativeMatchedMessage(ActualPath actualPath, Object actual) { | ||
return "does not contain " + DataRenderers.render(expected); | ||
} | ||
|
||
@Override | ||
public String negativeMismatchedMessage(ActualPath actualPath, Object actual) { | ||
return actualPath + " contains " + DataRenderers.render(expected) + "\nactual: " + | ||
DataRenderers.render(actual); | ||
} | ||
|
||
@Override | ||
public boolean negativeMatches(ActualPath actualPath, Object actual) { | ||
containAnalyzer = ContainAnalyzer.negativeContainAnalyzer(); | ||
return analyzeContain(actualPath, actual); | ||
} | ||
|
||
private boolean analyzeContain(ActualPath actualPath, Object actual) { | ||
containAnalyzer.contains(actualPath, actual, expected); | ||
return containAnalyzer.contains(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...au-core/src/test/groovy/com/twosigma/webtau/expectation/contain/ContainMatcherTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.twosigma.webtau.expectation.contain | ||
|
||
import org.junit.Test | ||
|
||
import static com.twosigma.webtau.Ddjt.actual | ||
import static com.twosigma.webtau.Ddjt.code | ||
import static com.twosigma.webtau.Ddjt.contain | ||
import static com.twosigma.webtau.Ddjt.throwException | ||
|
||
class ContainMatcherTest { | ||
@Test | ||
void "should throw exception when value doesn't contain expected value"() { | ||
code { | ||
actual("hello world").should(contain("world!")) | ||
} should throwException("\ndoes not contain:\n" + | ||
"\n" + | ||
"[value]: actual: hello world\n" + | ||
" expected to contain: world!") | ||
} | ||
|
||
@Test | ||
void "should throw exception when value contain expected value, but should not"() { | ||
code { | ||
actual("hello world").shouldNot(contain("world")) | ||
} should throwException("[value] contains world\n" + | ||
"actual: hello world") | ||
} | ||
|
||
@Test | ||
void "should pass when value contains expected value"() { | ||
actual("hello world").should(contain("world")) | ||
} | ||
|
||
@Test | ||
void "should pass when value doesn't contains expected value and should not"() { | ||
actual("hello world").shouldNot(contain("world!")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters