Update of /cvsroot/junit/junit/src/org/junit/experimental/theories/matchers/api In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/experimental/theories/matchers/api Added Files: MethodNamedMatcher.java CamelCaseName.java ClassNamedMatcher.java StackTrace.java Each.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: MethodNamedMatcher.java --- package org.junit.experimental.theories.matchers.api; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; public abstract class MethodNamedMatcher<T> extends BaseMatcher<T> { private StackTrace constructionStackTrace; public MethodNamedMatcher() { this.constructionStackTrace = StackTrace.create(); } public void describeTo(Description description) { description.appendText(new CamelCaseName(constructionStackTrace .factoryMethodName()).asNaturalLanguage()); } } --- NEW FILE: CamelCaseName.java --- /** * */ package org.junit.experimental.theories.matchers.api; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CamelCaseName { private static final Pattern PATTERN = Pattern.compile("([A-Za-z][a-z]*)"); private final String methodName; public CamelCaseName(String methodName) { this.methodName = methodName; } public String asNaturalLanguage() { String description = ""; Matcher matcher = PATTERN.matcher(methodName); while (matcher.find()) description += " " + matcher.group().toLowerCase(); return description.substring(1); } } --- NEW FILE: ClassNamedMatcher.java --- package org.junit.experimental.theories.matchers.api; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; public abstract class ClassNamedMatcher<T> extends BaseMatcher<T> { public void describeTo(Description description) { description.appendText(new CamelCaseName(getClass().getSimpleName()) .asNaturalLanguage()); } } --- NEW FILE: StackTrace.java --- /** * */ package org.junit.experimental.theories.matchers.api; public class StackTrace { public static StackTrace create() { return new StackTrace(new RuntimeException()); } private final StackTraceElement[] stackTrace; private StackTrace(Throwable e) { this.stackTrace = e.getStackTrace(); } public String factoryMethodName() { return nameOfMethodThatCalledMostRecentConstructor(); } private String nameOfMethodThatCalledMostRecentConstructor() { boolean initSeen = false; for (StackTraceElement element : getElements()) { if (element.getMethodName().equals("<init>")) initSeen = true; else if (initSeen) return element.getMethodName(); } return null; } public StackTraceElement[] getElements() { return stackTrace; } } --- NEW FILE: Each.java --- package org.junit.experimental.theories.matchers.api; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.hasItem; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; public class Each { public static <T> Matcher<Iterable<T>> each(final Matcher<T> individual) { final Matcher<Iterable<T>> allItemsAre = not(hasItem(not(individual))); return new BaseMatcher<Iterable<T>>() { public boolean matches(Object item) { return allItemsAre.matches(item); } public void describeTo(Description description) { description.appendText("each "); individual.describeTo(description); } }; } } |