From: David S. <ds...@us...> - 2007-07-02 18:11:08
|
Update of /cvsroot/junit/junit/src/org/junit/experimental/theories/test/imposterization In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/experimental/theories/test/imposterization Added Files: PopperImposterizerTest.java ThrownMatcherTest.java AssumePassingTest.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: PopperImposterizerTest.java --- package org.junit.experimental.theories.test.imposterization; import static org.junit.Assert.assertThat; import java.util.List; import org.hamcrest.Matchers; import org.junit.Test; import org.junit.experimental.imposterization.PopperImposterizer; public class PopperImposterizerTest { @Test public void canWrapImposterizedObjects() { List<?> list= new PopperImposterizer(null).imposterize(List.class); assertThat(new PopperImposterizer(null).imposterize(list.getClass()), Matchers.notNullValue()); } } --- NEW FILE: ThrownMatcherTest.java --- package org.junit.experimental.theories.test.imposterization; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import java.util.ArrayList; import org.junit.Test; import org.junit.experimental.imposterization.ThrownMatcher; import org.junit.experimental.imposterization.ThrownMatcher.IncorrectThrownException; import org.junit.experimental.theories.runner.api.Theories; import org.junit.runner.RunWith; @RunWith(Theories.class) public class ThrownMatcherTest { @Test public void assertThrownVerifiesExceptionThrown() throws Exception { ArithmeticException ae= new ArithmeticException(); try { ThrownMatcher.assertThrownException(is(ae)).when( new ArrayList<String>()).get(0); fail("should have thrown exception"); } catch (IncorrectThrownException e) { assertThat(e.getMessage(), containsString(ae.toString())); } } @Test public void assertThrownVerifiesExceptionThrownWithRequirements() throws Exception { ArithmeticException ae= new ArithmeticException(); try { ThrownMatcher.assertThrownException(is(ae)).when( new ArrayList<String>()).get(0); fail("should have thrown exception"); } catch (IncorrectThrownException e) { assertThat(e.getMessage(), containsString(ae.toString())); } } public static class ExceptionThrowing { public static Throwable EXCEPTION= new NullPointerException(); public void liveDangerously() throws Throwable { throw EXCEPTION; } } @Test public void stackTraceOnAssertThrown() { try { ThrownMatcher.assertThrownException(is(new RuntimeException())) .when(new ExceptionThrowing()).liveDangerously(); fail("should have thrown exception"); } catch (Throwable e) { assertThat(e.getCause(), is(ExceptionThrowing.EXCEPTION)); } } } --- NEW FILE: AssumePassingTest.java --- package org.junit.experimental.theories.test.imposterization; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.junit.experimental.imposterization.AssumePassing.assumePasses; import java.util.List; import org.hamcrest.Matchers; import org.junit.Test; import org.junit.Assume.AssumptionViolatedException; import org.junit.experimental.imposterization.AssumePassing; import org.junit.experimental.theories.runner.api.Theories; import org.junit.runner.JUnitCore; import org.junit.runner.RunWith; import org.junit.runner.notification.Failure; @RunWith(Theories.class) public class AssumePassingTest { public static class OnlyIfPassingButDoesnt { @Test public void failing() { fail(); } @SuppressWarnings("deprecation") @Test public void willIgnore() { ((OnlyIfPassingButDoesnt) AssumePassing.assumePasses(this .getClass())).failing(); fail(); } } @Test public void onlyIfPassingButDoesnt() { assertThat(onlyIfPassingFailures().size(), is(1)); } @SuppressWarnings("unchecked") @Test public void removedParameterizedFailureWhenZeroParams() { assertThat(onlyIfPassingFailures().get(0).getException(), Matchers .is(AssertionError.class)); } private List<Failure> onlyIfPassingFailures() { return JUnitCore.runClasses(OnlyIfPassingButDoesnt.class).getFailures(); } @RunWith(Theories.class) public static class OnlyIfPassesAndDoes { @Test public void passing() { } @SuppressWarnings("deprecation") @Test public void wontIgnore() { assumePasses(OnlyIfPassesAndDoes.class).passing(); fail(); } } @Test public void onlyIfPassesAndDoes() { assertThat(JUnitCore.runClasses(OnlyIfPassesAndDoes.class) .getFailures().size(), is(1)); } @RunWith(Theories.class) public static class OnlyIfPassesWithInvalidTheory { @Test public void throwsInvalidTheory() { throw new AssumptionViolatedException(null, is("a")); } @SuppressWarnings("deprecation") @Test public void wontIgnore() { assumePasses(OnlyIfPassesWithInvalidTheory.class) .throwsInvalidTheory(); } } @Test public void onlyIfPassesWithInvalidTheory() { assertThat(JUnitCore.runClasses(OnlyIfPassesWithInvalidTheory.class) .getIgnoreCount(), is(0)); } } |