From: David S. <ds...@us...> - 2007-07-02 18:11:03
|
Update of /cvsroot/junit/junit/src/org/junit/experimental/results In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/experimental/results Added Files: PrintableResult.java ResultMatchers.java FailureList.java Log Message: - The hamcrest-core-1.1 library is now included in the JUnit distribution. For more hamcrest matchers, see the hamcrest-library jar from http://code.google.com/p/hamcrest - The Popper Theory runner (http://popper.tigris.org) has been absorbed into the JUnit project, under the package name org.junit.experimental.theories - Several additional libraries used in the theories tests have been added in a new testlib directory - New "assertThat" statement to work with hamcrest matchers: // same as assertEquals(3, x) assertThat(x, is(3)); // same as assertNull(y) assertThat(y, nullValue()); - New feature: assumeThat. A failed assumption will cause the test to pass, without further execution. (The behavior of assumeThat may change in the future to allow richer reporting of tests that are skipped because of failed assumptions) // pass on any non-Windows system @Test public void getRootDrive() { assumeThat(getOsString(), is("Windows")); getFile("C:\"); // ... } - Convenience assumption functions: // none of these are null assumeNotNull(a, b, c); assumeTrue(everythingOk()); try { getDatabaseConnection(); } catch (Exception e) { assumeNoException(e); } - Documentation fixed for many assertEquals array methods - Two bugs in numeric equality fixed: 1718905: assertEquals does not compare float correctly 1715326: assertEquals does not compare java.math.BigDecimal properly - The protocol for overriding JUnit4ClassRunner has changed again. Please see the source for details. - Extenders can now extend TestMethod to describe the behavior of running methods that do not have a @Test annotation. - Adding Annotations to Description caused a binary compatibility problem with clients compiled on previous JUnit versions. This has been fixed. --- NEW FILE: PrintableResult.java --- /** * */ package org.junit.experimental.results; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.List; import org.junit.internal.TextListener; import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; @SuppressWarnings("restriction") public class PrintableResult { public static PrintableResult testResult(Class<?> type) { return new PrintableResult(type); } private Result result; public PrintableResult(List<Failure> failures) { this(new FailureList(failures).result()); } public PrintableResult(Result result) { this.result = result; } public PrintableResult(Class<?> type) { this(JUnitCore.runClasses(type)); } @Override public String toString() { if (result.getFailureCount() == 0) return "PASSED!"; ByteArrayOutputStream stream = new ByteArrayOutputStream(); new TextListener(new PrintStream(stream)).testRunFinished(result); return stream.toString(); } public List<Failure> getFailures() { return result.getFailures(); } } --- NEW FILE: ResultMatchers.java --- package org.junit.experimental.results; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasToString; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; public class ResultMatchers { public static Matcher<PrintableResult> isSuccessful() { return failureCountIs(0); } public static Matcher<PrintableResult> failureCountIs(final int count) { return new BaseMatcher<PrintableResult>() { public boolean matches(Object item) { return ((PrintableResult) item).getFailures().size() == count; } public void describeTo(Description description) { description.appendText("has " + count + " failures"); } }; } @SuppressWarnings("unchecked") public static Matcher<Object> hasSingleFailureContaining(String string) { return allOf(hasToString(containsString(string)), failureCountIs(1)); } } --- NEW FILE: FailureList.java --- /** * */ package org.junit.experimental.results; import java.util.List; import org.junit.runner.Result; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; final class FailureList { private final List<Failure> failures; FailureList(List<Failure> failures) { this.failures = failures; } public Result result() { Result result = new Result(); RunListener listener = result.createListener(); for (Failure failure : failures) { try { listener.testFailure(failure); } catch (Exception e) { throw new RuntimeException("I can't believe this happened"); } } return result; } } |