From: David S. <ds...@us...> - 2007-07-02 18:11:15
|
Update of /cvsroot/junit/junit/src/org/junit/experimental/theories/test/matchers In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/experimental/theories/test/matchers Added Files: EachTest.java MatcherCharacterization.java StackTraceTest.java ClassNamedMatcherTest.java CamelCaseNameTest.java MethodNamedMatcherTest.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: EachTest.java --- package org.junit.experimental.theories.test.matchers; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import org.hamcrest.Matchers; import org.junit.Test; import org.junit.experimental.theories.matchers.api.Each; public class EachTest { @Test public void eachDescription() { assertThat(Each.each(Matchers.is("a")).toString(), is("each is \"a\"")); } } --- NEW FILE: MatcherCharacterization.java --- package org.junit.experimental.theories.test.matchers; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.Test; public class MatcherCharacterization { @Test public void findCamelCase() { Pattern pattern= Pattern.compile("([A-Z]?[a-z]*)"); String methodName= "hasAFreezer"; Matcher matcher= pattern.matcher(methodName); assertThat(matcher.find(), is(true)); } } --- NEW FILE: StackTraceTest.java --- package org.junit.experimental.theories.test.matchers; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import org.junit.Test; import org.junit.experimental.theories.matchers.api.StackTrace; public class StackTraceTest { private static class ThingWithStackTrace { private StackTrace stackTrace; private ThingWithStackTrace() { stackTrace = StackTrace.create(); } } private ThingWithStackTrace newThing() { return new ThingWithStackTrace(); } @Test public void factoryMethodName() { assertThat(newThing().stackTrace.factoryMethodName(), is("newThing")); } @Test public void characterizeStackTrace() { StackTraceElement[] stackTrace = newThing().stackTrace.getElements(); String methodNames = ""; for (StackTraceElement element : stackTrace) { methodNames += element.getMethodName() + ":"; } assertThat(methodNames, hasToString(containsString(":<init>:"))); } } --- NEW FILE: ClassNamedMatcherTest.java --- /** * */ package org.junit.experimental.theories.test.matchers; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import org.junit.Test; import org.junit.experimental.theories.matchers.api.ClassNamedMatcher; public class ClassNamedMatcherTest { public static class NothingMuch extends ClassNamedMatcher<Object> { public boolean matches(Object item) { return false; } } @Test public void classNamedMatcherWorks() { assertThat(new NothingMuch().toString(), is("nothing much")); } public static class NothingMuchMore extends ClassNamedMatcher<Object> { public boolean matches(Object item) { return false; } } @Test public void classNamedMatcherWorksTriangulation() { assertThat(new NothingMuchMore().toString(), is("nothing much more")); } } --- NEW FILE: CamelCaseNameTest.java --- package org.junit.experimental.theories.test.matchers; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import org.junit.Test; import org.junit.experimental.theories.matchers.api.CamelCaseName; public class CamelCaseNameTest { @Test public void basicParsing() { assertThat(new CamelCaseName("hasAFreezer").asNaturalLanguage(), is("has a freezer")); } } --- NEW FILE: MethodNamedMatcherTest.java --- package org.junit.experimental.theories.test.matchers; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; import org.hamcrest.Matcher; import org.junit.Test; import org.junit.experimental.theories.matchers.api.MethodNamedMatcher; import org.junit.experimental.theories.matchers.api.StackTrace; public class MethodNamedMatcherTest { @Test public void noFactoryNameIfNoConstructor() { assertThat(StackTrace.create().factoryMethodName(), nullValue()); } @Test public void requirementDescriptionIsBasedOnMethodName() { assertThat(hasAFrooble().toString(), is("has a frooble")); } private Matcher<Object> hasAFrooble() { return new MethodNamedMatcher<Object>() { public boolean matches(Object value) { return false; } }; } @Test public void requirementDescriptionIsBasedOnMethodNameTriangulation() { assertThat(hasAWidget().toString(), is("has a widget")); } private Matcher<Object> hasAWidget() { return new MethodNamedMatcher<Object>() { public boolean matches(Object value) { return false; } }; } @Test public void requirementDescriptionIsBasedOnMethodNameMoreTriangulation() { assertThat(doesNotAtAllExist().toString(), is("does not at all exist")); } private Matcher<Object> doesNotAtAllExist() { return new MethodNamedMatcher<Object>() { public boolean matches(Object value) { return false; } }; } } |