Skip to content

Commit

Permalink
made TestBuilder accept Matcher and convert it to Tester
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejmikosik committed Dec 6, 2014
1 parent 6a004e7 commit cd90985
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main/java/org/testanza/TestBuilder.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.testanza;

import static org.testanza.Testers.asTester;
import junit.framework.Test;
import junit.framework.TestSuite;

import org.hamcrest.Matcher;

// TODO untested
public class TestBuilder {
private final TestSuite suite;
Expand All @@ -27,6 +30,22 @@ public <T> void testThatAll(T[] items, Tester<T> tester) {
}
}

public <T> void testThat(T item, Matcher<T> matcher) {
suite.addTest(asTester(matcher).test(item));
}

public <T> void testThatAll(Iterable<? extends T> items, Matcher<T> matcher) {
for (T item : items) {
suite.addTest(asTester(matcher).test(item));
}
}

public <T> void testThatAll(T[] items, Matcher<T> matcher) {
for (T item : items) {
suite.addTest(asTester(matcher).test(item));
}
}

public Test build() {
return suite;
}
Expand Down
12 changes: 12 additions & 0 deletions test/org/testanza/describe_TestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import junit.framework.Test;
import junit.framework.TestCase;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class describe_TestBuilder {
private static TestBuilder builder;

Expand All @@ -16,8 +20,16 @@ public Test test(Object item) {
return new TestCase() {};
}
};
Matcher<Object> matcher = new TypeSafeMatcher<Object>() {
public void describeTo(Description description) {}

protected boolean matchesSafely(Object item) {
return false;
}
};
builder = new TestBuilder("");
// verify that compiles
builder.testThatAll(items, tester);
builder.testThatAll(items, matcher);
}
}

0 comments on commit cd90985

Please sign in to comment.