libhamcrest-java-1.2/0000755000175000017500000000000011675175275014470 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/0000755000175000017500000000000010632277431017211 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/0000755000175000017500000000000010632277431020000 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/main/0000755000175000017500000000000010632277433020726 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/main/java/0000755000175000017500000000000011123257170021637 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/main/java/org/0000755000175000017500000000000011123257170022426 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/0000755000175000017500000000000011675175275024255 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/0000755000175000017500000000000011675175275025205 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/AllOf.java0000644000175000017500000000767511123257170027043 0ustar moellermoellerpackage org.hamcrest.core; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.hamcrest.Description; import org.hamcrest.DiagnosingMatcher; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Calculates the logical conjunction of multiple matchers. Evaluation is shortcut, so * subsequent matchers are not called if an earlier matcher returns false. */ public class AllOf extends DiagnosingMatcher { private final Iterable> matchers; public AllOf(Iterable> matchers) { this.matchers = matchers; } @Override public boolean matches(Object o, Description mismatchDescription) { for (Matcher matcher : matchers) { if (!matcher.matches(o)) { mismatchDescription.appendDescriptionOf(matcher).appendText(" "); matcher.describeMismatch(o, mismatchDescription); return false; } } return true; } public void describeTo(Description description) { description.appendList("(", " " + "and" + " ", ")", matchers); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ @Factory public static Matcher allOf(Iterable> matchers) { return new AllOf(matchers); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ @Factory public static Matcher allOf(Matcher... matchers) { return allOf(Arrays.asList(matchers)); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ @Factory public static Matcher allOf(Matcher first, Matcher second) { List> matchers = new ArrayList>(2); matchers.add(first); matchers.add(second); return allOf(matchers); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ @Factory public static Matcher allOf(Matcher first, Matcher second, Matcher third) { List> matchers = new ArrayList>(3); matchers.add(first); matchers.add(second); matchers.add(third); return allOf(matchers); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ @Factory public static Matcher allOf(Matcher first, Matcher second, Matcher third, Matcher fourth) { List> matchers = new ArrayList>(4); matchers.add(first); matchers.add(second); matchers.add(third); matchers.add(fourth); return allOf(matchers); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ @Factory public static Matcher allOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth) { List> matchers = new ArrayList>(5); matchers.add(first); matchers.add(second); matchers.add(third); matchers.add(fourth); matchers.add(fifth); return allOf(matchers); } /** * Evaluates to true only if ALL of the passed in matchers evaluate to true. */ @Factory public static Matcher allOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth, Matcher sixth) { List> matchers = new ArrayList>(6); matchers.add(first); matchers.add(second); matchers.add(third); matchers.add(fourth); matchers.add(sixth); return allOf(matchers); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/AnyOf.java0000644000175000017500000000701011123257170027041 0ustar moellermoellerpackage org.hamcrest.core; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so * subsequent matchers are not called if an earlier matcher returns true. */ public class AnyOf extends ShortcutCombination { public AnyOf(Iterable> matchers) { super(matchers); } @Override public boolean matches(Object o) { return matches(o, true); } @Override public void describeTo(Description description) { describeTo(description, "or"); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static AnyOf anyOf(Iterable> matchers) { return new AnyOf(matchers); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static AnyOf anyOf(Matcher... matchers) { return anyOf(Arrays.asList(matchers)); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static AnyOf anyOf(Matcher first, Matcher second) { List> matchers = new ArrayList>(); matchers.add(first); matchers.add(second); return anyOf(matchers); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static AnyOf anyOf(Matcher first, Matcher second, Matcher third) { List> matchers = new ArrayList>(); matchers.add(first); matchers.add(second); matchers.add(third); return anyOf(matchers); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static AnyOf anyOf(Matcher first, Matcher second, Matcher third, Matcher fourth) { List> matchers = new ArrayList>(); matchers.add(first); matchers.add(second); matchers.add(third); matchers.add(fourth); return anyOf(matchers); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static AnyOf anyOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth) { List> matchers = new ArrayList>(); matchers.add(first); matchers.add(second); matchers.add(third); matchers.add(fourth); matchers.add(fifth); return anyOf(matchers); } /** * Evaluates to true if ANY of the passed in matchers evaluate to true. */ @Factory public static AnyOf anyOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth, Matcher sixth) { List> matchers = new ArrayList>(); matchers.add(first); matchers.add(second); matchers.add(third); matchers.add(fourth); matchers.add(fifth); matchers.add(sixth); return anyOf(matchers); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/CombinableMatcher.java0000644000175000017500000000335611123257170031375 0ustar moellermoellerpackage org.hamcrest.core; import java.util.ArrayList; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; public class CombinableMatcher extends BaseMatcher { private final Matcher matcher; public CombinableMatcher(Matcher matcher) { this.matcher= matcher; } public boolean matches(Object item) { return matcher.matches(item); } public void describeTo(Description description) { description.appendDescriptionOf(matcher); } public CombinableMatcher and(Matcher other) { return new CombinableMatcher(new AllOf(templatedListWith(other))); } public CombinableMatcher or(Matcher other) { return new CombinableMatcher(new AnyOf(templatedListWith(other))); } private ArrayList> templatedListWith(Matcher other) { ArrayList> matchers = new ArrayList>(); matchers.add(matcher); matchers.add(other); return matchers; } /** * This is useful for fluently combining matchers that must both pass. For example: *
   *   assertThat(string, both(containsString("a")).and(containsString("b")));
   * 
*/ @Factory public static CombinableMatcher both(Matcher matcher) { return new CombinableMatcher(matcher); } /** * This is useful for fluently combining matchers where either may pass, for example: *
   *   assertThat(string, both(containsString("a")).and(containsString("b")));
   * 
*/ @Factory public static CombinableMatcher either(Matcher matcher) { return new CombinableMatcher(matcher); } }libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/DescribedAs.java0000644000175000017500000000333211123257170030200 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import java.util.regex.Pattern; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Provides a custom description to another matcher. */ public class DescribedAs extends BaseMatcher { private final String descriptionTemplate; private final Matcher matcher; private final Object[] values; private final static Pattern ARG_PATTERN = Pattern.compile("%([0-9]+)"); public DescribedAs(String descriptionTemplate, Matcher matcher, Object[] values) { this.descriptionTemplate = descriptionTemplate; this.matcher = matcher; this.values = values.clone(); } public boolean matches(Object o) { return matcher.matches(o); } public void describeTo(Description description) { java.util.regex.Matcher arg = ARG_PATTERN.matcher(descriptionTemplate); int textStart = 0; while (arg.find()) { description.appendText(descriptionTemplate.substring(textStart, arg.start())); int argIndex = Integer.parseInt(arg.group(1)); description.appendValue(values[argIndex]); textStart = arg.end(); } if (textStart < descriptionTemplate.length()) { description.appendText(descriptionTemplate.substring(textStart)); } } /** * Wraps an existing matcher and overrides the description when it fails. */ @Factory public static Matcher describedAs(String description, Matcher matcher, Object... values) { return new DescribedAs(description, matcher, values); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/Every.java0000644000175000017500000000212011123257170027114 0ustar moellermoellerpackage org.hamcrest.core; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; public class Every extends TypeSafeDiagnosingMatcher> { private final Matcher matcher; public Every(Matcher matcher) { this.matcher= matcher; } @Override public boolean matchesSafely(Iterable collection, Description mismatchDescription) { for (T t : collection) { if (!matcher.matches(t)) { mismatchDescription.appendText("an item "); matcher.describeMismatch(t, mismatchDescription); return false; } } return true; } public void describeTo(Description description) { description.appendText("every item is ").appendDescriptionOf(matcher); } /** * @param itemMatcher A matcher to apply to every element in a collection. * @return Evaluates to TRUE for a collection in which every item matches itemMatcher */ @Factory public static Matcher> everyItem(final Matcher itemMatcher) { return new Every(itemMatcher); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/Is.java0000644000175000017500000000405011123257170026401 0ustar moellermoellerpackage org.hamcrest.core; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsInstanceOf.instanceOf; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Decorates another Matcher, retaining the behavior but allowing tests * to be slightly more expressive. * * For example: assertThat(cheese, equalTo(smelly)) * vs. assertThat(cheese, is(equalTo(smelly))) */ public class Is extends BaseMatcher { private final Matcher matcher; public Is(Matcher matcher) { this.matcher = matcher; } public boolean matches(Object arg) { return matcher.matches(arg); } public void describeTo(Description description) { description.appendText("is ").appendDescriptionOf(matcher); } @Override public void describeMismatch(Object item, Description mismatchDescription) { // TODO(ngd): unit tests.... matcher.describeMismatch(item, mismatchDescription); } /** * Decorates another Matcher, retaining the behavior but allowing tests * to be slightly more expressive. * * For example: assertThat(cheese, equalTo(smelly)) * vs. assertThat(cheese, is(equalTo(smelly))) */ @Factory public static Matcher is(Matcher matcher) { return new Is(matcher); } /** * This is a shortcut to the frequently used is(equalTo(x)). * * For example: assertThat(cheese, is(equalTo(smelly))) * vs. assertThat(cheese, is(smelly)) */ @Factory public static Matcher is(T value) { return is(equalTo(value)); } /** * This is a shortcut to the frequently used is(instanceOf(SomeClass.class)). * * For example: assertThat(cheese, is(instanceOf(Cheddar.class))) * vs. assertThat(cheese, is(Cheddar.class)) */ @Factory public static Matcher is(Class type) { return is(instanceOf(type)); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/IsAnything.java0000644000175000017500000000210611123257170030103 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Factory; import org.hamcrest.BaseMatcher; /** * A matcher that always returns true. */ public class IsAnything extends BaseMatcher { private final String message; public IsAnything() { this("ANYTHING"); } public IsAnything(String message) { this.message = message; } public boolean matches(Object o) { return true; } public void describeTo(Description description) { description.appendText(message); } /** * This matcher always evaluates to true. */ @Factory public static Matcher anything() { return new IsAnything(); } /** * This matcher always evaluates to true. * * @param description A meaningful string used when describing itself. */ @Factory public static Matcher anything(String description) { return new IsAnything(description); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/IsCollectionContaining.java0000644000175000017500000000475211165365311032443 0ustar moellermoellerpackage org.hamcrest.core; import static org.hamcrest.core.AllOf.allOf; import static org.hamcrest.core.IsEqual.equalTo; import java.util.ArrayList; import java.util.List; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; public class IsCollectionContaining extends TypeSafeDiagnosingMatcher> { private final Matcher elementMatcher; public IsCollectionContaining(Matcher elementMatcher) { this.elementMatcher = elementMatcher; } @Override protected boolean matchesSafely(Iterable collection, Description mismatchDescription) { boolean isPastFirst = false; for (Object item : collection) { if (elementMatcher.matches(item)){ return true; } if (isPastFirst) { mismatchDescription.appendText(", "); } elementMatcher.describeMismatch(item, mismatchDescription); isPastFirst = true; } return false; } public void describeTo(Description description) { description .appendText("a collection containing ") .appendDescriptionOf(elementMatcher); } @Factory public static Matcher> hasItem(Matcher elementMatcher) { return new IsCollectionContaining(elementMatcher); } @Factory public static Matcher> hasItem(T element) { // Doesn't forward to hasItem() method so compiler can sort out generics. return new IsCollectionContaining(equalTo(element)); } @Factory public static Matcher> hasItems(Matcher... elementMatchers) { List>> all = new ArrayList>>(elementMatchers.length); for (Matcher elementMatcher : elementMatchers) { // Doesn't forward to hasItem() method so compiler can sort out generics. all.add(new IsCollectionContaining(elementMatcher)); } return allOf(all); } @Factory public static Matcher> hasItems(T... elements) { List>> all = new ArrayList>>(elements.length); for (T element : elements) { all.add(hasItem(element)); } return allOf(all); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/IsEqual.java0000644000175000017500000000350611123257170027376 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import java.lang.reflect.Array; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Is the value equal to another value, as tested by the * {@link java.lang.Object#equals} invokedMethod? */ public class IsEqual extends BaseMatcher { private final Object object; public IsEqual(T equalArg) { object = equalArg; } public boolean matches(Object arg) { return areEqual(arg, object); } public void describeTo(Description description) { description.appendValue(object); } private static boolean areEqual(Object o1, Object o2) { if (o1 == null) { return o2 == null; } else if (isArray(o1)) { return isArray(o2) && areArraysEqual(o1, o2); } else { return o1.equals(o2); } } private static boolean areArraysEqual(Object o1, Object o2) { return areArrayLengthsEqual(o1, o2) && areArrayElementsEqual(o1, o2); } private static boolean areArrayLengthsEqual(Object o1, Object o2) { return Array.getLength(o1) == Array.getLength(o2); } private static boolean areArrayElementsEqual(Object o1, Object o2) { for (int i = 0; i < Array.getLength(o1); i++) { if (!areEqual(Array.get(o1, i), Array.get(o2, i))) return false; } return true; } private static boolean isArray(Object o) { return o.getClass().isArray(); } /** * Is the value equal to another value, as tested by the * {@link java.lang.Object#equals} invokedMethod? */ @Factory public static Matcher equalTo(T operand) { return new IsEqual(operand); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/IsInstanceOf.java0000644000175000017500000000550211162457605030366 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import org.hamcrest.Description; import org.hamcrest.DiagnosingMatcher; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Tests whether the value is an instance of a class. * Classes of basic types will be converted to the relevant "Object" classes */ public class IsInstanceOf extends DiagnosingMatcher { private final Class expectedClass; private final Class matchableClass; /** * Creates a new instance of IsInstanceOf * * @param expectedClass The predicate evaluates to true for instances of this class * or one of its subclasses. */ public IsInstanceOf(Class expectedClass) { this.expectedClass = expectedClass; this.matchableClass = matchableClass(expectedClass); } private static Class matchableClass(Class expectedClass) { if (boolean.class.equals(expectedClass)) return Boolean.class; if (byte.class.equals(expectedClass)) return Byte.class; if (char.class.equals(expectedClass)) return Character.class; if (double.class.equals(expectedClass)) return Double.class; if (float.class.equals(expectedClass)) return Float.class; if (int.class.equals(expectedClass)) return Integer.class; if (long.class.equals(expectedClass)) return Long.class; if (short.class.equals(expectedClass)) return Short.class; return expectedClass; } @Override protected boolean matches(Object item, Description mismatchDescription) { if (null == item) { mismatchDescription.appendText("null"); return false; } if (!matchableClass.isInstance(item)) { mismatchDescription.appendValue(item).appendText(" is a " + item.getClass().getName()); return false; } return true; } public void describeTo(Description description) { description.appendText("an instance of ") .appendText(expectedClass.getName()); } /** * Is the value an instance of a particular type? * This version assumes no relationship between the required type and * the signature of the method that sets it up, for example in * assertThat(anObject, instanceOf(Thing.class)); */ @SuppressWarnings("unchecked") @Factory public static Matcher instanceOf(Class type) { return (Matcher) new IsInstanceOf(type); } /** * Is the value an instance of a particular type? * Use this version to make generics conform, for example in * the JMock clause with(any(Thing.class)) */ @SuppressWarnings("unchecked") @Factory public static Matcher any(Class type) { return (Matcher) new IsInstanceOf(type); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/IsNot.java0000644000175000017500000000222711175325204027067 0ustar moellermoeller/* Copyright (c) 2000-2009 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Calculates the logical negation of a matcher. */ public class IsNot extends BaseMatcher { private final Matcher matcher; public IsNot(Matcher matcher) { this.matcher = matcher; } public boolean matches(Object arg) { return !matcher.matches(arg); } public void describeTo(Description description) { description.appendText("not ").appendDescriptionOf(matcher); } /** * Inverts the rule. */ @Factory public static Matcher not(Matcher matcher) { return new IsNot(matcher); } /** * This is a shortcut to the frequently used not(equalTo(x)). * * For example: assertThat(cheese, is(not(equalTo(smelly)))) * vs. assertThat(cheese, is(not(smelly))) */ @Factory public static Matcher not(T value) { return not(equalTo(value)); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/IsNull.java0000644000175000017500000000231611123257170027237 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.core.IsNot.not; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Factory; import org.hamcrest.BaseMatcher; /** * Is the value null? */ public class IsNull extends BaseMatcher { public boolean matches(Object o) { return o == null; } public void describeTo(Description description) { description.appendText("null"); } /** * Matches if value is null. */ @Factory public static Matcher nullValue() { return new IsNull(); } /** * Matches if value is not null. */ @Factory public static Matcher notNullValue() { return not(IsNull.nullValue()); } /** * Matches if value is null. With type inference. */ @Factory public static Matcher nullValue(@SuppressWarnings("unused") Class type) { return nullValue(); } /** * Matches if value is not null. With type inference. */ @Factory public static Matcher notNullValue(@SuppressWarnings("unused") Class type) { return notNullValue(); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/IsSame.java0000644000175000017500000000170011123257170027206 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Is the value the same object as another value? */ public class IsSame extends BaseMatcher { private final T object; public IsSame(T object) { this.object = object; } public boolean matches(Object arg) { return arg == object; } public void describeTo(Description description) { description.appendText("sameInstance(") .appendValue(object) .appendText(")"); } /** * Creates a new instance of IsSame * * @param object The predicate evaluates to true only when the argument is * this object. */ @Factory public static Matcher sameInstance(T object) { return new IsSame(object); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/ShortcutCombination.java0000644000175000017500000000157511123257170032035 0ustar moellermoellerpackage org.hamcrest.core; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; abstract class ShortcutCombination extends BaseMatcher { private final Iterable> matchers; public ShortcutCombination(Iterable> matchers) { this.matchers = matchers; } public abstract boolean matches(Object o); public abstract void describeTo(Description description); protected boolean matches(Object o, boolean shortcut) { for (Matcher matcher : matchers) { if (matcher.matches(o) == shortcut) { return shortcut; } } return !shortcut; } public void describeTo(Description description, String operator) { description.appendList("(", " " + operator + " ", ")", matchers); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/StringContains.java0000644000175000017500000000124311123257170030774 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Tests if the argument is a string that contains a substring. */ public class StringContains extends SubstringMatcher { public StringContains(String substring) { super(substring); } @Override protected boolean evalSubstringOf(String s) { return s.indexOf(substring) >= 0; } @Override protected String relationship() { return "containing"; } @Factory public static Matcher containsString(String substring) { return new StringContains(substring); } }libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/StringEndsWith.java0000644000175000017500000000123311123257170030742 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Tests if the argument is a string that contains a substring. */ public class StringEndsWith extends SubstringMatcher { public StringEndsWith(String substring) { super(substring); } @Override protected boolean evalSubstringOf(String s) { return s.endsWith(substring); } @Override protected String relationship() { return "ending with"; } @Factory public static Matcher endsWith(String substring) { return new StringEndsWith(substring); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/StringStartsWith.java0000644000175000017500000000124611123257170031335 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Tests if the argument is a string that contains a substring. */ public class StringStartsWith extends SubstringMatcher { public StringStartsWith(String substring) { super(substring); } @Override protected boolean evalSubstringOf(String s) { return s.startsWith(substring); } @Override protected String relationship() { return "starting with"; } @Factory public static Matcher startsWith(String substring) { return new StringStartsWith(substring); } }libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/SubstringMatcher.java0000644000175000017500000000212311123257170031311 0ustar moellermoellerpackage org.hamcrest.core; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; public abstract class SubstringMatcher extends TypeSafeMatcher { // TODO: Replace String with CharSequence to allow for easy interopability between // String, StringBuffer, StringBuilder, CharBuffer, etc (joe). protected final String substring; protected SubstringMatcher(final String substring) { this.substring = substring; } @Override public boolean matchesSafely(String item) { return evalSubstringOf(item); } @Override public void describeMismatchSafely(String item, Description mismatchDescription) { mismatchDescription.appendText("was \"").appendText(item).appendText("\""); } public void describeTo(Description description) { description.appendText("a string ") .appendText(relationship()) .appendText(" ") .appendValue(substring); } protected abstract boolean evalSubstringOf(String string); protected abstract String relationship(); }libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/core/package.html0000644000175000017500000000017211123257170027445 0ustar moellermoeller

Fundamental matchers of objects and values, and composite matchers.

libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/internal/0000755000175000017500000000000011675175275026071 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/internal/ArrayIterator.java0000644000175000017500000000131511123257170031503 0ustar moellermoellerpackage org.hamcrest.internal; import java.lang.reflect.Array; import java.util.Iterator; public class ArrayIterator implements Iterator { private final Object array; private int currentIndex = 0; public ArrayIterator(Object array) { if (!array.getClass().isArray()) { throw new IllegalArgumentException("not an array"); } this.array = array; } public boolean hasNext() { return currentIndex < Array.getLength(array); } public Object next() { return Array.get(array, currentIndex++); } public void remove() { throw new UnsupportedOperationException("cannot remove items from an array"); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/internal/ReflectiveTypeFinder.java0000644000175000017500000000605311123257170033001 0ustar moellermoeller/** * The TypeSafe classes, and their descendants, need a mechanism to find out what type has been used as a parameter * for the concrete matcher. Unfortunately, this type is lost during type erasure so we need to use reflection * to get it back, by picking out the type of a known parameter to a known method. * The catch is that, with bridging methods, this type is only visible in the class that actually implements * the expected method, so the ReflectiveTypeFinder needs to be applied to that class or a subtype. * * For example, the abstract TypeSafeDiagnosingMatcher<T> defines an abstract method *
protected abstract boolean matchesSafely(T item, Description mismatchDescription);
* By default it uses new ReflectiveTypeFinder("matchesSafely", 2, 0); to find the * parameterised type. If we create a TypeSafeDiagnosingMatcher<String>, the type * finder will return String.class. * * A FeatureMatcher is an abstract subclass of TypeSafeDiagnosingMatcher. * Although it has a templated implementation of matchesSafely(<T>, Decription);, the * actualy run-time signature of this is matchesSafely(Object, Description);. Instead, * we must find the type by reflecting on the concrete implementation of *
protected abstract U featureValueOf(T actual);
* a method which is declared in FeatureMatcher. * * In short, use this to extract a type from a method in the leaf class of a templated class hierarchy. * * @author Steve Freeman * @author Nat Pryce */ package org.hamcrest.internal; import java.lang.reflect.Method; public class ReflectiveTypeFinder { private final String methodName; private final int expectedNumberOfParameters; private final int typedParameter; public ReflectiveTypeFinder(String methodName, int expectedNumberOfParameters, int typedParameter) { this.methodName = methodName; this.expectedNumberOfParameters = expectedNumberOfParameters; this.typedParameter = typedParameter; } public Class findExpectedType(Class fromClass) { for (Class c = fromClass; c != Object.class; c = c.getSuperclass()) { for (Method method : c.getDeclaredMethods()) { if (canObtainExpectedTypeFrom(method)) { return expectedTypeFrom(method); } } } throw new Error("Cannot determine correct type for " + methodName + "() method."); } /** * @param method The method to examine. * @return true if this method references the relevant type */ protected boolean canObtainExpectedTypeFrom(Method method) { return method.getName().equals(methodName) && method.getParameterTypes().length == expectedNumberOfParameters && !method.isSynthetic(); } /** * @param method The method from which to extract * @return The type we're looking for */ protected Class expectedTypeFrom(Method method) { return method.getParameterTypes()[typedParameter]; } }libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/internal/SelfDescribingValue.java0000644000175000017500000000056311123257170032577 0ustar moellermoellerpackage org.hamcrest.internal; import org.hamcrest.Description; import org.hamcrest.SelfDescribing; public class SelfDescribingValue implements SelfDescribing { private T value; public SelfDescribingValue(T value) { this.value = value; } public void describeTo(Description description) { description.appendValue(value); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/internal/SelfDescribingValueIterator.javalibhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/internal/SelfDescribingValueIterator.j0000644000175000017500000000104511123257170033615 0ustar moellermoellerpackage org.hamcrest.internal; import java.util.Iterator; import org.hamcrest.SelfDescribing; public class SelfDescribingValueIterator implements Iterator { private Iterator values; public SelfDescribingValueIterator(Iterator values) { this.values = values; } public boolean hasNext() { return values.hasNext(); } public SelfDescribing next() { return new SelfDescribingValue(values.next()); } public void remove() { values.remove(); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/BaseDescription.java0000644000175000017500000000753011123257170030162 0ustar moellermoellerpackage org.hamcrest; import static java.lang.String.valueOf; import java.util.Arrays; import java.util.Iterator; import org.hamcrest.internal.ArrayIterator; import org.hamcrest.internal.SelfDescribingValueIterator; /** * A {@link Description} that is stored as a string. */ public abstract class BaseDescription implements Description { public Description appendText(String text) { append(text); return this; } public Description appendDescriptionOf(SelfDescribing value) { value.describeTo(this); return this; } public Description appendValue(Object value) { if (value == null) { append("null"); } else if (value instanceof String) { toJavaSyntax((String) value); } else if (value instanceof Character) { append('"'); toJavaSyntax((Character) value); append('"'); } else if (value instanceof Short) { append('<'); append(valueOf(value)); append("s>"); } else if (value instanceof Long) { append('<'); append(valueOf(value)); append("L>"); } else if (value instanceof Float) { append('<'); append(valueOf(value)); append("F>"); } else if (value.getClass().isArray()) { appendValueList("[",", ","]", new ArrayIterator(value)); } else { append('<'); append(valueOf(value)); append('>'); } return this; } public Description appendValueList(String start, String separator, String end, T... values) { return appendValueList(start, separator, end, Arrays.asList(values)); } public Description appendValueList(String start, String separator, String end, Iterable values) { return appendValueList(start, separator, end, values.iterator()); } private Description appendValueList(String start, String separator, String end, Iterator values) { return appendList(start, separator, end, new SelfDescribingValueIterator(values)); } public Description appendList(String start, String separator, String end, Iterable values) { return appendList(start, separator, end, values.iterator()); } private Description appendList(String start, String separator, String end, Iterator i) { boolean separate = false; append(start); while (i.hasNext()) { if (separate) append(separator); appendDescriptionOf(i.next()); separate = true; } append(end); return this; } /** * Append the String str to the description. * The default implementation passes every character to {@link #append(char)}. * Override in subclasses to provide an efficient implementation. */ protected void append(String str) { for (int i = 0; i < str.length(); i++) { append(str.charAt(i)); } } /** * Append the char c to the description. */ protected abstract void append(char c); private void toJavaSyntax(String unformatted) { append('"'); for (int i = 0; i < unformatted.length(); i++) { toJavaSyntax(unformatted.charAt(i)); } append('"'); } private void toJavaSyntax(char ch) { switch (ch) { case '"': append("\\\""); break; case '\n': append("\\n"); break; case '\r': append("\\r"); break; case '\t': append("\\t"); break; default: append(ch); } } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/BaseMatcher.java0000644000175000017500000000125711123257170027262 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest; /** * BaseClass for all Matcher implementations. * * @see Matcher */ public abstract class BaseMatcher implements Matcher { /** * @see Matcher#_dont_implement_Matcher___instead_extend_BaseMatcher_() */ public final void _dont_implement_Matcher___instead_extend_BaseMatcher_() { // See Matcher interface for an explanation of this method. } public void describeMismatch(Object item, Description description) { description.appendText("was ").appendValue(item); } @Override public String toString() { return StringDescription.toString(this); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/CustomMatcher.java0000644000175000017500000000216411123257170027660 0ustar moellermoellerpackage org.hamcrest; /** * Utility class for writing one off matchers. * For example: *
 * Matcher<String> aNonEmptyString = new CustomMatcher<String>("a non empty string") {
 *   public boolean matches(Object object) {
 *     return ((object instanceof String) && !((String) object).isEmpty();
 *   }
 * };
 * 
*

* This class is designed for scenarios where an anonymous inner class * matcher makes sense. It should not be used by API designers implementing * matchers. * * @author Neil Dunn * @see CustomTypeSafeMatcher for a type safe variant of this class that you probably * want to use. * @param The type of object being matched. */ public abstract class CustomMatcher extends BaseMatcher { private final String fixedDescription; public CustomMatcher(String description) { if (description == null) { throw new IllegalArgumentException("Description should be non null!"); } this.fixedDescription = description; } public final void describeTo(Description description) { description.appendText(fixedDescription); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/CustomTypeSafeMatcher.java0000644000175000017500000000232111123257170031314 0ustar moellermoellerpackage org.hamcrest; /** * Utility class for writing one off matchers. * For example: *

 * Matcher<String> aNonEmptyString = new CustomTypeSafeMatcher<String>("a non empty string") {
 *   public boolean matchesSafely(String string) {
 *     return !string.isEmpty();
 *   }
 *   public void describeMismatchSafely(String string, Description mismatchDescription) {
 *     mismatchDescription.appendText("was empty");
 *   }
 * };
 * 
* This is a variant of {@link CustomMatcher} that first type checks * the argument being matched. By the time {@link #matchesSafely(T)} is * is called the argument is guaranteed to be non-null and of the correct * type. * * @author Neil Dunn * @param The type of object being matched */ public abstract class CustomTypeSafeMatcher extends TypeSafeMatcher { private final String fixedDescription; public CustomTypeSafeMatcher(String description) { if (description == null) { throw new IllegalArgumentException("Description must be non null!"); } this.fixedDescription = description; } public final void describeTo(Description description) { description.appendText(fixedDescription); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/Description.java0000644000175000017500000000435411123257170027370 0ustar moellermoellerpackage org.hamcrest; /** * A description of a Matcher. A Matcher will describe itself to a description * which can later be used for reporting. * * @see Matcher#describeTo(Description) */ public interface Description { /** * A description that consumes input but does nothing. */ static final Description NONE = new NullDescription(); /** * Appends some plain text to the description. */ Description appendText(String text); /** * Appends the description of a {@link SelfDescribing} value to this description. */ Description appendDescriptionOf(SelfDescribing value); /** * Appends an arbitary value to the description. */ Description appendValue(Object value); /** * Appends a list of values to the description. */ Description appendValueList(String start, String separator, String end, T... values); /** * Appends a list of values to the description. */ Description appendValueList(String start, String separator, String end, Iterable values); /** * Appends a list of {@link org.hamcrest.SelfDescribing} objects * to the description. */ Description appendList(String start, String separator, String end, Iterable values); public static final class NullDescription implements Description { public Description appendDescriptionOf(SelfDescribing value) { return this; } public Description appendList(String start, String separator, String end, Iterable values) { return this; } public Description appendText(String text) { return this; } public Description appendValue(Object value) { return this; } public Description appendValueList(String start, String separator, String end, T... values) { return this; } public Description appendValueList(String start, String separator, String end, Iterable values) { return this; } @Override public String toString() { return ""; } } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/DiagnosingMatcher.java0000644000175000017500000000070711123257170030471 0ustar moellermoellerpackage org.hamcrest; /** * TODO(ngd): Document. * * @param */ public abstract class DiagnosingMatcher extends BaseMatcher { public final boolean matches(Object item) { return matches(item, Description.NONE); } @Override public final void describeMismatch(Object item, Description mismatchDescription) { matches(item, mismatchDescription); } protected abstract boolean matches(Object item, Description mismatchDescription); } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/Factory.java0000644000175000017500000000067411123257170026515 0ustar moellermoellerpackage org.hamcrest; import static java.lang.annotation.ElementType.METHOD; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Target; /** * Marks a Hamcrest static factory method so tools recognise them. * A factory method is an equivalent to a named constructor. * * @author Joe Walnes */ @Retention(RUNTIME) @Target({METHOD}) public @interface Factory { } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java0000644000175000017500000000354511175026440030006 0ustar moellermoellerpackage org.hamcrest; import org.hamcrest.internal.ReflectiveTypeFinder; /** * Supporting class for matching a feature of an object. Implement featureValueOf() * in a subclass to pull out the feature to be matched against. * * @param The type of the object to be matched * @param The type of the feature to be matched */ public abstract class FeatureMatcher extends TypeSafeDiagnosingMatcher { private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("featureValueOf", 1, 0); private final Matcher subMatcher; private final String featureDescription; private final String featureName; /** * Constructor * @param subMatcher The matcher to apply to the feature * @param featureDescription Descriptive text to use in describeTo * @param featureName Identifying text for mismatch message */ public FeatureMatcher(Matcher subMatcher, String featureDescription, String featureName) { super(TYPE_FINDER); this.subMatcher = subMatcher; this.featureDescription = featureDescription; this.featureName = featureName; } /** * Implement this to extract the interesting feature. * @param actual the target object * @return the feature to be matched */ protected abstract U featureValueOf(T actual); @Override protected boolean matchesSafely(T actual, Description mismatchDescription) { final U featureValue = featureValueOf(actual); if (!subMatcher.matches(featureValue)) { mismatchDescription.appendText(featureName).appendText(" "); subMatcher.describeMismatch(featureValue, mismatchDescription); return false; } return true; }; public final void describeTo(Description description) { description.appendText(featureDescription).appendText(" ") .appendDescriptionOf(subMatcher); } }libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/Matcher.java0000644000175000017500000000430411123257170026463 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest; /** * A matcher over acceptable values. * A matcher is able to describe itself to give feedback when it fails. *

* Matcher implementations should NOT directly implement this interface. * Instead, extend the {@link BaseMatcher} abstract class, * which will ensure that the Matcher API can grow to support * new features and remain compatible with all Matcher implementations. *

* For easy access to common Matcher implementations, use the static factory * methods in {@link CoreMatchers}. * * @see CoreMatchers * @see BaseMatcher */ public interface Matcher extends SelfDescribing { /** * Evaluates the matcher for argument item. *

* This method matches against Object, instead of the generic type T. This is * because the caller of the Matcher does not know at runtime what the type is * (because of type erasure with Java generics). It is down to the implementations * to check the correct type. * * @param item the object against which the matcher is evaluated. * @return true if item matches, otherwise false. * * @see BaseMatcher */ boolean matches(Object item); /** * Generate a description of why the matcher has not accepted the item. * The description will be part of a larger description of why a matching * failed, so it should be concise. * This method assumes that matches(item) is false, but * will not check this. * * @param item The item that the Matcher has rejected. * @param mismatchDescription * The description to be built or appended to. */ void describeMismatch(Object item, Description mismatchDescription); /** * This method simply acts a friendly reminder not to implement Matcher directly and * instead extend BaseMatcher. It's easy to ignore JavaDoc, but a bit harder to ignore * compile errors . * * @see Matcher for reasons why. * @see BaseMatcher * @deprecated to make */ @Deprecated void _dont_implement_Matcher___instead_extend_BaseMatcher_(); } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/MatcherAssert.java0000644000175000017500000000165211123257170027650 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest; public class MatcherAssert { public static void assertThat(T actual, Matcher matcher) { assertThat("", actual, matcher); } public static void assertThat(String reason, T actual, Matcher matcher) { if (!matcher.matches(actual)) { Description description = new StringDescription(); description.appendText(reason) .appendText("\nExpected: ") .appendDescriptionOf(matcher) .appendText("\n but: "); matcher.describeMismatch(actual, description); throw new AssertionError(description.toString()); } } public static void assertThat(String reason, boolean assertion) { if (!assertion) { throw new AssertionError(reason); } } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/SelfDescribing.java0000644000175000017500000000072211123257170027763 0ustar moellermoellerpackage org.hamcrest; /** * The ability of an object to describe itself. */ public interface SelfDescribing { /** * Generates a description of the object. The description may be part of a * a description of a larger object of which this is just a component, so it * should be worded appropriately. * * @param description * The description to be built or appended to. */ void describeTo(Description description); }libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/StringDescription.java0000644000175000017500000000275311123257170030560 0ustar moellermoellerpackage org.hamcrest; import java.io.IOException; /** * A {@link Description} that is stored as a string. */ public class StringDescription extends BaseDescription { private final Appendable out; public StringDescription() { this(new StringBuilder()); } public StringDescription(Appendable out) { this.out = out; } /** * Return the description of a {@link SelfDescribing} object as a String. * * @param selfDescribing * The object to be described. * @return * The description of the object. */ public static String toString(SelfDescribing selfDescribing) { return new StringDescription().appendDescriptionOf(selfDescribing).toString(); } /** * Alias for {@link #toString(SelfDescribing)}. */ public static String asString(SelfDescribing selfDescribing) { return toString(selfDescribing); } @Override protected void append(String str) { try { out.append(str); } catch (IOException e) { throw new RuntimeException("Could not write description", e); } } @Override protected void append(char c) { try { out.append(c); } catch (IOException e) { throw new RuntimeException("Could not write description", e); } } /** * Returns the description as a string. */ @Override public String toString() { return out.toString(); } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/TypeSafeDiagnosingMatcher.java0000644000175000017500000000446211123257170032134 0ustar moellermoellerpackage org.hamcrest; import org.hamcrest.internal.ReflectiveTypeFinder; /** * Convenient base class for Matchers that require a non-null value of a specific type * and that will report why the received value has been rejected. * This implements the null check, checks the type and then casts. * To use, implement

matchesSafely()
. * * @param * @author Neil Dunn * @author Nat Pryce * @author Steve Freeman */ public abstract class TypeSafeDiagnosingMatcher extends BaseMatcher { private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesSafely", 2, 0); private final Class expectedType; /** * Subclasses should implement this. The item will already have been checked * for the specific type and will never be null. */ protected abstract boolean matchesSafely(T item, Description mismatchDescription); /** * Use this constructor if the subclass that implements matchesSafely * is not the class that binds <T> to a type. * @param expectedType The expectedType of the actual value. */ protected TypeSafeDiagnosingMatcher(Class expectedType) { this.expectedType = expectedType; } /** * Use this constructor if the subclass that implements matchesSafely * is not the class that binds <T> to a type. * @param typeFinder A type finder to extract the type */ protected TypeSafeDiagnosingMatcher(ReflectiveTypeFinder typeFinder) { this.expectedType = typeFinder.findExpectedType(getClass()); } /** * The default constructor for simple sub types */ protected TypeSafeDiagnosingMatcher() { this(TYPE_FINDER); } @SuppressWarnings("unchecked") public final boolean matches(Object item) { return item != null && expectedType.isInstance(item) && matchesSafely((T) item, new Description.NullDescription()); } @SuppressWarnings("unchecked") @Override public final void describeMismatch(Object item, Description mismatchDescription) { if (item == null || !expectedType.isInstance(item)) { super.describeMismatch(item, mismatchDescription); } else { matchesSafely((T) item, mismatchDescription); } } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/TypeSafeMatcher.java0000644000175000017500000000554311202570227030131 0ustar moellermoellerpackage org.hamcrest; import org.hamcrest.internal.ReflectiveTypeFinder; /** * Convenient base class for Matchers that require a non-null value of a specific type. * This simply implements the null check, checks the type and then casts. * * @author Joe Walnes * @author Steve Freeman * @author Nat Pryce */ public abstract class TypeSafeMatcher extends BaseMatcher { private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesSafely", 1, 0); final private Class expectedType; /** * The default constructor for simple sub types */ protected TypeSafeMatcher() { this(TYPE_FINDER); } /** * Use this constructor if the subclass that implements matchesSafely * is not the class that binds <T> to a type. * @param expectedType The expectedType of the actual value. */ protected TypeSafeMatcher(Class expectedType) { this.expectedType = expectedType; } /** * Use this constructor if the subclass that implements matchesSafely * is not the class that binds <T> to a type. * @param typeFinder A type finder to extract the type */ protected TypeSafeMatcher(ReflectiveTypeFinder typeFinder) { this.expectedType = typeFinder.findExpectedType(getClass()); } /** * Subclasses should implement this. The item will already have been checked for * the specific type and will never be null. */ protected abstract boolean matchesSafely(T item); /** * Subclasses should override this. The item will already have been checked for * the specific type and will never be null. */ protected void describeMismatchSafely(T item, Description mismatchDescription) { super.describeMismatch(item, mismatchDescription); } /** * Methods made final to prevent accidental override. * If you need to override this, there's no point on extending TypeSafeMatcher. * Instead, extend the {@link BaseMatcher}. */ @SuppressWarnings({"unchecked"}) public final boolean matches(Object item) { return item != null && expectedType.isInstance(item) && matchesSafely((T) item); } @SuppressWarnings("unchecked") @Override final public void describeMismatch(Object item, Description description) { if (item == null) { super.describeMismatch(item, description); } else if (! expectedType.isInstance(item)) { description.appendText("was a ") .appendText(item.getClass().getName()) .appendText(" (") .appendValue(item) .appendText(")"); } else { describeMismatchSafely((T)item, description); } } } libhamcrest-java-1.2/hamcrest-core/src/main/java/org/hamcrest/package.html0000644000175000017500000000033211123257170026513 0ustar moellermoeller

The stable API defining Matcher and its associated interfaces and classes. Hamcrest sub-projects define their convenience classes in the org.hamcrest package.

libhamcrest-java-1.2/hamcrest-examples/0000755000175000017500000000000010632277411020075 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-examples/src/0000755000175000017500000000000010632277411020664 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-examples/src/main/0000755000175000017500000000000010632277411021610 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-examples/src/main/java/0000755000175000017500000000000010632277411022531 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/0000755000175000017500000000000010632277411023320 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/0000755000175000017500000000000010632277411025126 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/0000755000175000017500000000000010632277411026744 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit3/0000755000175000017500000000000011675175275030175 5ustar moellermoeller././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit3/ExampleWithAssertThat.javalibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit3/ExampleWithAssertT0000644000175000017500000000116211033250101033617 0ustar moellermoellerpackage org.hamcrest.examples.junit3; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import junit.framework.TestCase; /** * Demonstrates how Hamcrest matchers can be used with assertThat() * using JUnit 3.8.x. * * @author Joe Walnes */ public class ExampleWithAssertThat extends TestCase { public void testUsingAssertThat() { assertThat("xx", is("xx")); assertThat("yy", is(not("xx"))); assertThat("i like cheese", containsString("cheese")); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit3/ExampleWithEasyMock2.javalibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit3/ExampleWithEasyMoc0000644000175000017500000000445111033250101033576 0ustar moellermoellerpackage org.hamcrest.examples.junit3; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import static org.hamcrest.EasyMock2Matchers.equalTo; import junit.framework.TestCase; /** * Demonstrates how HamCrest matchers can be used from EasyMock with * JUnit 3.x. * * @author Joe Walnes */ public class ExampleWithEasyMock2 extends TestCase { /* EasyMock (2) specific notes: * * Important terminology: * What EasyMock2 calls 'IArgumentMatcher', Hamcrest calls 'Matchers'. * * This functionality is available for EasyMock 2.x but NOT EasyMock 1.x. * * The class extends the standard JUnit TestCase. * * The additional Hamcrest Matchers can be used by using a static import: * import static org.hamcrest.EasyMockMatchers.*; * * This provides the Hamcrest library of Matchers through an interface * that will provide an adapter to EasyMock IArgumentMatchers and report * them to EasyMock as it needs to keep track of them. */ /** * A sample interface that will be mocked. */ public static interface AnInterface { void doStuff(String string); } private AnInterface mock = createMock(AnInterface.class); /** * This examples shows using a mock with a standard EasyMock2 matcher. * Hamcrest is not used here. */ public void testUsingAnEasyMockMatcher() { mock.doStuff(eq("i like cheese and stuff")); replay(mock); mock.doStuff("i like cheese and stuff"); verify(mock); } /** * This examples shows using a mock with a Hamcrest matcher, adapted * to jMock. */ public void testUsingAHamcrestMatcher() { mock.doStuff(equalTo("xx")); replay(mock); mock.doStuff("xx"); verify(mock); } /** * This examples shows using the standard jMock assertThat() method * with both jMock Constraints and Hamcrest Matchers. */ public void testUsingAssertThat() { // TODO(joe): This is a bit tricker with EasyMock. //assertThat("xx", equal("xx")); //assertThat("yy", not(equal("xx"))); //assertThat("i like cheese", startsWith("i like")); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit3/ExampleWithJMock1.javalibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit3/ExampleWithJMock1.0000644000175000017500000000457311033250101033405 0ustar moellermoellerpackage org.hamcrest.examples.junit3; import static org.hamcrest.JMock1Matchers.equalTo; import org.jmock.Mock; import org.jmock.MockObjectTestCase; /** * Demonstrates how HamCrest matchers can be used from jMock with JUnit 3.8.x. * * @author Joe Walnes */ public class ExampleWithJMock1 extends MockObjectTestCase { /* jMock specific notes: * * Important terminology: * What jMock calls 'Constraints', Hamcrest calls 'Matchers'. * * Note: This is only valid for jMock1. jMock2 supports Hamcrest out * of the box. * * The class extends org.jmock.MockObjectTestCase as usual. * This provides: * - The mock() methods and syntactic sugar for setting up mocks. * - Auto verification of mocks. * - jMock's implementation of assertThat(). * - jMock's standard Constraints. * * The additional Hamcrest Matchers can be used by using a static import: * import static org.hamcrest.JMockMatchers.*; * * This provides the Hamcrest library of Matchers through an interface * that will provide an adapter to JMock Constraints. */ /** * A sample interface to be mocked. */ public static interface AnInterface { void doStuff(String string); } private Mock mock = mock(AnInterface.class); private AnInterface anInterface = (AnInterface) mock.proxy(); /** * This examples shows using a mock with a standard jMock constraint. * Hamcrest is not used here. */ public void testUsingAJMockConstraint() { mock.expects(atLeastOnce()).method("doStuff") .with(stringContains("cheese")); anInterface.doStuff("i like cheese and stuff"); } /** * This examples shows using a mock with a Hamcrest matcher, adapted * to jMock. */ public void testUsingAHamcrestMatcher() { mock.expects(atLeastOnce()).method("doStuff") .with(equalTo("xx")); anInterface.doStuff("xx"); } /** * This examples shows using the standard jMock assertThat() method * with both jMock Constraints and Hamcrest Matchers. */ public void testUsingAssertThat() { assertThat("i like cheese", stringContains("cheese")); // jMock Constraint. assertThat("xx", equalTo("xx")); // Hamcrest Matcher. assertThat("yy", not(equalTo("xx"))); // Mixture of both. } } libhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit4/0000755000175000017500000000000011675175275030176 5ustar moellermoeller././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit4/ExampleWithAssertThat.javalibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit4/ExampleWithAssertT0000644000175000017500000000372311121050350033627 0ustar moellermoellerpackage org.hamcrest.examples.junit4; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import org.junit.Test; /** * Demonstrates how HamCrest matchers can be used with assertThat() * using JUnit 4.x. * * @author Joe Walnes */ public class ExampleWithAssertThat { @Test public void usingAssertThat() { assertThat("xx", is("xx")); assertThat("yy", is(not("xx"))); assertThat("i like cheese", containsString("cheese")); } /** * Allow JUnit 4 test to be run under JUnit 3. */ public static junit.framework.Test suite() { return new junit.framework.JUnit4TestAdapter(ExampleWithAssertThat.class); } public static class ComplicatedClass { private int firstNumber = 23; private int secondNumber = 45; private String someText = "This is useful text"; public String whichOne(boolean first) { return someText + (first ? firstNumber : secondNumber); } } @Test public void showMismatch() { ComplicatedClass complicated = new ComplicatedClass(); assertThat(complicated, shouldBe("the wrong thing")); } private Matcher shouldBe(String string) { return new TypeSafeMatcher() { public void describeTo(Description description) { // TODO Auto-generated method stub } @Override public boolean matchesSafely(ComplicatedClass item) { // TODO Auto-generated method stub return false; } @Override public void describeMismatchSafely(ComplicatedClass item, Description mismatchDescription) { // TODO Auto-generated method stub } }; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit4/ExampleWithEasyMock2.javalibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/junit4/ExampleWithEasyMoc0000644000175000017500000000474611033250101033606 0ustar moellermoellerpackage org.hamcrest.examples.junit4; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import static org.hamcrest.EasyMock2Matchers.equalTo; import org.junit.Test; /** * Demonstrates how HamCrest matchers can be used from EasyMock with * JUnit 4.x. * * @author Joe Walnes */ public class ExampleWithEasyMock2 { /* EasyMock (2) specific notes: * * Important terminology: * What EasyMock2 calls 'IArgumentMatcher', Hamcrest calls 'Matchers'. * * This functionality is available for EasyMock 2.x but NOT EasyMock 1.x. * * The class does not need to extend anything. * * The additional Hamcrest Matchers can be used by using a static import: * import static org.hamcrest.EasyMockMatchers.*; * * This provides the Hamcrest library of Matchers through an interface * that will provide an adapter to EasyMock IArgumentMatchers and report * them to EasyMock as it needs to keep track of them. */ /** * A sample interface that will be mocked. */ public static interface AnInterface { void doStuff(String string); } private AnInterface mock = createMock(AnInterface.class); /** * This examples shows using a mock with a standard EasyMock2 matcher. * Hamcrest is not used here. */ @Test public void usingAnEasyMockMatcher() { mock.doStuff(eq("i like cheese and stuff")); replay(mock); mock.doStuff("i like cheese and stuff"); verify(mock); } /** * This examples shows using a mock with a Hamcrest matcher, adapted * to jMock. */ @Test public void usingAHamcrestMatcher() { mock.doStuff(equalTo("xx")); replay(mock); mock.doStuff("xx"); verify(mock); } /** * This examples shows using the standard jMock assertThat() method * with both jMock Constraints and Hamcrest Matchers. */ @Test public void usingAssertThat() { // TODO(joe): This is a bit tricker with EasyMock. //assertThat("xx", isTwoXs()); //assertThat("yy", not(isTwoXs())); //assertThat("i like cheese", startsWith("i like")); } /** * Allow JUnit 4 test to be run under JUnit 3. */ public static junit.framework.Test suite() { return new junit.framework.JUnit4TestAdapter(ExampleWithEasyMock2.class); } } libhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/testng/0000755000175000017500000000000011675175275030265 5ustar moellermoeller././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/testng/ExampleWithAssertThat.javalibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/testng/ExampleWithAssertT0000644000175000017500000000115411033250101033710 0ustar moellermoellerpackage org.hamcrest.examples.testng; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import org.testng.annotations.Test; /** * Demonstrates how Hamcrest matchers can be used with assertThat() * using TestNG. * * @author Joe Walnes */ @Test public class ExampleWithAssertThat { @Test public void usingAssertThat() { assertThat("xx", is("xx")); assertThat("yy", is(not("xx"))); assertThat("i like cheese", containsString("cheese")); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/testng/ExampleWithEasyMock2.javalibhamcrest-java-1.2/hamcrest-examples/src/main/java/org/hamcrest/examples/testng/ExampleWithEasyMoc0000644000175000017500000000466611033250101033676 0ustar moellermoellerpackage org.hamcrest.examples.testng; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import static org.hamcrest.EasyMock2Matchers.equalTo; import org.testng.annotations.Configuration; import org.testng.annotations.Test; /** * Demonstrates how Hamcrest matchers can be used from EasyMock with * TestNG. * * @author Joe Walnes */ @Test public class ExampleWithEasyMock2 { /* EasyMock (2) specific notes: * * Important terminology: * What EasyMock2 calls 'IArgumentMatcher', Hamcrest calls 'Matchers'. * * This functionality is available for EasyMock 2.x but NOT EasyMock 1.x. * * The class does not need to extend anything. * * The additional Hamcrest Matchers can be used by using a static import: * import static org.hamcrest.EasyMockMatchers.*; * * This provides the Hamcrest library of Matchers through an interface * that will provide an adapter to EasyMock IArgumentMatchers and report * them to EasyMock as it needs to keep track of them. */ /** * A sample interface that will be mocked. */ public static interface AnInterface { void doStuff(String string); } private AnInterface mock; @Configuration(beforeTestMethod = true) public void setUpMock() { mock = createMock(AnInterface.class); } /** * This examples shows using a mock with a standard EasyMock2 matcher. * Hamcrest is not used here. */ @Test public void usingAnEasyMockMatcher() { mock.doStuff(eq("i like cheese and stuff")); replay(mock); mock.doStuff("i like cheese and stuff"); verify(mock); } /** * This examples shows using a mock with a Hamcrest matcher, adapted * to jMock. */ @Test public void usingAHamcrestMatcher() { mock.doStuff(equalTo("xx")); replay(mock); mock.doStuff("xx"); verify(mock); } /** * This examples shows using the standard jMock assertThat() method * with both jMock Constraints and Hamcrest Matchers. */ @Test public void usingAssertThat() { // TODO(joe): This is a bit tricker with EasyMock. //assertThat("xx", isTwoXs()); //assertThat("yy", not(isTwoXs())); //assertThat("i like cheese", startsWith("i like")); } } libhamcrest-java-1.2/hamcrest-generator/0000755000175000017500000000000010632277426020253 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-generator/src/0000755000175000017500000000000010632277426021042 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-generator/src/main/0000755000175000017500000000000010632277426021766 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-generator/src/main/java/0000755000175000017500000000000010632277427022710 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/0000755000175000017500000000000010632277427023477 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/0000755000175000017500000000000010632277427025305 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/0000755000175000017500000000000011675175275027301 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/config/0000755000175000017500000000000011675175275030546 5ustar moellermoeller././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/config/XmlConfigurator.javalibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/config/XmlConfigurator.0000644000175000017500000001237111111332021033637 0ustar moellermoellerpackage org.hamcrest.generator.config; import org.hamcrest.generator.HamcrestFactoryWriter; import org.hamcrest.generator.QDoxFactoryReader; import org.hamcrest.generator.QuickReferenceWriter; import org.hamcrest.generator.ReflectiveFactoryReader; import org.hamcrest.generator.SugarConfiguration; import org.hamcrest.generator.SugarGenerator; import org.hamcrest.generator.QDox; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class XmlConfigurator { private final SugarConfiguration sugarConfiguration; private final ClassLoader classLoader; private final SAXParserFactory saxParserFactory; private final QDox qdox; public XmlConfigurator(SugarConfiguration sugarConfiguration, ClassLoader classLoader) { this.sugarConfiguration = sugarConfiguration; this.classLoader = classLoader; saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setNamespaceAware(true); qdox = new QDox(); } public void addSourceDir(File sourceDir) { qdox.addSourceTree(sourceDir); } public void load(InputSource inputSource) throws ParserConfigurationException, SAXException, IOException { SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(inputSource, new DefaultHandler() { @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (localName.equals("factory")) { String className = attributes.getValue("class"); try { addClass(className); } catch (ClassNotFoundException e) { throw new SAXException("Cannot find Matcher class : " + className); } } } }); } private void addClass(String className) throws ClassNotFoundException { Class cls = classLoader.loadClass(className); sugarConfiguration.addFactoryMethods( new QDoxFactoryReader(new ReflectiveFactoryReader(cls), qdox, className)); } public static void main(String[] args) throws Exception { if (args.length != 4) { System.err.println("Args: config-file source-dir generated-class output-dir"); System.err.println(""); System.err.println(" config-file : Path to config file listing matchers to generate sugar for."); System.err.println(" e.g. path/to/matchers.xml"); System.err.println(""); System.err.println(" source-dir : Path to Java source containing matchers to generate sugar for."); System.err.println(" May contain multiple paths, separated by commas."); System.err.println(" e.g. src/java,src/more-java"); System.err.println(""); System.err.println("generated-class : Full name of class to generate."); System.err.println(" e.g. org.myproject.MyMatchers"); System.err.println(""); System.err.println(" output-dir : Where to output generated code (package subdirs will be"); System.err.println(" automatically created)."); System.err.println(" e.g. build/generated-code"); System.exit(-1); } String configFile = args[0]; String srcDirs = args[1]; String fullClassName = args[2]; File outputDir = new File(args[3]); String fileName = fullClassName.replace('.', File.separatorChar) + ".java"; int dotIndex = fullClassName.lastIndexOf("."); String packageName = dotIndex == -1 ? "" : fullClassName.substring(0, dotIndex); String shortClassName = fullClassName.substring(dotIndex + 1); if (!outputDir.isDirectory()) { System.err.println("Output directory not found : " + outputDir.getAbsolutePath()); System.exit(-1); } File outputFile = new File(outputDir, fileName); outputFile.getParentFile().mkdirs(); SugarGenerator sugarGenerator = new SugarGenerator(); try { sugarGenerator.addWriter(new HamcrestFactoryWriter( packageName, shortClassName, new FileWriter(outputFile))); sugarGenerator.addWriter(new QuickReferenceWriter(System.out)); XmlConfigurator xmlConfigurator = new XmlConfigurator(sugarGenerator, XmlConfigurator.class.getClassLoader()); if (srcDirs.trim().length() > 0) { for (String srcDir : srcDirs.split(",")) { xmlConfigurator.addSourceDir(new File(srcDir)); } } xmlConfigurator.load(new InputSource(configFile)); System.out.println("Generating " + fullClassName); sugarGenerator.generate(); } finally { sugarGenerator.close(); } } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/EasyMock2FactoryWriter.javalibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/EasyMock2FactoryWriter.0000644000175000017500000001123511033250104033573 0ustar moellermoellerpackage org.hamcrest.generator; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** * {@link FactoryWriter} that outputs Java code which simply delegates all * factory methods to factory methods elsewhere. This is useful for grouping * lots of matcher classes into one class, so you know where to look to find * matchers. * * @author Joe Walnes * @see FactoryWriter */ public class EasyMock2FactoryWriter implements FactoryWriter { private final PrintWriter output; private final String javaPackageName; private final String javaClassName; private String indentationString = " "; private String newLine = "\n"; private int indentation = 1; public EasyMock2FactoryWriter(Writer output, String javaPackageName, String javaClassName) { this.javaPackageName = javaPackageName; this.javaClassName = javaClassName; this.output = new PrintWriter(output); } public void writeHeader() throws IOException { output.append("package ").append(javaPackageName).append(';').append(newLine).append(newLine); output.append("public class ").append(javaClassName).append(" {").append(newLine).append(newLine); } public void writeFooter() throws IOException { output.append('}').append(newLine); } public void close() throws IOException { output.close(); } public void flush() throws IOException { output.flush(); } public void writeMethod(String generatedMethodName, FactoryMethod factoryMethodToDelegateTo) throws IOException { writeJavaDoc(factoryMethodToDelegateTo); indent(); output.append("public static "); //writeGenericTypeParameters(factoryMethodToDelegateTo); String returnType = factoryMethodToDelegateTo.getGenerifiedType(); if (returnType == null) { returnType = "java.lang.Object"; } output.append(returnType); output.append(' ').append(generatedMethodName); writeParameters(factoryMethodToDelegateTo); writeExceptions(factoryMethodToDelegateTo); output.append(" {").append(newLine); indentation++; writeMethodBody(factoryMethodToDelegateTo); indentation--; indent(); output.append('}').append(newLine).append(newLine); } private void writeMethodBody(FactoryMethod factoryMethod) { indent(); output.append("org.hamcrest.integration.EasyMockAdapter.adapt(").append(newLine); indentation++; indent(); output.append(factoryMethod.getMatcherClass()); output.append('.').append(factoryMethod.getName()); output.append('('); boolean seenFirst = false; for (FactoryMethod.Parameter parameter : factoryMethod.getParameters()) { if (seenFirst) { output.append(", "); } else { seenFirst = true; } output.append(parameter.getName()); } output.append("));").append(newLine); indentation--; indent(); output.append("return null;").append(newLine); } private void writeExceptions(FactoryMethod factoryMethod) { boolean seenFirst = false; for (String exception : factoryMethod.getExceptions()) { if (seenFirst) { output.append(", "); } else { output.append(" throws "); seenFirst = true; } output.append(exception); } } private void writeParameters(FactoryMethod factoryMethod) { output.append('('); boolean seenFirst = false; for (FactoryMethod.Parameter parameter : factoryMethod.getParameters()) { if (seenFirst) { output.append(", "); } else { seenFirst = true; } output.append(parameter.getType()).append(' ').append(parameter.getName()); } output.append(')'); } private void writeJavaDoc(FactoryMethod factoryMethod) { if (factoryMethod.getJavaDoc() != null) { String[] lines = factoryMethod.getJavaDoc().split("\n"); if (lines.length > 0) { indent(); output.append("/**").append(newLine); for (String line : lines) { indent(); output.append(" * ").append(line).append(newLine); } indent(); output.append(" */").append(newLine); } } } private void indent() { for (int i = 0; i < indentation; i++) { output.append(indentationString); } } } libhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/FactoryMethod.java0000644000175000017500000001631211074021477032702 0ustar moellermoellerpackage org.hamcrest.generator; import java.util.ArrayList; import static java.util.Collections.unmodifiableList; import java.util.List; /** * Represents a Matcher Factory method. *

*

This class uses Strings to represent things instead of java.lang.reflect equivalents, * allowing methods to be defined from sources other than reflection of classes in the * classpath. * * @author Joe Walnes * @see SugarGenerator */ public class FactoryMethod { private final String matcherClass; private final String factoryMethod; private final String returnType; private String generifiedType; private List parameters = new ArrayList(); private List exceptions = new ArrayList(); private List genericTypeParameters = new ArrayList(); private String javaDoc; public FactoryMethod(String matcherClass, String factoryMethod, String returnType) { this.matcherClass = matcherClass; this.factoryMethod = factoryMethod; this.returnType = returnType; } /** * Original class this factory method came from. */ public String getMatcherClass() { return matcherClass; } /** * @return The fully qualified name of the type returned by the method. This should be a * subclass of org.hamcrest.Matcher. */ public String getReturnType() { return returnType; } /** * Original name of factory method. */ public String getName() { return factoryMethod; } public void setGenerifiedType(String generifiedType) { this.generifiedType = generifiedType; } /** * Generified type of matcher. * ie. 'public Matcher<THISBIT> blah(...)' */ public String getGenerifiedType() { return generifiedType; } public void addParameter(String type, String name) { parameters.add(new Parameter(type, name)); } /** * List of Parameters passed to factory method. * ie. 'public Matcher<...&ht;> blah(THIS, AND, THAT)' */ public List getParameters() { return unmodifiableList(parameters); } public void addException(String exception) { exceptions.add(exception); } /** * List of exceptions thrown by factory method. * ie. 'public Matcher<...> blah(...) throws THIS, THAT' */ public List getExceptions() { return unmodifiableList(exceptions); } public void addGenericTypeParameter(String genericTypeParameter) { genericTypeParameters.add(genericTypeParameter); } /** * List of generic type parameters for factory method definition. * ie. 'public <THIS,THAT> Matcher<...> blah(...)' * * @return */ public List getGenericTypeParameters() { return unmodifiableList(genericTypeParameters); } public void setJavaDoc(String javaDoc) { this.javaDoc = javaDoc; } /** * JavaDoc definition of factory method. * Excludes surrounding comment markers. * Note that using standard Java reflection it is not possible to obtain this, * however source code parsers can read this. */ public String getJavaDoc() { return javaDoc; } @SuppressWarnings({"RedundantIfStatement"}) @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; FactoryMethod that = (FactoryMethod) o; if (exceptions != null ? !exceptions.equals(that.exceptions) : that.exceptions != null) return false; if (factoryMethod != null ? !factoryMethod.equals(that.factoryMethod) : that.factoryMethod != null) return false; if (genericTypeParameters != null ? !genericTypeParameters.equals(that.genericTypeParameters) : that.genericTypeParameters != null) return false; if (generifiedType != null ? !generifiedType.equals(that.generifiedType) : that.generifiedType != null) return false; if (javaDoc != null ? !javaDoc.equals(that.javaDoc) : that.javaDoc != null) return false; if (matcherClass != null ? !matcherClass.equals(that.matcherClass) : that.matcherClass != null) return false; if (parameters != null ? !parameters.equals(that.parameters) : that.parameters != null) return false; return true; } @Override public int hashCode() { int result; result = (matcherClass != null ? matcherClass.hashCode() : 0); result = 31 * result + (factoryMethod != null ? factoryMethod.hashCode() : 0); result = 31 * result + (generifiedType != null ? generifiedType.hashCode() : 0); result = 31 * result + (parameters != null ? parameters.hashCode() : 0); result = 31 * result + (exceptions != null ? exceptions.hashCode() : 0); result = 31 * result + (genericTypeParameters != null ? genericTypeParameters.hashCode() : 0); result = 31 * result + (javaDoc != null ? javaDoc.hashCode() : 0); return result; } @Override public String toString() { return "{FactoryMethod: \n" + " matcherClass = " + matcherClass + "\n" + " factoryMethod = " + factoryMethod + "\n" + " generifiedType = " + generifiedType + "\n" + " parameters = " + parameters + "\n" + " exceptions = " + exceptions + "\n" + " genericTypeParameters = " + genericTypeParameters + "\n" + " javaDoc = " + javaDoc + "\n" + "}"; } /** * Represents a parameter passed to a factory method. * * @see FactoryMethod */ public static class Parameter { private final String type; private String name; public Parameter(String type, String name) { this.type = type; this.name = name; } /** * Type of parameter, including any generic declarations. */ public String getType() { return type; } /** * Name of parameter, if it can be obtained. If it cannot * be obtained, a sensible default will returned instead. */ public String getName() { return name; } public void setName(String name) { this.name = name; } @SuppressWarnings({"RedundantIfStatement"}) @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Parameter parameter = (Parameter) o; if (name != null ? !name.equals(parameter.name) : parameter.name != null) return false; if (type != null ? !type.equals(parameter.type) : parameter.type != null) return false; return true; } @Override public int hashCode() { int result; result = (type != null ? type.hashCode() : 0); result = 31 * result + (name != null ? name.hashCode() : 0); return result; } @Override public String toString() { return type + " " + name; } } } libhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/FactoryWriter.java0000644000175000017500000000226111033250104032716 0ustar moellermoellerpackage org.hamcrest.generator; import java.io.Closeable; import java.io.Flushable; import java.io.IOException; /** * Writes syntactic sugar code for factories. *

Implementations of this could include vanilla factory methods for * Hamcrest matchers, wrapped factories for other libraries or factories * in other languages (jython, jruby, groovy, etc). *

Usage:

*
 * writer.writeHeader(...);
 * 

* writer.writeMethod(...); * writer.writeMethod(...); * writer.writeMethod(...); * ... * writer.writeFooter(...); * writer.close(); *

* * @author Joe Walnes * @see FactoryMethod * @see SugarGenerator * @see HamcrestFactoryWriter */ public interface FactoryWriter extends Closeable, Flushable { /** * Write the code header. */ void writeHeader() throws IOException; /** * Writes code that delegates to a method. * * @param generatedMethodName * @param factoryMethodToDelegateTo */ void writeMethod(String generatedMethodName, FactoryMethod factoryMethodToDelegateTo) throws IOException; /** * Write any necessary code to finish the output. */ void writeFooter() throws IOException; } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/HamcrestFactoryWriter.javalibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/HamcrestFactoryWriter.j0000644000175000017500000001370311111307215033723 0ustar moellermoellerpackage org.hamcrest.generator; import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; import java.util.StringTokenizer; /** * {@link FactoryWriter} that outputs Java code which simply delegates all * Hamcrest factory methods to factory methods elsewhere. This is useful for * grouping lots of matcher classes into one class, so you only have to look * in one place for matchers. * * @author Joe Walnes * @see FactoryWriter */ public class HamcrestFactoryWriter implements FactoryWriter { private final PrintWriter output; private final String javaPackageName; private final String javaClassName; private String indentationString = " "; private String newLine = "\n"; private int indentation = 1; public HamcrestFactoryWriter(String javaPackageName, String javaClassName, Writer output) { this.javaPackageName = javaPackageName; this.javaClassName = javaClassName; this.output = new PrintWriter(output); } public void writeHeader() throws IOException { output.append("// Generated source.").append(newLine) .append("package ").append(javaPackageName).append(';').append(newLine).append(newLine); output.append("public class ").append(javaClassName).append(" {").append(newLine).append(newLine); } public void writeFooter() throws IOException { output.append('}').append(newLine); } public void close() throws IOException { output.close(); } public void flush() throws IOException { output.flush(); } public void writeMethod(String generatedMethodName, FactoryMethod factoryMethodToDelegateTo) throws IOException { writeJavaDoc(factoryMethodToDelegateTo); indent(); output.append("public static "); writeGenericTypeParameters(factoryMethodToDelegateTo); output.append(factoryMethodToDelegateTo.getReturnType()); if (factoryMethodToDelegateTo.getGenerifiedType() != null) { output.append('<').append(factoryMethodToDelegateTo.getGenerifiedType()).append('>'); } output.append(' ').append(generatedMethodName); writeParameters(factoryMethodToDelegateTo); writeExceptions(factoryMethodToDelegateTo); output.append(" {").append(newLine); indentation++; writeMethodBody(factoryMethodToDelegateTo); indentation--; indent(); output.append('}').append(newLine).append(newLine); } private void writeGenericTypeParameters(FactoryMethod factoryMethod) { if (!factoryMethod.getGenericTypeParameters().isEmpty()) { output.append('<'); boolean seenFirst = false; for (String type : factoryMethod.getGenericTypeParameters()) { if (seenFirst) { output.append(", "); } else { seenFirst = true; } output.append(type); } output.append("> "); } } private void writeMethodBody(FactoryMethod factoryMethod) { indent(); output.append("return ").append(factoryMethod.getMatcherClass()); output.append('.'); // lets write the generic types if (!factoryMethod.getGenericTypeParameters().isEmpty()) { output.append('<'); boolean seenFirst = false; for (String type : factoryMethod.getGenericTypeParameters()) { if (seenFirst) { output.append(","); } else { seenFirst = true; } // lets only print the first word of the type // so if its 'T extends Cheese' we just print T //output.append(type); StringTokenizer iter = new StringTokenizer(type); iter.hasMoreElements(); output.append(iter.nextToken()); } output.append(">"); } output.append(factoryMethod.getName()); output.append('('); boolean seenFirst = false; for (FactoryMethod.Parameter parameter : factoryMethod.getParameters()) { if (seenFirst) { output.append(", "); } else { seenFirst = true; } output.append(parameter.getName()); } output.append(')'); output.append(';').append(newLine); } private void writeExceptions(FactoryMethod factoryMethod) { boolean seenFirst = false; for (String exception : factoryMethod.getExceptions()) { if (seenFirst) { output.append(", "); } else { output.append(" throws "); seenFirst = true; } output.append(exception); } } private void writeParameters(FactoryMethod factoryMethod) { output.append('('); boolean seenFirst = false; for (FactoryMethod.Parameter parameter : factoryMethod.getParameters()) { if (seenFirst) { output.append(", "); } else { seenFirst = true; } output.append(parameter.getType()).append(' ').append(parameter.getName()); } output.append(')'); } private void writeJavaDoc(FactoryMethod factoryMethod) { if (factoryMethod.getJavaDoc() != null) { String[] lines = factoryMethod.getJavaDoc().split("\n"); if (lines.length > 0) { indent(); output.append("/**").append(newLine); for (String line : lines) { indent(); output.append(" * ").append(line).append(newLine); } indent(); output.append(" */").append(newLine); } } } private void indent() { for (int i = 0; i < indentation; i++) { output.append(indentationString); } } } libhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/QDox.java0000644000175000017500000000163111033250104030765 0ustar moellermoellerpackage org.hamcrest.generator; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.JavaClass; import java.io.File; import java.io.Reader; /** * Wraps QDox library. This is because to ease distribution, QDox is bundled into * hamcrest-generator.jar and has its package renamed to ensure there is no conflict * (using Jar Jar Links). This wrapper class removes all traces of QDox from Hamcrest's * public API, so there aren't any compatibility problems. * * @author Joe Walnes */ public class QDox { private final JavaDocBuilder javaDocBuilder = new JavaDocBuilder(); public void addSourceTree(File sourceDir) { javaDocBuilder.addSourceTree(sourceDir); } public void addSource(Reader reader) { javaDocBuilder.addSource(reader); } JavaClass getClassByName(String className) { return javaDocBuilder.getClassByName(className); } } libhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/QDoxFactoryReader.java0000644000175000017500000001012411111332771033445 0ustar moellermoellerpackage org.hamcrest.generator; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaMethod; import com.thoughtworks.qdox.model.JavaParameter; import com.thoughtworks.qdox.model.Type; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; /** * Wraps an existing sequence of FactoryMethods, and attempts to pull in * parameter names and JavaDoc (which aren't available using reflection) using * QDox. * * @see QDox * @author Joe Walnes */ public class QDoxFactoryReader implements Iterable { private final Iterable wrapped; private final JavaClass classSource; private static final Pattern GENERIC_REGEX = Pattern.compile("<.*>"); private static final Pattern VARARGS_REGEX = Pattern.compile("...", Pattern.LITERAL); public QDoxFactoryReader(Iterable wrapped, QDox qdox, String className) { this.wrapped = wrapped; this.classSource = qdox.getClassByName(className); } public Iterator iterator() { final Iterator iterator = wrapped.iterator(); return new Iterator() { public boolean hasNext() { return iterator.hasNext(); } public FactoryMethod next() { return enhance(iterator.next()); } public void remove() { iterator.remove(); } }; } private FactoryMethod enhance(FactoryMethod factoryMethod) { JavaMethod methodSource = findMethodInSource(factoryMethod); if (methodSource != null) { factoryMethod.setJavaDoc(createJavaDocComment(methodSource)); JavaParameter[] parametersFromSource = methodSource.getParameters(); List parametersFromReflection = factoryMethod.getParameters(); if (parametersFromReflection.size() == parametersFromSource.length) { for (int i = 0; i < parametersFromSource.length; i++) { parametersFromReflection.get(i).setName( parametersFromSource[i].getName()); } } } return factoryMethod; } /** * Attempts to locate the source code for a specific method, by cross-referencing * the signature returned by reflection with the list of methods parsed by QDox. */ private JavaMethod findMethodInSource(FactoryMethod factoryMethod) { // Note, this doesn't always work - it struggles with some kinds of generics. // This seems to cover most cases though. List params = factoryMethod.getParameters(); Type[] types = new Type[params.size()]; for (int i = 0; i < types.length; i++) { // QDox ignores varargs and generics, so we strip them out to help QDox. String type = params.get(i).getType(); type = GENERIC_REGEX.matcher(type).replaceAll(""); type = VARARGS_REGEX.matcher(type).replaceAll(""); types[i] = new Type(type); } JavaMethod[] methods = classSource.getMethodsBySignature(factoryMethod.getName(), types, false); return methods.length == 1 ? methods[0] : null; } /** * Reconstructs the JavaDoc as a string for a particular method. */ private String createJavaDocComment(JavaMethod methodSource) { String comment = methodSource.getComment(); DocletTag[] tags = methodSource.getTags(); if ((comment == null || comment.trim().length() == 0) && tags.length == 0) { return null; } StringBuilder result = new StringBuilder(); result.append(comment); result.append("\n\n"); for (DocletTag tag : tags) { result.append('@').append(tag.getName()) .append(' ').append(tag.getValue()) .append('\n'); } return result.toString(); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/QuickReferenceWriter.javalibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/QuickReferenceWriter.ja0000644000175000017500000000355311033250104033660 0ustar moellermoellerpackage org.hamcrest.generator; import java.io.IOException; import java.io.PrintStream; /** * Dumps a quick list of factory methods. Designed to be read by users, as a cheatsheet. * * @author Joe Walnes */ public class QuickReferenceWriter implements FactoryWriter { private final PrintStream out; private int columnPosition = 14; public QuickReferenceWriter(PrintStream out) { this.out = out; } public QuickReferenceWriter() { this(System.out); } public void setColumnPosition(int columnPosition) { this.columnPosition = columnPosition; } public void writeHeader() throws IOException { } public void writeMethod(String generatedMethodName, FactoryMethod factoryMethod) throws IOException { String actsOn = removePackageNames(factoryMethod.getGenerifiedType()); for (int i = actsOn.length(); i < columnPosition; i++) { out.append(' '); } out.append('[').append(actsOn).append("] "); out.append(generatedMethodName); out.append('('); boolean seenFirst = false; for (FactoryMethod.Parameter parameter : factoryMethod.getParameters()) { if (seenFirst) { out.append(", "); } else { seenFirst = true; } out.append(removePackageNames(parameter.getType())); out.append(' '); out.append(parameter.getName()); } out.append(')'); out.println(); } private String removePackageNames(String in) { // Simplify fully qualified names (allowing for trailing '...'). return in == null ? "" : in.replaceAll("[^<>]*\\.([^\\.])", "$1"); } public void writeFooter() throws IOException { } public void close() throws IOException { } public void flush() throws IOException { } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/ReflectiveFactoryReader.javalibhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/ReflectiveFactoryReader0000644000175000017500000001416411111331567033754 0ustar moellermoellerpackage org.hamcrest.generator; import java.lang.reflect.Method; import static java.lang.reflect.Modifier.isPublic; import static java.lang.reflect.Modifier.isStatic; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.util.Iterator; /** * Reads a list of Hamcrest factory methods from a class, using standard Java reflection. *

Usage

*
 * for (FactoryMethod method : new ReflectiveFactoryReader(MyMatchers.class)) {
 *   ...
 * }
 * 
*

All methods matching signature '@Factory public static Matcher blah(blah)' will be * treated as factory methods. To change this behavior, override {@link #isFactoryMethod(Method)}. *

Caveat: Reflection is hassle-free, but unfortunately cannot expose method parameter names or JavaDoc * comments, making the sugar slightly more obscure. * * @author Joe Walnes * @see SugarGenerator * @see FactoryMethod */ public class ReflectiveFactoryReader implements Iterable { private final Class cls; private final ClassLoader classLoader; public ReflectiveFactoryReader(Class cls) { this.cls = cls; this.classLoader = cls.getClassLoader(); } public Iterator iterator() { return new Iterator() { private int currentMethod = -1; private Method[] allMethods = cls.getMethods(); public boolean hasNext() { while (true) { currentMethod++; if (currentMethod >= allMethods.length) { return false; } else if (isFactoryMethod(allMethods[currentMethod])) { return true; } // else carry on looping and try the next one. } } public FactoryMethod next() { if (currentMethod >= 0 && currentMethod < allMethods.length) { return buildFactoryMethod(allMethods[currentMethod]); } else { throw new IllegalStateException("next() called without hasNext() check."); } } public void remove() { throw new UnsupportedOperationException(); } }; } /** * Determine whether a particular method is classified as a matcher factory method. *

*

The rules for determining this are: * 1. The method must be public static. * 2. It must have a return type of org.hamcrest.Matcher (or something that extends this). * 3. It must be marked with the org.hamcrest.Factory annotation. *

*

To use another set of rules, override this method. */ @SuppressWarnings({"unchecked"}) protected boolean isFactoryMethod(Method javaMethod) { // We dynamically load these classes, to avoid a compile time // dependency on org.hamcrest.{Factory,Matcher}. This gets around // a circular bootstrap issue (because generator is required to // compile core). Class factoryCls; Class matcherCls; try { factoryCls = classLoader.loadClass("org.hamcrest.Factory"); matcherCls = classLoader.loadClass("org.hamcrest.Matcher"); } catch (ClassNotFoundException e) { throw new RuntimeException("Cannot load hamcrest core", e); } return isStatic(javaMethod.getModifiers()) && isPublic(javaMethod.getModifiers()) && javaMethod.getAnnotation(factoryCls) != null && matcherCls.isAssignableFrom(javaMethod.getReturnType()); } private FactoryMethod buildFactoryMethod(Method javaMethod) { FactoryMethod result = new FactoryMethod( javaMethod.getDeclaringClass().getName(), javaMethod.getName(), javaMethod.getReturnType().getName()); for (TypeVariable typeVariable : javaMethod.getTypeParameters()) { boolean hasBound = false; StringBuilder s = new StringBuilder(typeVariable.getName()); for (Type bound : typeVariable.getBounds()) { if (bound != Object.class) { if (hasBound) { s.append(" & "); } else { s.append(" extends "); hasBound = true; } s.append(typeToString(bound)); } } result.addGenericTypeParameter(s.toString()); } Type returnType = javaMethod.getGenericReturnType(); if (returnType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) returnType; Type generifiedType = parameterizedType.getActualTypeArguments()[0]; result.setGenerifiedType(typeToString(generifiedType)); } int paramNumber = 0; for (Type paramType : javaMethod.getGenericParameterTypes()) { String type = typeToString(paramType); // Special case for var args methods.... String[] -> String... if (javaMethod.isVarArgs() && paramNumber == javaMethod.getParameterTypes().length - 1) { type = type.replaceFirst("\\[\\]$", "..."); } result.addParameter(type, "param" + (++paramNumber)); } for (Class exception : javaMethod.getExceptionTypes()) { result.addException(typeToString(exception)); } return result; } /* * Get String representation of Type (e.g. java.lang.String or Map<Stuff,? extends Cheese>). *

* Annoyingly this method wouldn't be needed if java.lang.reflect.Type.toString() behaved consistently * across implementations. Rock on Liskov. */ private static String typeToString(Type type) { return type instanceof Class ? classToString((Class) type): type.toString(); } private static String classToString(Class cls) { return cls.isArray() ? cls.getComponentType().getName() + "[]" : cls.getName(); } } libhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/SugarConfiguration.java0000644000175000017500000000035211033250104033722 0ustar moellermoellerpackage org.hamcrest.generator; public interface SugarConfiguration { void addWriter(FactoryWriter factoryWriter); void addFactoryMethod(FactoryMethod method); void addFactoryMethods(Iterable methods); } libhamcrest-java-1.2/hamcrest-generator/src/main/java/org/hamcrest/generator/SugarGenerator.java0000644000175000017500000000724511033250104033051 0ustar moellermoellerpackage org.hamcrest.generator; import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * API for syntactic sugar and wrapper code generation framework. *

Generally, Matcher factory methods are defined all over the place, which makes it * really hard to remember which methods need to be imported and doesn't allow you * to easily browse a list of all of them. *

This generates one uber matcher factory that delegates to all the respective classes. *

Additionally, this allows the uber-classes to do things like wrap matchers in adapters * (e.g. to make them EasyMock friendly) or even generate wrappers in other languages * (such as JRuby or Jython). *

You need to add at least one writer and at least one factory method for this to be * any help. *

Usage

*
 * SugarGenerator sugarGenerator = new SugarGenerator();
 * try {
 *   // Write out sugar as standard Hamcrest factories.
 *   sugarGenerator.addWriter(
 *     new HamcrestFactoryWriter("com.some.package", "MyMatcherClass", new FileWriter(...)));
 *   // Also write out sugar as EasyMock compatible factories.
 *   sugarGenerator.addWriter(
 *     new EasyMockFactoryWriter("com.some.package", "MyEasyMatcherClass", new FileWriter(...)));
 *   // Add a load of Matcher factories to the generated sugar. The factory methods
 *   // are read via reflection.
 *   sugarGenerator.addFactoryMethods(new ReflectiveFactoryReader(IsIn.class));
 *   sugarGenerator.addFactoryMethods(new ReflectiveFactoryReader(IsSame.class));
 *   sugarGenerator.addFactoryMethods(new ReflectiveFactoryReader(IsNot.class));
 *   // Generate everything!
 *   sugarGenerator.generate();
 * } finally {
 *   // Clean up... close all streams.
 *   sugarGenerator.close();
 * }
* * @author Joe Walnes * @see FactoryWriter * @see HamcrestFactoryWriter * @see ReflectiveFactoryReader */ public class SugarGenerator implements Closeable, SugarConfiguration { private final List factoryWriters = new ArrayList(); private final List factoryMethods = new ArrayList(); /** * Add a writer of factories. */ public void addWriter(FactoryWriter factoryWriter) { factoryWriters.add(factoryWriter); } /** * Add a FactoryMethod that will be generated in the sugar. * * @see ReflectiveFactoryReader * @see FactoryMethod */ public void addFactoryMethod(FactoryMethod method) { factoryMethods.add(method); } /** * Convient way to add multiple FactoryMethods. * * @see #addFactoryMethod(FactoryMethod) */ public void addFactoryMethods(Iterable methods) { for (FactoryMethod method : methods) { addFactoryMethod(method); } } /** * Generate all the factory methods using all the writers. * * This should always happen AFTER adding factory methods and writers. */ public void generate() throws IOException { for (FactoryWriter factoryWriter : factoryWriters) { factoryWriter.writeHeader(); for (FactoryMethod factoryMethod : factoryMethods) { factoryWriter.writeMethod(factoryMethod.getName(), factoryMethod); } factoryWriter.writeFooter(); factoryWriter.flush(); } } /** * Close all underlying streams. Calling this means you don't have to explicitly * keep track of all the File streams and close them. */ public void close() throws IOException { for (FactoryWriter factoryWriter : factoryWriters) { factoryWriter.close(); } } } libhamcrest-java-1.2/hamcrest-integration/0000755000175000017500000000000010632277413020604 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-integration/src/0000755000175000017500000000000010632277413021373 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-integration/src/main/0000755000175000017500000000000010632277413022317 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-integration/src/main/java/0000755000175000017500000000000010632277413023240 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-integration/src/main/java/org/0000755000175000017500000000000010632277416024032 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/0000755000175000017500000000000011675175275025650 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/integration/0000755000175000017500000000000011675175275030173 5ustar moellermoeller././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.javalibhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.ja0000644000175000017500000000232011111332131033545 0ustar moellermoellerpackage org.hamcrest.integration; import org.easymock.IArgumentMatcher; import org.easymock.EasyMock; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; /** * An adapter allowing a Hamcrest {@link org.hamcrest.Matcher} * to act as an EasyMock {@link org.easymock.IArgumentMatcher}. * * @author Joe Walnes */ public class EasyMock2Adapter implements IArgumentMatcher { /** * Convenience factory method that will adapt a * Hamcrest {@link org.hamcrest.Matcher} to act as an * EasyMock {@link org.easymock.IArgumentMatcher} and * report it to EasyMock so it can be kept track of. */ public static IArgumentMatcher adapt(Matcher matcher) { EasyMock2Adapter easyMock2Matcher = new EasyMock2Adapter(matcher); EasyMock.reportMatcher(easyMock2Matcher); return easyMock2Matcher; } private final Matcher hamcrestMatcher; public EasyMock2Adapter(Matcher matcher) { this.hamcrestMatcher = matcher; } public boolean matches(Object argument) { return hamcrestMatcher.matches(argument); } public void appendTo(StringBuffer buffer) { hamcrestMatcher.describeTo(new StringDescription(buffer)); } } libhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/integration/JMock1Adapter.java0000644000175000017500000000210511033250101033363 0ustar moellermoellerpackage org.hamcrest.integration; import org.jmock.core.Constraint; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; /** * An adapter allowing a Hamcrest {@link org.hamcrest.Matcher} * to act as an jMock1 {@link org.jmock.core.Constraint}. * Note, this is not necessary for jMock2 as it supports Hamcrest * out of the box. * * @author Joe Walnes */ public class JMock1Adapter implements Constraint { /** * Convenience factory method that will adapt a * Hamcrest {@link org.hamcrest.Matcher} to act as an * jMock {@link org.jmock.core.Constraint}. */ public static Constraint adapt(Matcher matcher) { return new JMock1Adapter(matcher); } private final Matcher hamcrestMatcher; public JMock1Adapter(Matcher matcher) { this.hamcrestMatcher = matcher; } public boolean eval(Object o) { return hamcrestMatcher.matches(o); } public StringBuffer describeTo(StringBuffer buffer) { hamcrestMatcher.describeTo(new StringDescription(buffer)); return buffer; } } libhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/EasyMock2Matchers.java0000644000175000017500000000047011033250102031743 0ustar moellermoellerpackage org.hamcrest; import org.hamcrest.integration.EasyMock2Adapter; import org.hamcrest.core.IsEqual; /** * * @author Joe Walnes */ public class EasyMock2Matchers { public static String equalTo(String string) { EasyMock2Adapter.adapt(IsEqual.equalTo(string)); return null; } } libhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/JMock1Matchers.java0000644000175000017500000000044511033250102031234 0ustar moellermoellerpackage org.hamcrest; import org.hamcrest.integration.JMock1Adapter; import org.hamcrest.core.IsEqual; import org.jmock.core.Constraint; public class JMock1Matchers { public static Constraint equalTo(String string) { return JMock1Adapter.adapt(IsEqual.equalTo(string)); } } libhamcrest-java-1.2/hamcrest-integration/src/main/java/org/hamcrest/JavaLangMatcherAssert.java0000644000175000017500000000062211044676440032652 0ustar moellermoellerpackage org.hamcrest; /** * Integration method for use with Java's assert keyword. * Example: *
 * assert that("Foo", startsWith("f"));
 * 
* * @author Neil Dunn */ public class JavaLangMatcherAssert { private JavaLangMatcherAssert() {}; public static boolean that(T argument, Matcher matcher) { return matcher.matches(argument); } } libhamcrest-java-1.2/hamcrest-library/0000755000175000017500000000000010632277506017730 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/0000755000175000017500000000000010632277506020517 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/0000755000175000017500000000000010632277506021443 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/0000755000175000017500000000000010632277506022364 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/0000755000175000017500000000000010632277506023153 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/0000755000175000017500000000000011072752127024755 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/beans/0000755000175000017500000000000011675175275026061 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/beans/HasProperty.java0000644000175000017500000000276311121052033031160 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.beans; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; /** * Matcher that checks that an object has a JavaBean property * with the specified name. If an error occurs while introspecting * the object then this is treated as a matcher failure. * * @author Iain McGinniss * @author Nat Pryce * @author Steve Freeman */ public class HasProperty extends TypeSafeMatcher { private final String propertyName; public HasProperty(String propertyName) { this.propertyName = propertyName; } @Override public boolean matchesSafely(T obj) { // TODO(ngd): this is not type safe. try { return PropertyUtil.getPropertyDescriptor(propertyName, obj) != null; } catch (IllegalArgumentException e) { // introspection failure is treated as a matcher failure return false; } } @Override public void describeMismatchSafely(T item, Description mismatchDescription) { mismatchDescription.appendText("no ").appendValue(propertyName).appendText(" in ").appendValue(item); }; public void describeTo(Description description) { description.appendText("hasProperty(").appendValue(propertyName).appendText(")"); } @Factory public static Matcher hasProperty(String propertyName) { return new HasProperty(propertyName); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java0000644000175000017500000001127011152022077033013 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.beans; import static org.hamcrest.beans.PropertyUtil.NO_ARGUMENTS; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; /** * Matcher that asserts that a JavaBean property on an argument passed to the * mock object meets the provided matcher. This is useful for when objects * are created within code under test and passed to a mock object, and you wish * to assert that the created object has certain properties. *

*

Example Usage

* Consider the situation where we have a class representing a person, which * follows the basic JavaBean convention of having get() and possibly set() * methods for it's properties: * public class Person { * private String name; *

* public Person(String person) { * this.person = person; * } *

* public String getName() { * return name; * } * } * And that these person * objects are generated within a piece of code under test (a class named * PersonGenerator). This object is sent to one of our mock objects which * overrides the PersonGenerationListener interface: * public interface PersonGenerationListener { * public void personGenerated(Person person); * } * * In order to check that the code under test generates a person with name * "Iain" we would do the following: *

* * Mock personGenListenerMock = mock(PersonGenerationListener.class); * personGenListenerMock.expects(once()).method("personGenerated").with(and(isA(Person.class), hasProperty("Name", eq("Iain"))); * PersonGenerationListener listener = (PersonGenerationListener)personGenListenerMock.proxy(); * *

* If an exception is thrown by the getter method for a property, the property * does not exist, is not readable, or a reflection related exception is thrown * when trying to invoke it then this is treated as an evaluation failure and * the matches method will return false. *

* This matcher class will also work with JavaBean objects that have explicit * bean descriptions via an associated BeanInfo description class. See the * JavaBeans specification for more information: *

* http://java.sun.com/products/javabeans/docs/index.html * * @author Iain McGinniss * @author Nat Pryce * @author Steve Freeman */ public class HasPropertyWithValue extends TypeSafeDiagnosingMatcher { private final String propertyName; private final Matcher valueMatcher; public HasPropertyWithValue(String propertyName, Matcher valueMatcher) { this.propertyName = propertyName; this.valueMatcher = valueMatcher; } @Override public boolean matchesSafely(T bean, Description mismatchDescription) { try { Method readMethod = findReadMethod(bean, mismatchDescription); if (readMethod == null) { return false; } Object propertyValue = readMethod.invoke(bean, NO_ARGUMENTS); boolean valueMatches = valueMatcher.matches(propertyValue); if (!valueMatches) { mismatchDescription.appendText("property \"" + propertyName + "\" "); valueMatcher.describeMismatch(propertyValue, mismatchDescription); } return valueMatches; } catch (IllegalArgumentException e) { return false; } catch (IllegalAccessException e) { return false; } catch (InvocationTargetException e) { return false; } } private Method findReadMethod(Object argument, Description mismatchDescription) throws IllegalArgumentException { PropertyDescriptor property = PropertyUtil.getPropertyDescriptor(propertyName, argument); if (null == property) { mismatchDescription.appendText("No property \"" + propertyName + "\""); return null; } Method readMethod = property.getReadMethod(); if (null == readMethod) { mismatchDescription.appendText("property \"" + propertyName + "\" is not readable"); } return readMethod; } public void describeTo(Description description) { description.appendText("hasProperty("); description.appendValue(propertyName); description.appendText(", "); description.appendDescriptionOf(valueMatcher); description.appendText(")"); } @Factory public static Matcher hasProperty(String propertyName, Matcher value) { return new HasPropertyWithValue(propertyName, value); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/beans/PropertyUtil.java0000644000175000017500000000356311113513352031370 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.beans; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; /** * Utility class for accessing properties on JavaBean objects. *

* See http://java.sun.com/products/javabeans/docs/index.html for * more information on JavaBeans. * * @author Iain McGinniss * @author Steve Freeman * @since 1.1.0 */ public class PropertyUtil { /** * Returns the description of the property with the provided * name on the provided object's interface. * * @return the descriptor of the property, or null if the property does not exist. * @throws IllegalArgumentException if there's a introspection failure */ public static PropertyDescriptor getPropertyDescriptor(String propertyName, Object fromObj) throws IllegalArgumentException { for (PropertyDescriptor property : propertyDescriptorsFor(fromObj, null)) { if (property.getName().equals(propertyName)) { return property; } } return null; } /** * Returns all the property descriptors for the class associated with the given object * * @param fromObj Use the class of this object * @param stopClass TODO * @return Property descriptors * @throws IllegalArgumentException if there's a introspection failure */ public static PropertyDescriptor[] propertyDescriptorsFor(Object fromObj, Class stopClass) throws IllegalArgumentException { try { return Introspector.getBeanInfo(fromObj.getClass(), stopClass).getPropertyDescriptors(); } catch (IntrospectionException e) { throw new IllegalArgumentException("Could not get property descriptors for " + fromObj.getClass(), e); } } public static final Object[] NO_ARGUMENTS = new Object[0]; } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/beans/SamePropertyValuesAs.java0000644000175000017500000001102411130362733032777 0ustar moellermoellerpackage org.hamcrest.beans; import static org.hamcrest.beans.PropertyUtil.NO_ARGUMENTS; import static org.hamcrest.beans.PropertyUtil.propertyDescriptorsFor; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.hamcrest.Description; import org.hamcrest.DiagnosingMatcher; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.core.IsEqual; public class SamePropertyValuesAs extends TypeSafeDiagnosingMatcher { private final T expectedBean; private final Set propertyNames; private final List propertyMatchers; public SamePropertyValuesAs(T expectedBean) { PropertyDescriptor[] descriptors = propertyDescriptorsFor(expectedBean, Object.class); this.expectedBean = expectedBean; this.propertyNames = propertyNamesFrom(descriptors); this.propertyMatchers = propertyMatchersFor(expectedBean, descriptors); } @Override public boolean matchesSafely(T item, Description mismatchDescription) { return isCompatibleType(item, mismatchDescription) && hasNoExtraProperties(item, mismatchDescription) && hasMatchingValues(item, mismatchDescription); } private boolean isCompatibleType(T item, Description mismatchDescription) { if (! expectedBean.getClass().isAssignableFrom(item.getClass())) { mismatchDescription.appendText("is incompatible type: " + item.getClass().getSimpleName()); return false; } return true; } private boolean hasNoExtraProperties(T item, Description mismatchDescription) { Set actualPropertyNames = propertyNamesFrom(propertyDescriptorsFor(item, Object.class)); actualPropertyNames.removeAll(propertyNames); if (! actualPropertyNames.isEmpty()) { mismatchDescription.appendText("has extra properties called " + actualPropertyNames); return false; } return true; } private boolean hasMatchingValues(T item, Description mismatchDescription) { for (PropertyMatcher propertyMatcher : propertyMatchers) { if (! propertyMatcher.matches(item)) { propertyMatcher.describeMismatch(item, mismatchDescription); return false; } } return true; } public void describeTo(Description description) { description.appendText("same property values as " + expectedBean.getClass().getSimpleName()) .appendList(" [", ", ", "]", propertyMatchers); } private static List propertyMatchersFor(T bean, PropertyDescriptor[] descriptors) { List result = new ArrayList(descriptors.length); for (PropertyDescriptor propertyDescriptor : descriptors) { result.add(new PropertyMatcher(propertyDescriptor, bean)); } return result; } private static Set propertyNamesFrom(PropertyDescriptor[] descriptors) { HashSet result = new HashSet(); for (PropertyDescriptor propertyDescriptor : descriptors) { result.add(propertyDescriptor.getDisplayName()); } return result; } public static class PropertyMatcher extends DiagnosingMatcher { private final Method readMethod; private final Matcher matcher; private final String propertyName; public PropertyMatcher(PropertyDescriptor descriptor, Object expectedObject) { this.propertyName = descriptor.getDisplayName(); this.readMethod = descriptor.getReadMethod(); this.matcher = new IsEqual(readProperty(readMethod, expectedObject)); } @Override public boolean matches(Object actual, Description mismatchDescription) { Object actualValue = readProperty(readMethod, actual); if (! matcher.matches(actualValue)) { mismatchDescription.appendText(propertyName + " "); matcher.describeMismatch(actualValue, mismatchDescription); return false; } return true; } public void describeTo(Description description) { description.appendText(propertyName + ": ").appendDescriptionOf(matcher); } } private static Object readProperty(Method method, Object target) { try { return method.invoke(target, NO_ARGUMENTS); } catch (Exception e) { throw new IllegalArgumentException("Could not invoke " + method + " on " + target, e); } } @Factory public static Matcher samePropertyValuesAs(T expectedBean) { return new SamePropertyValuesAs(expectedBean); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/beans/package.html0000644000175000017500000000015110632277507030330 0ustar moellermoeller

Matchers of Java Bean properties and their values.

libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/0000755000175000017500000000000011675175275027124 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsArray.java0000644000175000017500000000477511175134450031337 0ustar moellermoellerpackage org.hamcrest.collection; import java.util.Arrays; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; /** * Matcher for array whose elements satisfy a sequence of matchers. * The array size must equal the number of element matchers. */ public class IsArray extends TypeSafeMatcher { private final Matcher[] elementMatchers; public IsArray(Matcher[] elementMatchers) { this.elementMatchers = elementMatchers.clone(); } @Override public boolean matchesSafely(T[] array) { if (array.length != elementMatchers.length) return false; for (int i = 0; i < array.length; i++) { if (!elementMatchers[i].matches(array[i])) return false; } return true; } @Override public void describeMismatchSafely(T[] actual, Description mismatchDescription) { if (actual.length != elementMatchers.length) { mismatchDescription.appendText("array length was " + actual.length); return; } for (int i = 0; i < actual.length; i++) { if (!elementMatchers[i].matches(actual[i])) { mismatchDescription.appendText("element " + i + " was ").appendValue(actual[i]); return; } } } public void describeTo(Description description) { description.appendList(descriptionStart(), descriptionSeparator(), descriptionEnd(), Arrays.asList(elementMatchers)); } /** * Returns the string that starts the description. * * Can be overridden in subclasses to customise how the matcher is * described. */ protected String descriptionStart() { return "["; } /** * Returns the string that separates the elements in the description. * * Can be overridden in subclasses to customise how the matcher is * described. */ protected String descriptionSeparator() { return ", "; } /** * Returns the string that ends the description. * * Can be overridden in subclasses to customise how the matcher is * described. */ protected String descriptionEnd() { return "]"; } /** * Evaluates to true only if each matcher[i] is satisfied by array[i]. */ @Factory public static IsArray array(Matcher... elementMatchers) { return new IsArray(elementMatchers); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContaining.java0000644000175000017500000000341511120445434033334 0ustar moellermoellerpackage org.hamcrest.collection; import java.util.Arrays; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Factory; import org.hamcrest.TypeSafeMatcher; import static org.hamcrest.core.IsEqual.equalTo; /** * Matches if an array contains an item satisfying a nested matcher. */ public class IsArrayContaining extends TypeSafeMatcher { private final Matcher elementMatcher; public IsArrayContaining(Matcher elementMatcher) { this.elementMatcher = elementMatcher; } @Override public boolean matchesSafely(T[] array) { for (T item : array) { if (elementMatcher.matches(item)) { return true; } } return false; } @Override public void describeMismatchSafely(T[] item, Description mismatchDescription) { super.describeMismatch(Arrays.asList(item), mismatchDescription); }; public void describeTo(Description description) { description .appendText("an array containing ") .appendDescriptionOf(elementMatcher); } /** * Evaluates to true if any item in an array satisfies the given matcher. */ @Factory public static Matcher hasItemInArray(Matcher elementMatcher) { return new IsArrayContaining(elementMatcher); } /** * This is a shortcut to the frequently used hasItemInArray(equalTo(x)). * * For example, assertThat(hasItemInArray(equal_to(x))) * vs. assertThat(hasItemInArray(x)) */ @Factory public static Matcher hasItemInArray(T element) { Matcher matcher = equalTo(element); return IsArrayContaining.hasItemInArray(matcher); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.javalibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOr0000644000175000017500000000353311161140205033646 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.core.IsEqual.equalTo; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; public class IsArrayContainingInAnyOrder extends TypeSafeMatcher { private final IsIterableContainingInAnyOrder iterableMatcher; private final Collection> matchers; public IsArrayContainingInAnyOrder(Collection> matchers) { this.iterableMatcher = new IsIterableContainingInAnyOrder(matchers); this.matchers = matchers; } @Override public boolean matchesSafely(E[] item) { return iterableMatcher.matches(Arrays.asList(item)); } @Override public void describeMismatchSafely(E[] item, Description mismatchDescription) { iterableMatcher.describeMismatch(Arrays.asList(item), mismatchDescription); }; public void describeTo(Description description) { description.appendList("[", ", ", "]", matchers) .appendText(" in any order"); } @Factory public static Matcher arrayContainingInAnyOrder(Matcher... matchers) { return arrayContainingInAnyOrder(Arrays.asList(matchers)); } @Factory public static Matcher arrayContainingInAnyOrder(Collection> matchers) { return new IsArrayContainingInAnyOrder(matchers); } @Factory public static Matcher arrayContainingInAnyOrder(E... items) { List> matchers = new ArrayList>(); for (E item : items) { matchers.add(equalTo(item)); } return new IsArrayContainingInAnyOrder(matchers); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInOrder.javalibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInOrder0000644000175000017500000000334511161147666033714 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.core.IsEqual.equalTo; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; public class IsArrayContainingInOrder extends TypeSafeMatcher { private final Collection> matchers; private final IsIterableContainingInOrder iterableMatcher; public IsArrayContainingInOrder(List> matchers) { this.iterableMatcher = new IsIterableContainingInOrder(matchers); this.matchers = matchers; } @Override public boolean matchesSafely(E[] item) { return iterableMatcher.matches(Arrays.asList(item)); } @Override public void describeMismatchSafely(E[] item, Description mismatchDescription) { iterableMatcher.describeMismatch(Arrays.asList(item), mismatchDescription); }; public void describeTo(Description description) { description.appendList("[", ", ", "]", matchers); } @Factory public static Matcher arrayContaining(E... items) { List> matchers = new ArrayList>(); for (E item : items) { matchers.add(equalTo(item)); } return arrayContaining(matchers); } @Factory public static Matcher arrayContaining(Matcher... matchers) { return arrayContaining(Arrays.asList(matchers)); } @Factory public static Matcher arrayContaining(List> matchers) { return new IsArrayContainingInOrder(matchers); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayWithSize.java0000644000175000017500000000255411123143031033003 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.core.DescribedAs.describedAs; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.Factory; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; /** * Matches if array size satisfies a nested matcher. */ public class IsArrayWithSize extends FeatureMatcher { public IsArrayWithSize(Matcher sizeMatcher) { super(sizeMatcher, "an array with size","array size"); } @Override protected Integer featureValueOf(E[] actual) { return actual.length; }; /** * Does array size satisfy a given matcher? */ @Factory public static Matcher arrayWithSize(Matcher sizeMatcher) { return new IsArrayWithSize(sizeMatcher); } /** * This is a shortcut to the frequently used arrayWithSize(equalTo(x)). * * For example, assertThat(arrayWithSize(equal_to(x))) * vs. assertThat(arrayWithSize(x)) */ @Factory public static Matcher arrayWithSize(int size) { return arrayWithSize(equalTo(size)); } /** * Matches an empty array. */ @Factory public static Matcher emptyArray() { Matcher isEmpty = arrayWithSize(0); return describedAs("an empty array", isEmpty); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsCollectionWithSize.javalibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsCollectionWithSize.jav0000644000175000017500000000242011123141611033651 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.core.IsEqual.equalTo; import java.util.Collection; import org.hamcrest.Factory; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; /** * Matches if collection size satisfies a nested matcher. */ public class IsCollectionWithSize extends FeatureMatcher, Integer> { public IsCollectionWithSize(Matcher sizeMatcher) { super(sizeMatcher, "a collection with size", "collection size"); } @Override protected Integer featureValueOf(Collection actual) { return actual.size(); } /** * Does collection size satisfy a given matcher? */ @Factory public static Matcher> hasSize(Matcher size) { return new IsCollectionWithSize(size); } /** * This is a shortcut to the frequently used hasSize(equalTo(x)). * * For example, assertThat(hasSize(equal_to(x))) * vs. assertThat(hasSize(x)) */ @Factory public static Matcher> hasSize(int size) { Matcher matcher = equalTo(size); return IsCollectionWithSize.hasSize(matcher); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsEmptyCollection.java0000644000175000017500000000145411121016754033357 0ustar moellermoellerpackage org.hamcrest.collection; import java.util.Collection; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; /** * Tests if collection is empty. */ public class IsEmptyCollection extends TypeSafeMatcher> { @Override public boolean matchesSafely(Collection item) { return item.isEmpty(); } @Override public void describeMismatchSafely(Collection item, Description mismatchDescription) { mismatchDescription.appendValue(item); } public void describeTo(Description description) { description.appendText("an empty collection"); } /** * Matches an empty collection. */ @Factory public static Matcher> empty() { return new IsEmptyCollection(); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsEmptyIterable.java0000644000175000017500000000154211121021235032777 0ustar moellermoellerpackage org.hamcrest.collection; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; /** * Tests if collection is empty. */ public class IsEmptyIterable extends TypeSafeMatcher> { @Override public boolean matchesSafely(Iterable iterable) { return !iterable.iterator().hasNext(); } @Override public void describeMismatchSafely(Iterable iter, Description mismatchDescription) { mismatchDescription.appendValueList("[", ",", "]", iter); } public void describeTo(Description description) { description.appendText("an empty iterable"); } /** * Matches an empty iterable. */ @Factory public static Matcher> emptyIterable() { return new IsEmptyIterable(); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsIn.java0000644000175000017500000000207611033250117030607 0ustar moellermoellerpackage org.hamcrest.collection; import java.util.Arrays; import java.util.Collection; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; public class IsIn extends BaseMatcher { private final Collection collection; public IsIn(Collection collection) { this.collection = collection; } public IsIn(T[] elements) { collection = Arrays.asList(elements); } public boolean matches(Object o) { return collection.contains(o); } public void describeTo(Description buffer) { buffer.appendText("one of "); buffer.appendValueList("{", ", ", "}", collection); } @Factory public static Matcher isIn(Collection collection) { return new IsIn(collection); } @Factory public static Matcher isIn(T[] elements) { return new IsIn(elements); } @Factory public static Matcher isOneOf(T... elements) { return isIn(elements); } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrder.javalibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInAn0000644000175000017500000000654211161150351033633 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.core.IsEqual.equalTo; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; public class IsIterableContainingInAnyOrder extends TypeSafeDiagnosingMatcher> { private final Collection> matchers; public IsIterableContainingInAnyOrder(Collection> matchers) { this.matchers = matchers; } @Override protected boolean matchesSafely(Iterable items, Description mismatchDescription) { Matching matching = new Matching(matchers, mismatchDescription); for (T item : items) { if (! matching.matches(item)) { return false; } } return matching.isFinished(items); } public void describeTo(Description description) { description.appendText("iterable over ") .appendList("[", ", ", "]", matchers) .appendText(" in any order"); } private static class Matching { private final Collection> matchers; private final Description mismatchDescription; public Matching(Collection> matchers, Description mismatchDescription) { this.matchers = new ArrayList>(matchers);; this.mismatchDescription = mismatchDescription; } public boolean matches(S item) { return isNotSurplus(item) && isMatched(item); } public boolean isFinished(Iterable items) { if (matchers.isEmpty()) { return true; } mismatchDescription .appendText("No item matches: ").appendList("", ", ", "", matchers) .appendText(" in ").appendValueList("[", ", ", "]", items); return false; } private boolean isNotSurplus(S item) { if (matchers.isEmpty()) { mismatchDescription.appendText("Not matched: ").appendValue(item); return false; } return true; } private boolean isMatched(S item) { for (Matcher matcher : matchers) { if (matcher.matches(item)) { matchers.remove(matcher); return true; } } mismatchDescription.appendText("Not matched: ").appendValue(item); return false; } } @Factory public static Matcher> containsInAnyOrder(final Matcher item) { return containsInAnyOrder(new ArrayList>() {{ add(item); }}); } @Factory public static Matcher> containsInAnyOrder(Matcher... matchers) { return containsInAnyOrder(Arrays.asList(matchers)); } @Factory public static Matcher> containsInAnyOrder(T... items) { List> matchers = new ArrayList>(); for (T item : items) { matchers.add(equalTo(item)); } return new IsIterableContainingInAnyOrder(matchers); } @Factory public static Matcher> containsInAnyOrder(Collection> matchers) { return new IsIterableContainingInAnyOrder(matchers); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.javalibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInOr0000644000175000017500000000662711162653572033677 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.core.IsEqual.equalTo; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; public class IsIterableContainingInOrder extends TypeSafeDiagnosingMatcher> { private final List> matchers; public IsIterableContainingInOrder(List> matchers) { this.matchers = matchers; } @Override protected boolean matchesSafely(Iterable iterable, Description mismatchDescription) { MatchSeries matchSeries = new MatchSeries(matchers, mismatchDescription); for (E item : iterable) { if (! matchSeries.matches(item)) { return false; } } return matchSeries.isFinished(); } public void describeTo(Description description) { description.appendText("iterable over ").appendList("[", ", ", "]", matchers); } private static class MatchSeries { public final List> matchers; private final Description mismatchDescription; public int nextMatchIx = 0; public MatchSeries(List> matchers, Description mismatchDescription) { this.mismatchDescription = mismatchDescription; if (matchers.isEmpty()) { throw new IllegalArgumentException("Should specify at least one expected element"); } this.matchers = matchers; } public boolean matches(F item) { return isNotSurplus(item) && isMatched(item); } public boolean isFinished() { if (nextMatchIx < matchers.size()) { mismatchDescription.appendText("No item matched: ").appendDescriptionOf(matchers.get(nextMatchIx)); return false; } return true; } private boolean isMatched(F item) { Matcher matcher = matchers.get(nextMatchIx); if (!matcher.matches(item)) { describeMismatch(matcher, item); return false; } nextMatchIx++; return true; } private boolean isNotSurplus(F item) { if (matchers.size() <= nextMatchIx) { mismatchDescription.appendText("Not matched: ").appendValue(item); return false; } return true; } private void describeMismatch(Matcher matcher, F item) { mismatchDescription.appendText("item " + nextMatchIx + ": "); matcher.describeMismatch(item, mismatchDescription); } } @Factory public static Matcher> contains(E... items) { List> matchers = new ArrayList>(); for (E item : items) { matchers.add(equalTo(item)); } return contains(matchers); } @Factory public static Matcher> contains(final Matcher item) { return contains(new ArrayList>() {{ add(item); }}); } @Factory public static Matcher> contains(Matcher... items) { return contains(Arrays.asList(items)); } @Factory public static Matcher> contains(List> contents) { return new IsIterableContainingInOrder(contents); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableWithSize.java0000644000175000017500000000174111123142221033451 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.core.IsEqual.equalTo; import java.util.Iterator; import org.hamcrest.Factory; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; public class IsIterableWithSize extends FeatureMatcher, Integer> { public IsIterableWithSize(Matcher sizeMatcher) { super(sizeMatcher, "an iterable with size", "iterable size"); } @Override protected Integer featureValueOf(Iterable actual) { int size = 0; for (Iterator iterator = actual.iterator(); iterator.hasNext(); iterator.next()) { size++; } return size; } @Factory public static Matcher> iterableWithSize(Matcher sizeMatcher) { return new IsIterableWithSize(sizeMatcher); } @Factory public static Matcher> iterableWithSize(int size) { return iterableWithSize(equalTo(size)); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsMapContaining.java0000644000175000017500000000355311123145775033006 0ustar moellermoellerpackage org.hamcrest.collection; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import static org.hamcrest.core.IsEqual.equalTo; import java.util.Map; import java.util.Map.Entry; public class IsMapContaining extends TypeSafeMatcher> { private final Matcher keyMatcher; private final Matcher valueMatcher; public IsMapContaining(Matcher keyMatcher, Matcher valueMatcher) { this.keyMatcher = keyMatcher; this.valueMatcher = valueMatcher; } @Override public boolean matchesSafely(Map map) { for (Entry entry : map.entrySet()) { if (keyMatcher.matches(entry.getKey()) && valueMatcher.matches(entry.getValue())) { return true; } } return false; } @Override public void describeMismatchSafely(Map map, Description mismatchDescription) { mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet()); } public void describeTo(Description description) { description.appendText("map containing [") .appendDescriptionOf(keyMatcher) .appendText("->") .appendDescriptionOf(valueMatcher) .appendText("]"); } @Factory public static Matcher> hasEntry(Matcher keyMatcher, Matcher valueMatcher) { return new IsMapContaining(keyMatcher, valueMatcher); } @Factory public static Matcher> hasEntry(K key, V value) { return IsMapContaining.hasEntry(equalTo(key), equalTo(value)); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsMapContainingKey.java0000644000175000017500000000272511123146122033442 0ustar moellermoellerpackage org.hamcrest.collection; import java.util.Map; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import static org.hamcrest.core.IsEqual.equalTo; public class IsMapContainingKey extends TypeSafeMatcher> { private final Matcher keyMatcher; public IsMapContainingKey(Matcher keyMatcher) { this.keyMatcher = keyMatcher; } @Override public boolean matchesSafely(Map item) { for (Object key : item.keySet()) { if (keyMatcher.matches(key)) { return true; } } return false; } @Override public void describeMismatchSafely(Map map, Description mismatchDescription) { mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet()); } public void describeTo(Description description) { description.appendText("map with key ") .appendDescriptionOf(keyMatcher); } @Factory public static Matcher> hasKey(K key) { // does not forward to other hasKey method to help compiler cope with type inference return new IsMapContainingKey(equalTo(key)); } @Factory public static Matcher> hasKey(Matcher keyMatcher) { return new IsMapContainingKey(keyMatcher); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsMapContainingValue.javalibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/IsMapContainingValue.jav0000644000175000017500000000261511123146403033625 0ustar moellermoellerpackage org.hamcrest.collection; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import static org.hamcrest.core.IsEqual.equalTo; import java.util.Map; public class IsMapContainingValue extends TypeSafeMatcher>{ private final Matcher valueMatcher; public IsMapContainingValue(Matcher valueMatcher) { this.valueMatcher = valueMatcher; } @Override public boolean matchesSafely(Map item) { for (V value : item.values()) { if (valueMatcher.matches(value)) { return true; } } return false; } @Override public void describeMismatchSafely(Map map, Description mismatchDescription) { mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet()); } public void describeTo(Description description) { description.appendText("map with value ") .appendDescriptionOf(valueMatcher); } @Factory public static Matcher> hasValue(V value) { return IsMapContainingValue.hasValue(equalTo(value)); } @Factory public static Matcher> hasValue(Matcher valueMatcher) { return new IsMapContainingValue(valueMatcher); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/collection/package.html0000644000175000017500000000013210632277507031372 0ustar moellermoeller

Matchers of arrays and collections.

libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/number/0000755000175000017500000000000011675175275026261 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/number/IsCloseTo.java0000644000175000017500000000254411121016053030743 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.number; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Factory; import org.hamcrest.TypeSafeMatcher; /** * Is the value a number equal to a value within some range of * acceptable error? */ public class IsCloseTo extends TypeSafeMatcher { private final double delta; private final double value; public IsCloseTo(double value, double error) { this.delta = error; this.value = value; } @Override public boolean matchesSafely(Double item) { return actualDelta(item) <= 0.0; } @Override public void describeMismatchSafely(Double item, Description mismatchDescription) { mismatchDescription.appendValue(item) .appendText(" differed by ") .appendValue(actualDelta(item)); } public void describeTo(Description description) { description.appendText("a numeric value within ") .appendValue(delta) .appendText(" of ") .appendValue(value); } private double actualDelta(Double item) { return (Math.abs((item - value)) - delta); } @Factory public static Matcher closeTo(double operand, double error) { return new IsCloseTo(operand, error); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/number/OrderingComparison.java0000644000175000017500000000547611175325205032725 0ustar moellermoeller/* Copyright (c) 2000-2009 hamcrest.org */ package org.hamcrest.number; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; public class OrderingComparison> extends TypeSafeMatcher { private static final int LESS_THAN = -1; private static final int GREATER_THAN = 1; private static final int EQUAL = 0; private final T expected; private final int minCompare, maxCompare; private OrderingComparison(T expected, int minCompare, int maxCompare) { this.expected = expected; this.minCompare = minCompare; this.maxCompare = maxCompare; } @Override public boolean matchesSafely(T actual) { int compare = Integer.signum(actual.compareTo(expected)); return minCompare <= compare && compare <= maxCompare; } @Override public void describeMismatchSafely(T actual, Description mismatchDescription) { mismatchDescription.appendValue(expected) .appendText(" was ") .appendText(comparison(actual.compareTo(expected))) .appendText(" ").appendValue(actual); }; public void describeTo(Description description) { description.appendText("a value ").appendText(comparison(minCompare)); if (minCompare != maxCompare) { description.appendText(" or ").appendText(comparison(maxCompare)); } description.appendText(" ").appendValue(expected); } private String comparison(int compare) { if (compare == EQUAL) { return "equal to"; } else if (compare > EQUAL) { return "greater than"; } else { return "less than"; } } /** * Is value = expected? */ @Factory public static > Matcher comparesEqualTo(T value) { return new OrderingComparison(value, EQUAL, EQUAL); } /** * Is value > expected? */ @Factory public static > Matcher greaterThan(T value) { return new OrderingComparison(value, GREATER_THAN, GREATER_THAN); } /** * Is value >= expected? */ @Factory public static > Matcher greaterThanOrEqualTo(T value) { return new OrderingComparison(value, EQUAL, GREATER_THAN); } /** * Is value < expected? */ @Factory public static > Matcher lessThan(T value) { return new OrderingComparison(value, LESS_THAN, LESS_THAN); } /** * Is value <= expected? */ @Factory public static > Matcher lessThanOrEqualTo(T value) { return new OrderingComparison(value, LESS_THAN, EQUAL); } }libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/number/package.html0000644000175000017500000000014110632277507030527 0ustar moellermoeller

Matchers that perform numeric comparisons.

libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/object/0000755000175000017500000000000011675175275026237 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/object/HasToString.java0000644000175000017500000000207211123147262031267 0ustar moellermoellerpackage org.hamcrest.object; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.Factory; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; public class HasToString extends FeatureMatcher { public HasToString(Matcher toStringMatcher) { super(toStringMatcher, "with toString()", "toString()"); } @Override protected String featureValueOf(T actual) { return actual.toString(); }; /** * Evaluates whether item.toString() satisfies a given matcher. */ @Factory public static Matcher hasToString(Matcher toStringMatcher) { return new HasToString(toStringMatcher); } /** * This is a shortcut to the frequently used has_string(equalTo(x)). * * For example, assertThat(hasToString(equal_to(x))) * vs. assertThat(hasToString(x)) */ @Factory public static Matcher hasToString(String expectedToString) { return new HasToString(equalTo(expectedToString)); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/object/IsCompatibleType.java0000644000175000017500000000162611121016673032302 0ustar moellermoellerpackage org.hamcrest.object; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Factory; import org.hamcrest.TypeSafeMatcher; public class IsCompatibleType extends TypeSafeMatcher> { private final Class type; public IsCompatibleType(Class type) { this.type = type; } @Override public boolean matchesSafely(Class cls) { return type.isAssignableFrom(cls); } @Override public void describeMismatchSafely(Class cls, Description mismatchDescription) { mismatchDescription.appendValue(cls.getName()); } public void describeTo(Description description) { description.appendText("type < ").appendText(type.getName()); } @Factory public static Matcher> typeCompatibleWith(Class baseType) { return new IsCompatibleType(baseType); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/object/IsEventFrom.java0000644000175000017500000000404011123251741031256 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.object; import java.util.EventObject; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; /** * Tests if the value is an event announced by a specific object. */ public class IsEventFrom extends TypeSafeDiagnosingMatcher { private final Class eventClass; private final Object source; public IsEventFrom(Class eventClass, Object source) { this.eventClass = eventClass; this.source = source; } @Override public boolean matchesSafely(EventObject item, Description mismatchDescription) { if (!eventClass.isInstance(item)) { mismatchDescription.appendText("item type was " + item.getClass().getName()); return false; } if (!eventHasSameSource(item)) { mismatchDescription.appendText("source was ").appendValue(item.getSource()); return false; } return true; } private boolean eventHasSameSource(EventObject ev) { return ev.getSource() == source; } public void describeTo(Description description) { description.appendText("an event of type ") .appendText(eventClass.getName()) .appendText(" from ") .appendValue(source); } /** * Constructs an IsEventFrom Matcher that returns true for any object * derived from eventClass announced by source. */ @Factory public static Matcher eventFrom(Class eventClass, Object source) { return new IsEventFrom(eventClass, source); } /** * Constructs an IsEventFrom Matcher that returns true for any object * derived from {@link java.util.EventObject} announced by source * . */ @Factory public static Matcher eventFrom(Object source) { return eventFrom(EventObject.class, source); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/object/package.html0000644000175000017500000000014110632277507030505 0ustar moellermoeller

Matchers that inspect objects and classes.

libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/text/0000755000175000017500000000000011675175275025755 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/text/pattern/0000755000175000017500000000000011161147300027404 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/text/IsEmptyString.java0000644000175000017500000000221411111344640031353 0ustar moellermoeller package org.hamcrest.text; import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.core.IsNull.nullValue; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; /** * Matches empty Strings (and null). */ public final class IsEmptyString extends BaseMatcher { private static final IsEmptyString INSTANCE = new IsEmptyString(); @SuppressWarnings("unchecked") private static final Matcher NULL_OR_EMPTY_INSTANCE = anyOf(nullValue(), INSTANCE); public boolean matches(Object item) { return item != null && item instanceof String && ((String) item).equals(""); } public void describeTo(Description description) { description.appendText("an empty string"); } /** * Matches if value is null or zero-length string. */ @Factory public static Matcher isEmptyString() { return INSTANCE; } /** * Matches if value is null or zero-length string. */ @Factory public static Matcher isEmptyOrNullString() { return NULL_OR_EMPTY_INSTANCE; } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/text/IsEqualIgnoringCase.java0000644000175000017500000000255511121045541032435 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.text; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Factory; import org.hamcrest.TypeSafeMatcher; /** * Tests if a string is equal to another string, regardless of the case. */ public class IsEqualIgnoringCase extends TypeSafeMatcher { // TODO: Replace String with CharSequence to allow for easy interopability between // String, StringBuffer, StringBuilder, CharBuffer, etc (joe). private final String string; public IsEqualIgnoringCase(String string) { if (string == null) { throw new IllegalArgumentException("Non-null value required by IsEqualIgnoringCase()"); } this.string = string; } @Override public boolean matchesSafely(String item) { return string.equalsIgnoreCase(item); } @Override public void describeMismatchSafely(String item, Description mismatchDescription) { mismatchDescription.appendText("was ").appendText(item); } public void describeTo(Description description) { description.appendText("equalToIgnoringCase(") .appendValue(string) .appendText(")"); } @Factory public static Matcher equalToIgnoringCase(String string) { return new IsEqualIgnoringCase(string); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/text/IsEqualIgnoringWhiteSpace.java0000644000175000017500000000401211121044761033607 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.text; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.Factory; import org.hamcrest.TypeSafeMatcher; /** * Tests if a string is equal to another string, ignoring any changes in whitespace. */ public class IsEqualIgnoringWhiteSpace extends TypeSafeMatcher { // TODO: Replace String with CharSequence to allow for easy interopability between // String, StringBuffer, StringBuilder, CharBuffer, etc (joe). private final String string; public IsEqualIgnoringWhiteSpace(String string) { if (string == null) { throw new IllegalArgumentException("Non-null value required by IsEqualIgnoringCase()"); } this.string = string; } @Override public boolean matchesSafely(String item) { return stripSpace(string).equalsIgnoreCase(stripSpace(item)); } @Override public void describeMismatchSafely(String item, Description mismatchDescription) { mismatchDescription.appendText("was ").appendText(stripSpace(item)); } public void describeTo(Description description) { description.appendText("equalToIgnoringWhiteSpace(") .appendValue(string) .appendText(")"); } public String stripSpace(String toBeStripped) { StringBuilder result = new StringBuilder(); boolean lastWasSpace = true; for (int i = 0; i < toBeStripped.length(); i++) { char c = toBeStripped.charAt(i); if (Character.isWhitespace(c)) { if (!lastWasSpace) { result.append(' '); } lastWasSpace = true; } else { result.append(c); lastWasSpace = false; } } return result.toString().trim(); } @Factory public static Matcher equalToIgnoringWhiteSpace(String string) { return new IsEqualIgnoringWhiteSpace(string); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/text/StringContainsInOrder.java0000644000175000017500000000242411124172362033031 0ustar moellermoellerpackage org.hamcrest.text; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; public class StringContainsInOrder extends TypeSafeMatcher { private final Iterable substrings; public StringContainsInOrder(Iterable substrings) { this.substrings = substrings; } @Override public boolean matchesSafely(String s) { int fromIndex = 0; for (String substring : substrings) { fromIndex = s.indexOf(substring, fromIndex); if (fromIndex == -1) { return false; } } return true; } @Override public void describeMismatchSafely(String item, Description mismatchDescription) { mismatchDescription.appendText("was \"").appendText(item).appendText("\""); } public void describeTo(Description description) { description.appendText("a string containing ") .appendValueList("", ", ", "", substrings) .appendText(" in order"); } @Factory public static Matcher stringContainsInOrder(Iterable substrings) { return new StringContainsInOrder(substrings); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/text/package.html0000644000175000017500000000013610632277507030227 0ustar moellermoeller

Matchers that perform text comparisons.

libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/xml/0000755000175000017500000000000011675175275025571 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/xml/HasXPath.java0000644000175000017500000001031011111346402030060 0ustar moellermoellerpackage org.hamcrest.xml; import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.hamcrest.Description; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.w3c.dom.Node; /** * Applies a Matcher to a given XML Node in an existing XML Node tree, specified by an XPath expression. * * @author Joe Walnes */ public class HasXPath extends TypeSafeDiagnosingMatcher { private final Matcher valueMatcher; private final XPathExpression compiledXPath; private final String xpathString; private final QName evaluationMode; /** * @param xPathExpression XPath expression. * @param valueMatcher Matcher to use at given XPath. * May be null to specify that the XPath must exist but the value is irrelevant. */ public HasXPath(String xPathExpression, Matcher valueMatcher) { this(xPathExpression, null, valueMatcher); } /** * @param xPathExpression XPath expression. * @param namespaceContext Resolves XML namespace prefixes in the XPath expression * @param valueMatcher Matcher to use at given XPath. * May be null to specify that the XPath must exist but the value is irrelevant. */ public HasXPath(String xPathExpression, NamespaceContext namespaceContext, Matcher valueMatcher) { this(xPathExpression, namespaceContext, valueMatcher, XPathConstants.STRING); } private HasXPath(String xPathExpression, NamespaceContext namespaceContext, Matcher valueMatcher, QName mode) { try { XPath xPath = XPathFactory.newInstance().newXPath(); if (namespaceContext != null) { xPath.setNamespaceContext(namespaceContext); } compiledXPath = xPath.compile(xPathExpression); this.xpathString = xPathExpression; this.valueMatcher = valueMatcher; this.evaluationMode = mode; } catch (XPathExpressionException e) { throw new IllegalArgumentException("Invalid XPath : " + xPathExpression, e); } } @Override public boolean matchesSafely(Node item, Description mismatchDescription) { try { return matchesResult(compiledXPath.evaluate(item, evaluationMode), mismatchDescription); } catch (XPathExpressionException e) { return false; } } public void describeTo(Description description) { description.appendText("an XML document with XPath ").appendText(xpathString); if (valueMatcher != null) { description.appendText(" ").appendDescriptionOf(valueMatcher); } } private boolean matchesResult(Object result, Description mismatchDescription) { if (result == null) { mismatchDescription.appendText("xpath returned no results."); return false; } else if (valueMatcher == null) { return true; } else { boolean valueMatched = valueMatcher.matches(result); if (!valueMatched) { mismatchDescription.appendText("xpath result "); valueMatcher.describeMismatch(result, mismatchDescription); } return valueMatched; } } @Factory public static Matcher hasXPath(String xPath, Matcher valueMatcher) { return hasXPath(xPath, null, valueMatcher); } @Factory public static Matcher hasXPath(String xPath, NamespaceContext namespaceContext, Matcher valueMatcher) { return new HasXPath(xPath, namespaceContext, valueMatcher, XPathConstants.STRING); } @Factory public static Matcher hasXPath(String xPath) { return hasXPath(xPath, (NamespaceContext) null); } @Factory public static Matcher hasXPath(String xPath, NamespaceContext namespaceContext) { return new HasXPath(xPath, namespaceContext, null, XPathConstants.NODE); } } libhamcrest-java-1.2/hamcrest-library/src/main/java/org/hamcrest/xml/package.html0000644000175000017500000000012110632277507030035 0ustar moellermoeller

Matchers of XML documents.

libhamcrest-java-1.2/hamcrest-text/0000755000175000017500000000000010632277420017243 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-text/src/0000755000175000017500000000000010632277420020032 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-text/src/main/0000755000175000017500000000000011074354330020753 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/0000755000175000017500000000000010632277440020215 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/0000755000175000017500000000000010632277440021004 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/0000755000175000017500000000000010632277441021731 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/0000755000175000017500000000000010632277441022652 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/0000755000175000017500000000000010632277441023441 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/0000755000175000017500000000000011675175275025261 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/beans/0000755000175000017500000000000011675175275026351 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/beans/HasPropertyTest.java0000644000175000017500000000231611121052310032300 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.beans; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.beans.HasProperty.hasProperty; import static org.hamcrest.core.IsNot.not; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; /** * @author Iain McGinniss * @author Nat Pryce * @author Steve Freeman * @since 1.1.0 */ public class HasPropertyTest extends AbstractMatcherTest { private final HasPropertyWithValueTest.BeanWithoutInfo bean = new HasPropertyWithValueTest.BeanWithoutInfo("a bean"); @Override protected Matcher createMatcher() { return hasProperty("irrelevant"); } public void testReturnsTrueIfPropertyExists() { assertThat(bean, hasProperty("writeOnlyProperty")); } public void testReturnsFalseIfPropertyDoesNotExist() { final Matcher hasProperty = hasProperty("aNonExistentProp"); assertThat(bean, not(hasProperty)); assertMismatchDescription("no \"aNonExistentProp\" in <[Person: a bean]>", hasProperty, bean); } public void testDescribeTo() { assertDescription("hasProperty(\"property\")", hasProperty("property")); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/beans/HasPropertyWithValueTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/beans/HasPropertyWithValueTest.ja0000644000175000017500000001047211152217573033626 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.beans; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.beans.HasPropertyWithValue.hasProperty; import static org.hamcrest.core.IsAnything.anything; import static org.hamcrest.core.IsEqual.equalTo; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.beans.SimpleBeanInfo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; import org.hamcrest.core.IsEqual; /** * @author Iain McGinniss * @author Nat Pryce * @author Steve Freeman * @since 1.1.0 */ public class HasPropertyWithValueTest extends AbstractMatcherTest { private final BeanWithoutInfo shouldMatch = new BeanWithoutInfo("is expected"); private final BeanWithoutInfo shouldNotMatch = new BeanWithoutInfo( "not expected"); private final BeanWithInfo beanWithInfo = new BeanWithInfo("with info"); @Override protected Matcher createMatcher() { return hasProperty("irrelevant", anything()); } public void testMatchesInfolessBeanWithMatchedNamedProperty() { assertMatches("with property", hasProperty("property", equalTo("is expected")), shouldMatch); assertMismatchDescription("property \"property\" was \"not expected\"", hasProperty("property", equalTo("is expected")), shouldNotMatch); } public void testMatchesBeanWithInfoWithMatchedNamedProperty() { assertMatches("with bean info", hasProperty("property", equalTo("with info")), beanWithInfo); assertMismatchDescription("property \"property\" was \"with info\"", hasProperty("property", equalTo("without info")), beanWithInfo); } public void testDoesNotMatchInfolessBeanWithoutMatchedNamedProperty() { assertMismatchDescription("No property \"nonExistentProperty\"", hasProperty("nonExistentProperty", anything()), shouldNotMatch); } public void testDoesNotMatchWriteOnlyProperty() { assertMismatchDescription("property \"writeOnlyProperty\" is not readable", hasProperty("writeOnlyProperty", anything()), shouldNotMatch); } public void testDescribeTo() { assertDescription("hasProperty(\"property\", )", hasProperty("property", equalTo(true))); } public void testMatchesPropertyAndValue() { assertMatches("property with value", hasProperty( "property", anything()), beanWithInfo); } public void testDoesNotWriteMismatchIfPropertyMatches() { Description description = new StringDescription(); hasProperty( "property", anything()).describeMismatch(beanWithInfo, description); assertEquals("Expected mismatch description", "", description.toString()); } public void testDescribesMissingPropertyMismatch() { assertMismatchDescription("No property \"honk\"", hasProperty( "honk", anything()), shouldNotMatch); } public void testCanAccessAnAnonymousInnerClass() { class X implements IX { public int getTest() { return 1; } } assertThat(new X(), HasPropertyWithValue.hasProperty("test", IsEqual.equalTo(1))); } interface IX { int getTest(); } public static class BeanWithoutInfo { private String property; public BeanWithoutInfo(String property) { this.property = property; } public String getProperty() { return property; } public void setProperty(String property) { this.property = property; } public void setWriteOnlyProperty(float property) { } @Override public String toString() { return "[Person: " + property + "]"; } } public static class BeanWithInfo { private final String propertyValue; public BeanWithInfo(String propertyValue) { this.propertyValue = propertyValue; } public String property() { return propertyValue; } } public static class BeanWithInfoBeanInfo extends SimpleBeanInfo { @Override public PropertyDescriptor[] getPropertyDescriptors() { try { return new PropertyDescriptor[] { new PropertyDescriptor("property", BeanWithInfo.class, "property", null) }; } catch (IntrospectionException e) { throw new RuntimeException("Introspection exception: " + e.getMessage()); } } } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/beans/SamePropertyValuesAsTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/beans/SamePropertyValuesAsTest.ja0000644000175000017500000000660311130363234033604 0ustar moellermoeller/* Copyright (c) 2000-2008 hamcrest.org */ package org.hamcrest.beans; import static org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class SamePropertyValuesAsTest extends AbstractMatcherTest { private static final Value aValue = new Value("expected"); private static final ExampleBean expectedBean = new ExampleBean("same", 1, aValue); private static final ExampleBean actualBean = new ExampleBean("same", 1, aValue); @Override protected Matcher createMatcher() { return samePropertyValuesAs(expectedBean); } public void testReportsMatchWhenAllPropertiesMatch() { assertMatches("matched properties", samePropertyValuesAs(expectedBean), actualBean); } public void testReportsMismatchWhenActualTypeIsNotAssignableToExpectedType() { assertMismatchDescription("is incompatible type: ExampleBean", samePropertyValuesAs((Object)aValue), actualBean); } public void testReportsMisatchOnFirstPropertyDifference() { assertMismatchDescription("string was \"different\"", samePropertyValuesAs(expectedBean), new ExampleBean("different", 1, aValue)); assertMismatchDescription("int was <2>", samePropertyValuesAs(expectedBean), new ExampleBean("same", 2, aValue)); assertMismatchDescription("value was ", samePropertyValuesAs(expectedBean), new ExampleBean("same", 1, new Value("other"))); } public void testMatchesBeansWithInheritanceButNoExtraProperties() { assertMatches("sub type with same properties", samePropertyValuesAs(expectedBean), new SubBeanWithNoExtraProperties("same", 1, aValue)); } public void testRejectsSubTypeThatHasExtraProperties() { assertMismatchDescription("has extra properties called [extra]", samePropertyValuesAs(expectedBean), new SubBeanWithExtraProperty("same", 1, aValue)); } public void testDescribesItself() { assertDescription("same property values as ExampleBean [int: <1>, string: \"same\", value: ]", samePropertyValuesAs(expectedBean)); } public static class Value { public Value(Object value) { this.value = value; } public final Object value; @Override public String toString() { return "Value " + value; } } public static class ExampleBean { private String stringProperty; private int intProperty; private Value valueProperty; public ExampleBean(String stringProperty, int intProperty, Value valueProperty) { this.stringProperty = stringProperty; this.intProperty = intProperty; this.valueProperty = valueProperty; } public String getString() { return stringProperty; } public int getInt() { return intProperty; } public Value getValue() { return valueProperty; } } public static class SubBeanWithNoExtraProperties extends ExampleBean { public SubBeanWithNoExtraProperties(String stringProperty, int intProperty, Value valueProperty) { super(stringProperty, intProperty, valueProperty); } } public static class SubBeanWithExtraProperty extends ExampleBean { public SubBeanWithExtraProperty(String stringProperty, int intProperty, Value valueProperty) { super(stringProperty, intProperty, valueProperty); } public String getExtra() { return "extra"; } } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/0000755000175000017500000000000011675175275027414 5ustar moellermoeller././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrderTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingInAny0000644000175000017500000000372311161150142033637 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsArrayContainingInAnyOrderTest extends AbstractMatcherTest { @SuppressWarnings("unchecked") @Override protected Matcher createMatcher() { return arrayContainingInAnyOrder(equalTo(1), equalTo(2)); } @SuppressWarnings("unchecked") public void testHasAReadableDescription() { assertDescription("[<1>, <2>] in any order", arrayContainingInAnyOrder(equalTo(1), equalTo(2))); assertDescription("[<1>, <2>] in any order", arrayContainingInAnyOrder(1, 2)); } public void testMatchesItemsInAnyOrder() { assertMatches("in order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3}); assertMatches("out of order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {3, 2, 1}); assertMatches("single", arrayContainingInAnyOrder(1), new Integer[] {1}); } @SuppressWarnings("unchecked") public void testAppliesMatchersInAnyOrder() { assertMatches("in order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); assertMatches("out of order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {3, 2, 1}); assertMatches("single", arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1}); } public void testMismatchesItemsInAnyOrder() { Matcher matcher = arrayContainingInAnyOrder(1, 2, 3); assertMismatchDescription("was null", matcher, null); assertMismatchDescription("No item matches: <1>, <2>, <3> in []", matcher, new Integer[] {}); assertMismatchDescription("No item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1}); assertMismatchDescription("Not matched: <4>", matcher, new Integer[] {4,3,2,1}); } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingInOrderTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingInOrd0000644000175000017500000000331011165350304033632 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder; import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsArrayContainingInOrderTest extends AbstractMatcherTest { @SuppressWarnings("unchecked") @Override protected Matcher createMatcher() { return arrayContaining(equalTo(1), equalTo(2)); } @SuppressWarnings("unchecked") public void testHasAReadableDescription() { assertDescription("[<1>, <2>]", arrayContaining(equalTo(1), equalTo(2))); } public void testMatchesItemsInOrder() { assertMatches("in order", arrayContaining(1, 2, 3), new Integer[] {1, 2, 3}); assertMatches("single", arrayContaining(1), new Integer[] {1}); } @SuppressWarnings("unchecked") public void testAppliesMatchersInOrder() { assertMatches("in order", arrayContaining(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); assertMatches("single", arrayContaining(equalTo(1)), new Integer[] {1}); } public void testMismatchesItemsInOrder() { Matcher matcher = arrayContaining(1, 2, 3); assertMismatchDescription("was null", matcher, null); assertMismatchDescription("No item matched: <1>", matcher, new Integer[] {}); assertMismatchDescription("No item matched: <2>", matcher, new Integer[] {1}); assertMismatchDescription("item 0: was <4>", matcher, new Integer[] {4,3,2,1}); assertMismatchDescription("item 2: was <4>", matcher, new Integer[] {1,2, 4}); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingTest.0000644000175000017500000000577311111332021033616 0ustar moellermoellerpackage org.hamcrest.collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import static org.hamcrest.collection.IsArrayContaining.hasItemInArray; public class IsArrayContainingTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return hasItemInArray("irrelevant"); } public void testMatchesAnArrayThatContainsAnElementMatchingTheGivenMatcher() { assertMatches("should matches array that contains 'a'", hasItemInArray("a"), new String[]{"a", "b", "c"}); } public void testDoesNotMatchAnArrayThatDoesntContainAnElementMatchingTheGivenMatcher() { assertDoesNotMatch("should not matches array that doesn't contain 'a'", hasItemInArray("a"), new String[]{"b", "c"}); assertDoesNotMatch("should not matches empty array", hasItemInArray("a"), new String[0]); } public void testDoesNotMatchNull() { assertDoesNotMatch("should not matches null", hasItemInArray("a"), null); } public void testHasAReadableDescription() { assertDescription("an array containing \"a\"", hasItemInArray("a")); } // Remaining code no longer compiles, thanks to generics. I think that's a good thing, but // I still need to investigate how this behaves with code that doesn't use generics. // I expect ClassCastExceptions will be thrown. // -Joe. // public void testDoesNotMatchObjectThatIsNotAnArray() { // assertDoesNotMatch("should not matches empty list", // arrayContaining("a"), "not a collection"); // } // public void testMatchesPrimitiveArrayElements() { // assertMatches("boolean", arrayContaining(true), new boolean[]{true, false}); // assertDoesNotMatch("boolean", arrayContaining(false), new boolean[]{false}); // // assertMatches("byte", arrayContaining((byte) 1), new byte[]{1, 2, 3}); // assertDoesNotMatch("byte", arrayContaining((byte) 0), new byte[]{1, 2, 3}); // // assertMatches("char", arrayContaining('a'), new char[]{'a', 'b', 'c'}); // assertDoesNotMatch("char", arrayContaining('z'), new char[]{'a', 'b', 'c'}); // // assertMatches("short", arrayContaining((short) 1), new short[]{1, 2, 3}); // assertDoesNotMatch("short", arrayContaining((short) 0), new short[]{1, 2, 3}); // // assertMatches("int", arrayContaining(1), new int[]{1, 2, 3}); // assertDoesNotMatch("int", arrayContaining(0), new int[]{1, 2, 3}); // // assertMatches("long", arrayContaining(1L), new long[]{1, 2, 3}); // assertDoesNotMatch("long", arrayContaining(0L), new long[]{1, 2, 3}); // // assertMatches("float", arrayContaining(1f), new float[]{1f, 2f, 3f}); // assertDoesNotMatch("float", arrayContaining(0f), new float[]{1f, 2f, 3f}); // // assertMatches("double", arrayContaining(1.0), new double[]{1.0, 2.0, 3.0}); // assertDoesNotMatch("double", arrayContaining(0.0), new double[]{1.0, 2.0, 3.0}); // } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayTest.java0000644000175000017500000000276711111332021032446 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsArray.array; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; @SuppressWarnings("unchecked") public class IsArrayTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return array(equalTo("irrelevant")); } public void testMatchesAnArrayThatMatchesAllTheElementMatchers() { assertMatches("should match array with matching elements", array(equalTo("a"), equalTo("b"), equalTo("c")), new String[]{"a", "b", "c"}); } public void testDoesNotMatchAnArrayWhenElementsDoNotMatch() { assertDoesNotMatch("should not match array with different elements", array(equalTo("a"), equalTo("b")), new String[]{"b", "c"}); } public void testDoesNotMatchAnArrayOfDifferentSize() { assertDoesNotMatch("should not match larger array", array(equalTo("a"), equalTo("b")), new String[]{"a", "b", "c"}); assertDoesNotMatch("should not match smaller array", array(equalTo("a"), equalTo("b")), new String[]{"a"}); } public void testDoesNotMatchNull() { assertDoesNotMatch("should not match null", array(equalTo("a")), null); } public void testHasAReadableDescription() { assertDescription("[\"a\", \"b\"]", array(equalTo("a"), equalTo("b"))); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayWithSizeTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayWithSizeTest.ja0000644000175000017500000000247211044676451033626 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; import static org.hamcrest.collection.IsArrayWithSize.emptyArray; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsArrayWithSizeTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return arrayWithSize(equalTo(2)); } public void testMatchesWhenSizeIsCorrect() { assertMatches("correct size", arrayWithSize(equalTo(3)), new Object[] {1, 2, 3}); assertDoesNotMatch("incorrect size", arrayWithSize(equalTo(2)), new Object[] {1, 2, 3}); } public void testProvidesConvenientShortcutForArrayWithSizeEqualTo() { assertMatches("correct size", arrayWithSize(3), new Object[] {1, 2, 3}); assertDoesNotMatch("incorrect size", arrayWithSize(2), new Object[] {1, 2, 3}); } public void testEmptyArray() { assertMatches("correct size", emptyArray(), new Object[] {}); assertDoesNotMatch("incorrect size", emptyArray(), new Object[] {1}); } public void testHasAReadableDescription() { assertDescription("an array with size <3>", arrayWithSize(equalTo(3))); assertDescription("an empty array", emptyArray()); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionContainingTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionContaining0000644000175000017500000000777211165365441033743 0ustar moellermoellerpackage org.hamcrest.collection; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsCollectionContaining.hasItem; import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.hamcrest.core.IsEqual.equalTo; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.core.IsCollectionContaining; import org.hamcrest.core.IsEqual; public class IsCollectionContainingTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return hasItem(equalTo("irrelevant")); } public void testMatchesACollectionThatContainsAnElementMatchingTheGivenMatcher() { Matcher> itemMatcher = hasItem(equalTo("a")); assertMatches("should match list that contains 'a'", itemMatcher, asList("a", "b", "c")); } public void testDoesNotMatchCollectionThatDoesntContainAnElementMatchingTheGivenMatcher() { final Matcher> matcher1 = hasItem(mismatchable("a")); assertMismatchDescription("mismatched: b, mismatched: c", matcher1, asList("b", "c")); final Matcher> matcher2 = hasItem(equalTo("a")); assertMismatchDescription("", matcher2, new ArrayList()); } public void testDoesNotMatchNull() { assertDoesNotMatch("should not matches null", hasItem(equalTo("a")), null); } public void testHasAReadableDescription() { assertDescription("a collection containing \"a\"", hasItem(equalTo("a"))); } public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24 { final Set s = new HashSet(); s.add(Integer.valueOf(2)); assertThat(s, new IsCollectionContaining(new IsEqual(Integer.valueOf(2)))); assertThat(s, IsCollectionContaining.hasItem(Integer.valueOf(2))); } @SuppressWarnings("unchecked") public void testMatchesAllItemsInCollection() { final Matcher> matcher1 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("should match list containing all items", matcher1, asList("a", "b", "c")); final Matcher> matcher2 = hasItems("a", "b", "c"); assertMatches("should match list containing all items (without matchers)", matcher2, asList("a", "b", "c")); final Matcher> matcher3 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("should match list containing all items in any order", matcher3, asList("c", "b", "a")); final Matcher> matcher4 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("should match list containing all items plus others", matcher4, asList("e", "c", "b", "a", "d")); final Matcher> matcher5 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertDoesNotMatch("should not match list unless it contains all items", matcher5, asList("e", "c", "b", "d")); // 'a' missing } private Matcher mismatchable(final String string) { return new TypeSafeDiagnosingMatcher() { @Override protected boolean matchesSafely(String item, Description mismatchDescription) { if (string.equals(item)) return true; mismatchDescription.appendText("mismatched: " + item); return false; } public void describeTo(Description description) { description.appendText("mismatchable: " + string); } }; } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionWithSizeTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionWithSizeTe0000644000175000017500000000603711123142440033664 0ustar moellermoellerpackage org.hamcrest.collection; import static java.util.Arrays.asList; import java.util.ArrayList; import java.util.List; import java.util.Collection; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; public class IsCollectionWithSizeTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return hasSize(7); } public void testMatchesWhenSizeIsCorrect() { assertMatches("correct size", hasSize(equalTo(2)), asList(null, null)); assertMismatchDescription("collection size was <3>", hasSize(equalTo(2)), asList(null, null, null)); } public void testMatchesCollectionWhenSizeIsCorrectUsingObjectElementType() { Collection list = asList(null, null); assertMatches("correct size", hasSize(equalTo(2)), list); assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list); } public void testMatchesCollectionWhenSizeIsCorrectUsingStringElementType() { Collection list = asList("a", "b"); assertMatches("correct size", hasSize(equalTo(2)), list); assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list); } public void testMatchesCollectionWhenSizeIsCorrectUsingWildcardElementType() { Collection list = asList("a", "b"); assertMatches("correct size", hasSize(equalTo(2)), list); assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list); } public void testMatchesListWhenSizeIsCorrectUsingObjectElementType() { List list = asList(null, null); assertMatches("correct size", hasSize(equalTo(2)), list); assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list); } public void testMatchesListWhenSizeIsCorrectUsingStringElementType() { List list = asList("a", "b"); assertMatches("correct size", hasSize(equalTo(2)), list); assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list); } public void testMatchesListWhenSizeIsCorrectUsingWildcardElementType() { List list = asList("a", "b"); assertMatches("correct size", hasSize(equalTo(2)), list); assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list); } public void testProvidesConvenientShortcutForHasSizeEqualTo() { assertMatches("correct size", hasSize(2), asList(null, null)); assertMismatchDescription("collection size was <3>", hasSize(2), asList(null, null, null)); } public void testHasAReadableDescription() { assertDescription("a collection with size <3>", hasSize(equalTo(3))); } public void testCompilesWithATypedCollection() { // To prove Issue 43 ArrayList arrayList = new ArrayList(); MatcherAssert.assertThat(arrayList, hasSize(0)); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsEmptyCollectionTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsEmptyCollectionTest.0000644000175000017500000000171211203515471033643 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.Matchers.is; import static org.hamcrest.collection.IsEmptyCollection.empty; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsEmptyCollectionTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return empty(); } public void testMatchesAnEmptyCollection() { assertMatches("empty collection", empty(), Arrays.asList()); } public void testDoesNotMatchACollectionWithAnItem() { assertMismatchDescription("<[one, three]>", is(empty()), collectionOfValues()); } public void testHasAReadableDescription() { assertDescription("an empty collection", empty()); } private Collection collectionOfValues() { return new ArrayList() {{ add("one"); add("three"); }}; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsEmptyIterableTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsEmptyIterableTest.ja0000644000175000017500000000140211044676452033620 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; import java.util.Arrays; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsEmptyIterableTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return emptyIterable(); } public void testMatchesAnEmptyIterable() { assertMatches("empty iterable", emptyIterable(), Arrays.asList()); } public void testDoesNotMatchAnIterableWithItems() { assertDoesNotMatch("iterable with an item", emptyIterable(), Arrays.asList(1)); } public void testHasAReadableDescription() { assertDescription("an empty iterable", emptyIterable()); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsInTest.java0000644000175000017500000000244211044676452031754 0ustar moellermoellerpackage org.hamcrest.collection; import java.util.Arrays; import java.util.Collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; public class IsInTest extends AbstractMatcherTest { String[] elements = {"a", "b", "c"}; @Override protected Matcher createMatcher() { return new IsIn(elements); } public void testReturnsTrueIfArgumentIsInCollection() { Collection collection = Arrays.asList(elements); Matcher isIn = new IsIn(collection); assertMatches("a", isIn, "a"); assertMatches("b", isIn, "b"); assertMatches("c", isIn, "c"); assertDoesNotMatch("d", isIn, "d"); } public void testReturnsTrueIfArgumentIsInArray() { Matcher isIn = new IsIn(elements); assertMatches("a", isIn, "a"); assertMatches("b", isIn, "b"); assertMatches("c", isIn, "c"); assertDoesNotMatch("d", isIn, "d"); } public void testHasReadableDescription() { Matcher isIn = new IsIn(elements); assertEquals("description", "one of {\"a\", \"b\", \"c\"}", StringDescription.toString(isIn)); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrderTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsIterableContainingIn0000644000175000017500000000443711161156226033654 0ustar moellermoellerpackage org.hamcrest.collection; import static java.util.Arrays.asList; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.hamcrest.collection.IsIterableContainingInOrderTest.make; import static org.hamcrest.collection.IsIterableContainingInOrderTest.value; import java.util.Collections; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import org.hamcrest.collection.IsIterableContainingInOrderTest.WithValue; public class IsIterableContainingInAnyOrderTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return containsInAnyOrder(1, 2); } public void testMatchesSingleItemIterable() { assertMatches("single item", containsInAnyOrder(1), asList(1)); } public void testDoesNotMatchEmpty() { assertMismatchDescription("No item matches: <1>, <2> in []", containsInAnyOrder(1, 2), Collections.emptyList()); } public void testMatchesIterableOutOfOrder() { assertMatches("Out of order", containsInAnyOrder(1, 2), asList(2, 1)); } public void testMatchesIterableInOrder() { assertMatches("In order", containsInAnyOrder(1, 2), asList(1, 2)); } public void testDoesNotMatchIfOneOfMultipleElementsMismatches() { assertMismatchDescription("Not matched: <4>", containsInAnyOrder(1, 2, 3), asList(1, 2, 4)); } @SuppressWarnings("unchecked") public void testDoesNotMatchIfThereAreMoreElementsThanMatchers() { Matcher> helpTheCompilerOut = containsInAnyOrder(value(1), value(3)); assertMismatchDescription("Not matched: ", helpTheCompilerOut, asList(make(1), make(2), make(3))); } public void testDoesNotMatchIfThereAreMoreMatchersThanElements() { assertMismatchDescription("No item matches: <4> in [<1>, <2>, <3>]", containsInAnyOrder(1, 2, 3, 4), asList(1, 2, 3)); } public void testHasAReadableDescription() { assertDescription("iterable over [<1>, <2>] in any order", containsInAnyOrder(1, 2)); } public void testDoesNotMatchIfSingleItemMismatches() throws Exception { assertMismatchDescription("Not matched: ", containsInAnyOrder(value(4)), asList(make(3))); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsIterableContainingInOrderTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsIterableContainingIn0000644000175000017500000000515011162653622033650 0ustar moellermoellerpackage org.hamcrest.collection; import static java.util.Arrays.asList; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import java.util.ArrayList; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; @SuppressWarnings("unchecked") public class IsIterableContainingInOrderTest extends AbstractMatcherTest { private final Matcher> contains123 = contains(value(1), value(2), value(3)); @Override protected Matcher createMatcher() { return contains(1, 2); } public void testMatchingSingleItemIterable() throws Exception { assertMatches("Single item iterable", contains(1), asList(1)); } public void testMatchingMultipleItemIterable() throws Exception { assertMatches("Multiple item iterable", contains(1, 2, 3), asList(1, 2, 3)); } public void testDoesNotMatchWithMoreElementsThanExpected() throws Exception { assertMismatchDescription("Not matched: <4>", contains(1, 2, 3), asList(1, 2, 3, 4)); } public void testDoesNotMatchWithFewerElementsThanExpected() throws Exception { assertMismatchDescription("No item matched: value with <3>", contains123, asList(make(1), make(2))); } public void testDoesNotMatchIfSingleItemMismatches() throws Exception { assertMismatchDescription("item 0: value was <3>", contains(value(4)), asList(make(3))); } public void testDoesNotMatchIfOneOfMultipleItemsMismatch() throws Exception { assertMismatchDescription("item 2: value was <4>", contains123, asList(make(1), make(2), make(4))); } public void testDoesNotMatchEmptyIterable() throws Exception { assertMismatchDescription("No item matched: value with <4>", contains(value(4)), new ArrayList()); } public void testHasAReadableDescription() { assertDescription("iterable over [<1>, <2>]", contains(1, 2)); } public static class WithValue { private final int value; public WithValue(int value) { this.value = value; } public int getValue() { return value; } @Override public String toString() { return "WithValue " + value; } } public static WithValue make(int value) { return new WithValue(value); } public static Matcher value(int value) { return new FeatureMatcher(equalTo(value), "value with", "value") { @Override protected Integer featureValueOf(WithValue actual) { return actual.getValue(); } }; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsIterableWithSizeTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsIterableWithSizeTest0000644000175000017500000000226711044676452033711 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize; import java.util.Arrays; import java.util.Collections; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsIterableWithSizeTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return iterableWithSize(7); } public void testMatchesEmptyIterable() throws Exception { assertMatches("Empty iterable", iterableWithSize(0), Collections.emptyList()); } public void testMatchingSingleItemIterable() throws Exception { assertMatches("Single item iterable", iterableWithSize(1), Arrays.asList(1)); } public void testMatchingMultipleItemIterable() throws Exception { assertMatches("Multiple item iterable", iterableWithSize(3), Arrays.asList(1, 2, 3)); } public void testDoesNotMatchIncorrectSize() throws Exception { assertDoesNotMatch("Incorrect size", iterableWithSize(3), Arrays.asList(1)); } public void testHasAReadableDescription() { assertDescription("an iterable with size <4>", iterableWithSize(4)); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsMapContainingKeyTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsMapContainingKeyTest0000644000175000017500000000503611153041746033661 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsMapContainingKey.hasKey; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; public class IsMapContainingKeyTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return hasKey("foo"); } public void testMatchesSingletonMapContainingKey() { Map map = new HashMap(); map.put("a", 1); assertMatches("Matches single key", hasKey("a"), map); } public void testMatchesMapContainingKey() { Map map = new HashMap(); map.put("a", 1); map.put("b", 2); map.put("c", 3); assertMatches("Matches a", hasKey("a"), map); assertMatches("Matches c", hasKey("c"), map); } // No longer compiles // public void testMatchesMapContainingKeyWithNoGenerics() { // Map map = new HashMap(); // map.put("a", 1); // map.put("b", 2); // map.put("c", 3); // // assertMatches("Matches a", hasKey("a"), map); // assertMatches("Matches c", hasKey("c"), map); // } public void testMatchesMapContainingKeyWithIntegerKeys() throws Exception { Map map = new HashMap(); map.put(1, "A"); map.put(2, "B"); assertThat(map, hasKey(Integer.valueOf(1))); } public void testMatchesMapContainingKeyWithNumberKeys() throws Exception { Map map = new HashMap(); map.put(1, "A"); map.put(2, "B"); assertThat(map, hasKey((Number) Integer.valueOf(1))); // very ugly version! assertThat(map, IsMapContainingKey.hasKey(Integer.valueOf(1))); assertThat(map, hasKey(Integer.valueOf(1))); } public void testHasReadableDescription() { assertDescription("map with key \"a\"", hasKey("a")); } public void testDoesNotMatchEmptyMap() { assertMismatchDescription("map was []", hasKey("Foo"), new HashMap()); } public void testDoesNotMatchMapMissingKey() { Map map = new TreeMap(); map.put("a", 1); map.put("b", 2); map.put("c", 3); assertMismatchDescription("map was [, , ]", hasKey("d"), map); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsMapContainingTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsMapContainingTest.ja0000644000175000017500000000414311126370264033577 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsMapContaining.hasEntry; import static org.hamcrest.core.IsAnything.anything; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import java.util.Map; import java.util.TreeMap; public class IsMapContainingTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return IsMapContaining.hasEntry("irrelevant", "irrelevant"); } public void testMatchesMapContainingMatchingKeyAndValue() { Map map = new TreeMap(); map.put("a", 1); map.put("b", 2); assertMatches("matcherA", hasEntry(equalTo("a"), equalTo(1)), map); assertMatches("matcherB", hasEntry(equalTo("b"), equalTo(2)), map); assertMismatchDescription("map was [, ]", hasEntry(equalTo("c"), equalTo(3)), map); } // no longer compiles. SF // public void testMatchesMapContainingMatchingKeyAndValueWithoutGenerics() { // Map map = new HashMap(); // map.put("a", 1); // map.put("b", 2); // // assertMatches("matcherA", hasEntry(equalTo("a"), equalTo(1)), map); // assertMatches("matcherB", hasEntry(equalTo("b"), equalTo(2)), map); // assertDoesNotMatch("matcherC", hasEntry(equalTo("c"), equalTo(3)), map); // } // public void testDoesNotMatchNull() { assertMismatchDescription("was null", hasEntry(anything(), anything()), null); } public void testHasReadableDescription() { assertDescription("map containing [\"a\"-><2>]", hasEntry(equalTo("a"), (equalTo(2)))); } // Remaining code no longer compiles, thanks to generics. I think that's a good thing, but // I still need to investigate how this behaves with code that doesn't use generics. // I expect ClassCastExceptions will be thrown. // -Joe. // public void testDoesNotMatchAnObjectThatIsNotAMap() { // assertDoesNotMatch("should not matches a string", // mapContaining(ANYTHING, ANYTHING), "not a map"); // } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsMapContainingValueTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsMapContainingValueTe0000644000175000017500000000316111126370267033636 0ustar moellermoellerpackage org.hamcrest.collection; import static org.hamcrest.collection.IsMapContainingValue.hasValue; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; public class IsMapContainingValueTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return hasValue("foo"); } public void testHasReadableDescription() { assertDescription("map with value \"a\"", hasValue("a")); } public void testDoesNotMatchEmptyMap() { Map map = new HashMap(); assertMismatchDescription("map was []", hasValue(1), map); } public void testMatchesSingletonMapContainingValue() { Map map = new HashMap(); map.put("a", 1); assertMatches("Singleton map", hasValue(1), map); } // No longer compiles -- SF // @SuppressWarnings("unchecked") // public void testMatchesSingletonMapContainingValueWithoutGenerics() { // Map map = new HashMap(); // map.put("a", 1); // // assertMatches("Singleton map", hasValue(1), map); // } public void testMatchesMapContainingValue() { Map map = new TreeMap(); map.put("a", 1); map.put("b", 2); map.put("c", 3); assertMatches("hasValue 1", hasValue(1), map); assertMatches("hasValue 3", hasValue(3), map); assertMismatchDescription("map was [, , ]", hasValue(4), map); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/0000755000175000017500000000000011675175275026211 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/AllOfTest.java0000644000175000017500000000413011111332067030662 0ustar moellermoellerpackage org.hamcrest.core; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.AllOf.allOf; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class AllOfTest extends AbstractMatcherTest { @Override @SuppressWarnings("unchecked") protected Matcher createMatcher() { return allOf(equalTo("irrelevant")); } @SuppressWarnings("unchecked") public void testEvaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() { assertThat("good", allOf(equalTo("good"), equalTo("good"))); assertThat("good", not(allOf(equalTo("bad"), equalTo("good")))); assertThat("good", not(allOf(equalTo("good"), equalTo("bad")))); assertThat("good", not(allOf(equalTo("bad"), equalTo("bad")))); } @SuppressWarnings("unchecked") public void testEvaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() { assertThat("good", allOf(equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good"))); assertThat("good", not(allOf(equalTo("good"), equalTo("good"), equalTo("bad"), equalTo("good"), equalTo("good")))); } @SuppressWarnings("unchecked") public void testSupportsMixedTypes() { final Matcher all = allOf( equalTo(new SampleBaseClass("bad")), equalTo(new SampleBaseClass("good")), equalTo(new SampleSubClass("ugly"))); final Matcher negated = not(all); assertThat(new SampleSubClass("good"), negated); } @SuppressWarnings("unchecked") public void testHasAReadableDescription() { assertDescription("(\"good\" and \"bad\" and \"ugly\")", allOf(equalTo("good"), equalTo("bad"), equalTo("ugly"))); } @SuppressWarnings("unchecked") public void testMismatchDescriptionDescribesFirstFailingMatch() { assertMismatchDescription("\"good\" was \"bad\"", allOf(equalTo("bad"), equalTo("good")), "bad"); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/AnyOfTest.java0000644000175000017500000000350111111332163030677 0ustar moellermoellerpackage org.hamcrest.core; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class AnyOfTest extends AbstractMatcherTest { @Override @SuppressWarnings("unchecked") protected Matcher createMatcher() { return anyOf(equalTo("irrelevant")); } @SuppressWarnings("unchecked") public void testEvaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() { assertThat("good", anyOf(equalTo("bad"), equalTo("good"))); assertThat("good", anyOf(equalTo("good"), equalTo("good"))); assertThat("good", anyOf(equalTo("good"), equalTo("bad"))); assertThat("good", not(anyOf(equalTo("bad"), equalTo("bad")))); } @SuppressWarnings("unchecked") public void testEvaluatesToTheTheLogicalDisjunctionOfManyOtherMatchers() { assertThat("good", anyOf(equalTo("bad"), equalTo("good"), equalTo("bad"), equalTo("bad"), equalTo("bad"))); assertThat("good", not(anyOf(equalTo("bad"), equalTo("bad"), equalTo("bad"), equalTo("bad"), equalTo("bad")))); } @SuppressWarnings("unchecked") public void testSupportsMixedTypes() { final Matcher combined = anyOf( equalTo(new SampleBaseClass("bad")), equalTo(new SampleBaseClass("good")), equalTo(new SampleSubClass("ugly")) ); assertThat(new SampleSubClass("good"), combined); } @SuppressWarnings("unchecked") public void testHasAReadableDescription() { assertDescription("(\"good\" or \"bad\" or \"ugly\")", anyOf(equalTo("good"), equalTo("bad"), equalTo("ugly"))); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/CombinableTest.java0000644000175000017500000000407011111331754031725 0ustar moellermoellerpackage org.hamcrest.core; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertEquals; import org.hamcrest.Matchers; import org.hamcrest.StringDescription; import org.junit.Assert; import org.junit.Test; public class CombinableTest { private static final CombinableMatcher EITHER_3_OR_4 = CombinableMatcher.either(equalTo(3)).or(equalTo(4)); private static final CombinableMatcher NOT_3_AND_NOT_4 = CombinableMatcher.both(not(equalTo(3))).and(not(equalTo(4))); @Test public void bothAcceptsAndRejects() { assertThat(2, NOT_3_AND_NOT_4); assertThat(3, not(NOT_3_AND_NOT_4)); } @Test public void acceptsAndRejectsThreeAnds() { final CombinableMatcher tripleAnd = NOT_3_AND_NOT_4.and(equalTo(2)); assertThat(2, tripleAnd); assertThat(3, not(tripleAnd)); } @Test public void bothDescribesItself() { assertEquals("(not <3> and not <4>)", NOT_3_AND_NOT_4.toString()); StringDescription mismatch = new StringDescription(); NOT_3_AND_NOT_4.describeMismatch(3, mismatch); assertEquals("was <3>", mismatch.toString()); } @Test public void eitherAcceptsAndRejects() { assertThat(3, EITHER_3_OR_4); assertThat(6, not(EITHER_3_OR_4)); } @Test public void acceptsAndRejectsThreeOrs() { final CombinableMatcher orTriple = EITHER_3_OR_4.or(Matchers .greaterThan(10)); assertThat(11, orTriple); assertThat(9, not(orTriple)); } @Test public void eitherDescribesItself() { Assert.assertEquals("(<3> or <4>)", EITHER_3_OR_4.toString()); StringDescription mismatch = new StringDescription(); EITHER_3_OR_4.describeMismatch(6, mismatch); Assert.assertEquals("was <6>", mismatch.toString()); } @Test public void picksUpTypeFromLeftHandSideOfExpression() { assertThat("yellow", CombinableMatcher.both(equalTo("yellow")).and(notNullValue())); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/DescribedAsTest.java0000644000175000017500000000250411073234215032043 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.core.DescribedAs.describedAs; import static org.hamcrest.core.IsAnything.anything; import static org.hamcrest.core.IsNot.not; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class DescribedAsTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return describedAs("irrelevant", anything()); } public void testOverridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { Matcher m1 = describedAs("m1 description", anything()); Matcher m2 = describedAs("m2 description", not(anything())); assertDescription("m1 description", m1); assertDescription("m2 description", m2); } public void testAppendsValuesToDescription() { Matcher m = describedAs("value 1 = %0, value 2 = %1", anything(), 33, 97); assertDescription("value 1 = <33>, value 2 = <97>", m); } public void testDelegatesMatchingToAnotherMatcher() { Matcher m1 = describedAs("irrelevant", anything()); Matcher m2 = describedAs("irrelevant", not(anything())); assertTrue(m1.matches(new Object())); assertFalse(m2.matches("hi")); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/EveryTest.java0000644000175000017500000000212111074016156030763 0ustar moellermoellerpackage org.hamcrest.core; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import java.util.ArrayList; import org.hamcrest.StringDescription; import org.junit.Test; public class EveryTest { @Test public void isTrueWhenEveryValueMatches() { assertThat(asList("AaA", "BaB", "CaC"), Every.everyItem(containsString("a"))); assertThat(asList("AbA", "BbB", "CbC"), not(Every.everyItem(containsString("a")))); } @Test public void isAlwaysTrueForEmptyLists() { assertThat(new ArrayList(), Every.everyItem(containsString("a"))); } @Test public void describesItself() { final Every each= new Every(containsString("a")); assertEquals("every item is a string containing \"a\"", each.toString()); StringDescription description = new StringDescription(); each.matchesSafely(asList("BbB"), description); assertEquals("an item was \"BbB\"", description.toString()); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/IsAnythingTest.java0000644000175000017500000000152111112053377031750 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsAnything.anything; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsAnythingTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return anything(); } public void testAlwaysEvaluatesToTrue() { assertThat(null, anything()); assertThat(new Object(), anything()); assertThat("hi", anything()); } public void testHasUsefulDefaultDescription() { assertDescription("ANYTHING", anything()); } public void testCanOverrideDescription() { String description = "description"; assertDescription(description, anything(description)); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/IsEqualTest.java0000644000175000017500000000644511111332021031231 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsEqual.equalTo; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsEqualTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return equalTo("irrelevant"); } public void testComparesObjectsUsingEqualsMethod() { assertThat("hi", equalTo("hi")); assertThat("bye", not(equalTo("hi"))); assertThat(1, equalTo(1)); assertThat(1, not(equalTo(2))); } public void testCanCompareNullValues() { assertThat(null, equalTo(null)); assertThat(null, not(equalTo("hi"))); assertThat("hi", not(equalTo(null))); } public void testHonoursIsEqualImplementationEvenWithNullValues() { Object alwaysEqual = new Object() { @Override public boolean equals(Object obj) { return true; } }; Object neverEqual = new Object() { @Override public boolean equals(Object obj) { return false; } }; assertThat(alwaysEqual, equalTo(null)); assertThat(neverEqual, not(equalTo(null))); } public void testComparesTheElementsOfAnObjectArray() { String[] s1 = {"a", "b"}; String[] s2 = {"a", "b"}; String[] s3 = {"c", "d"}; String[] s4 = {"a", "b", "c", "d"}; assertThat(s1, equalTo(s1)); assertThat(s2, equalTo(s1)); assertThat(s3, not(equalTo(s1))); assertThat(s4, not(equalTo(s1))); } public void testComparesTheElementsOfAnArrayOfPrimitiveTypes() { int[] i1 = new int[]{1, 2}; int[] i2 = new int[]{1, 2}; int[] i3 = new int[]{3, 4}; int[] i4 = new int[]{1, 2, 3, 4}; assertThat(i1, equalTo(i1)); assertThat(i2, equalTo(i1)); assertThat(i3, not(equalTo(i1))); assertThat(i4, not(equalTo(i1))); } public void testRecursivelyTestsElementsOfArrays() { int[][] i1 = new int[][]{{1, 2}, {3, 4}}; int[][] i2 = new int[][]{{1, 2}, {3, 4}}; int[][] i3 = new int[][]{{5, 6}, {7, 8}}; int[][] i4 = new int[][]{{1, 2, 3, 4}, {3, 4}}; assertThat(i1, equalTo(i1)); assertThat(i2, equalTo(i1)); assertThat(i3, not(equalTo(i1))); assertThat(i4, not(equalTo(i1))); } public void testIncludesTheResultOfCallingToStringOnItsArgumentInTheDescription() { final String argumentDescription = "ARGUMENT DESCRIPTION"; Object argument = new Object() { @Override public String toString() { return argumentDescription; } }; assertDescription("<" + argumentDescription + ">", equalTo(argument)); } public void testReturnsAnObviousDescriptionIfCreatedWithANestedMatcherByMistake() { Matcher innerMatcher = equalTo("NestedMatcher"); assertDescription("<" + innerMatcher.toString() + ">", equalTo(innerMatcher)); } public void testReturnsGoodDescriptionIfCreatedWithNullReference() { assertDescription("null", equalTo(null)); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/IsInstanceOfTest.java0000644000175000017500000000360011162457405032225 0ustar moellermoeller/* Copyright (c) 2000-2009 hamcrest.org */ package org.hamcrest.core; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.*; import static org.hamcrest.core.IsNot.not; public class IsInstanceOfTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return instanceOf(Number.class); } public void testEvaluatesToTrueIfArgumentIsInstanceOfASpecificClass() { assertThat(1, instanceOf(Number.class)); assertThat(1.0, instanceOf(Number.class)); assertThat(null, not(instanceOf(Number.class))); assertThat(new Object(), not(instanceOf(Number.class))); } public void testHasAReadableDescription() { assertDescription("an instance of java.lang.Number", instanceOf(Number.class)); } public void testDecribesActualClassInMismatchMessage() { assertMismatchDescription("\"some text\" is a java.lang.String", instanceOf(Number.class), "some text"); } public void testMatchesPrimitiveTypes() { assertThat(true, any(boolean.class)); assertThat((byte)1, any(byte.class)); assertThat('x', any(char.class)); assertThat(5.0, any(double.class)); assertThat(5.0f, any(float.class)); assertThat(2, any(int.class)); assertThat(4L, any(long.class)); assertThat((short)1, any(short.class)); } public void testInstanceOfRequiresACastToReturnTheCorrectTypeForUseInJMock() { @SuppressWarnings("unused") Integer anInteger = (Integer)with(instanceOf(Integer.class)); } public void testAnyWillReturnTheCorrectTypeForUseInJMock() { @SuppressWarnings("unused") Integer anInteger = with(any(Integer.class)); } private static T with(Matcher matcher) { return null; } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/IsNotTest.java0000644000175000017500000000212311175325206030730 0ustar moellermoeller/* Copyright (c) 2000-2009 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsNotTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return not("something"); } public void testEvaluatesToTheTheLogicalNegationOfAnotherMatcher() { assertMatches("should match", not(equalTo("A")), "B"); assertDoesNotMatch("should not match", not(equalTo("B")), "B"); } public void testProvidesConvenientShortcutForNotEqualTo() { assertMatches("should match", not("A"), "B"); assertMatches("should match", not("B"), "A"); assertDoesNotMatch("should not match", not("A"), "A"); assertDoesNotMatch("should not match", not("B"), "B"); } public void testUsesDescriptionOfNegatedMatcherWithPrefix() { assertDescription("not a value greater than <2>", not(greaterThan(2))); assertDescription("not \"A\"", not("A")); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/IsNullTest.java0000644000175000017500000000177311111332021031073 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.core.IsNot.not; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNull.nullValue; import static org.hamcrest.core.IsNull.notNullValue; public class IsNullTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return nullValue(); } public void testEvaluatesToTrueIfArgumentIsNull() { assertThat(null, nullValue()); assertThat(ANY_NON_NULL_ARGUMENT, not(nullValue())); assertThat(ANY_NON_NULL_ARGUMENT, notNullValue()); assertThat(null, not(notNullValue())); } public void testSupportsStaticTyping() { requiresStringMatcher(nullValue(String.class)); requiresStringMatcher(notNullValue(String.class)); } private void requiresStringMatcher(Matcher arg) { // no-op } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/IsSameTest.java0000644000175000017500000000175611111332021031047 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.core; import static org.hamcrest.core.IsSame.sameInstance; import static org.hamcrest.core.IsNot.not; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; public class IsSameTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return sameInstance("irrelevant"); } public void testEvaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { Object o1 = new Object(); Object o2 = new Object(); assertThat(o1, sameInstance(o1)); assertThat(o2, not(sameInstance(o1))); } public void testReturnsReadableDescriptionFromToString() { assertDescription("sameInstance(\"ARG\")", sameInstance("ARG")); } public void testReturnsReadableDescriptionFromToStringWhenInitialisedWithNull() { assertDescription("sameInstance(null)", sameInstance(null)); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/IsTest.java0000644000175000017500000000265711111331223030245 0ustar moellermoellerpackage org.hamcrest.core; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.Is.is; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return is("something"); } public void testJustMatchesTheSameWayTheUnderylingMatcherDoes() { assertMatches("should match", is(equalTo(true)), true); assertMatches("should match", is(equalTo(false)), false); assertDoesNotMatch("should not match", is(equalTo(true)), false); assertDoesNotMatch("should not match", is(equalTo(false)), true); } public void testGeneratesIsPrefixInDescription() { assertDescription("is ", is(equalTo(true))); } public void testProvidesConvenientShortcutForIsEqualTo() { assertMatches("should match", is("A"), "A"); assertMatches("should match", is("B"), "B"); assertDoesNotMatch("should not match", is("A"), "B"); assertDoesNotMatch("should not match", is("B"), "A"); assertDescription("is \"A\"", is("A")); } public void testProvidesConvenientShortcutForIsInstanceOf() { assertTrue("should match", is(String.class).matches("A")); assertFalse("should not match", is(Integer.class).matches(new Object())); assertFalse("should not match", is(Integer.class).matches(null)); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/SampleBaseClass.java0000644000175000017500000000060211111332021032015 0ustar moellermoellerpackage org.hamcrest.core; public class SampleBaseClass { String value; public SampleBaseClass(String value) { this.value = value; } @Override public String toString() { return value; } @Override public boolean equals(Object obj) { return obj instanceof SampleBaseClass && value.equals(((SampleBaseClass) obj).value); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/core/SampleSubClass.java0000644000175000017500000000024011033250112031675 0ustar moellermoellerpackage org.hamcrest.core; public class SampleSubClass extends SampleBaseClass { public SampleSubClass(String value) { super(value); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/0000755000175000017500000000000011675175275027247 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/config/0000755000175000017500000000000011675175275030514 5ustar moellermoeller././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/config/XmlConfiguratorTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/config/XmlConfiguratorT0000644000175000017500000000646111107220350033664 0ustar moellermoellerpackage org.hamcrest.generator.config; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.hamcrest.core.CombinableMatcher; import org.hamcrest.generator.FactoryMethod; import org.hamcrest.generator.FactoryWriter; import org.hamcrest.generator.SugarConfiguration; import org.xml.sax.InputSource; public class XmlConfiguratorTest extends TestCase { private MockSugarConfiguration sugarConfiguration; private XmlConfigurator config; @Override protected void setUp() throws Exception { super.setUp(); sugarConfiguration = new MockSugarConfiguration(); config = new XmlConfigurator(sugarConfiguration, getClass().getClassLoader()); } public void testAddsMatcherFactoryMethodsToConfiguration() throws Exception { config.load(createXml("" + "" + " " + " " + "")); assertThat(sugarConfiguration.factoryMethods(), hasItem(new FactoryMethod(SomeMatcher.class.getName(), "matcher1", "org.hamcrest.Matcher"))); assertThat(sugarConfiguration.factoryMethods(), hasItem(new FactoryMethod(SomeMatcher.class.getName(), "matcher2", "org.hamcrest.Matcher"))); assertThat(sugarConfiguration.factoryMethods(), hasItem(new FactoryMethod(AnotherMatcher.class.getName(), "matcher3", "org.hamcrest.CombinableMatcher"))); } private InputSource createXml(String xml) { return new InputSource(new StringReader(xml)); } // Sample Matchers @SuppressWarnings("unchecked") public static class SomeMatcher { @Factory public static Matcher matcher1() { return null; } @Factory public static Matcher matcher2() { return null; } } @SuppressWarnings("unchecked") public static class AnotherMatcher { @Factory public static CombinableMatcher matcher3() { return null; } } /** * Simple 'record and check' style mock. Not using a mocking library to avoid * cyclical dependency between mocking library and hamcrest. */ private static class MockSugarConfiguration implements SugarConfiguration { private final List seenFactoryMethods = new ArrayList(); private final List seenFactoryWriters = new ArrayList(); public void addWriter(FactoryWriter factoryWriter) { seenFactoryWriters.add(factoryWriter); } public void addFactoryMethod(FactoryMethod method) { seenFactoryMethods.add(method); } public void addFactoryMethods(Iterable methods) { for (FactoryMethod method : methods) { addFactoryMethod(method); } } public List factoryMethods() { return seenFactoryMethods; } } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/EasyMock2FactoryWriterTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/EasyMock2FactoryWriterT0000644000175000017500000001362611111332021033611 0ustar moellermoellerpackage org.hamcrest.generator; import junit.framework.TestCase; import java.io.StringWriter; import java.io.IOException; public class EasyMock2FactoryWriterTest extends TestCase { private FactoryWriter factoryWriter; private StringWriter output = new StringWriter(); @Override protected void setUp() throws Exception { super.setUp(); factoryWriter = new EasyMock2FactoryWriter(output, "com.blah", "EasyMatchers"); } public void testWritesMethodDelegationMethodWrappedInAdapter() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "anyObject", "unusedReturnType"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static java.lang.Object anyObject() {\n" + " org.hamcrest.integration.EasyMockAdapter.adapt(\n" + " com.example.MyMatcher.anyObject());\n" + " return null;\n" + " }\n" + "\n", output.toString()); } public void testWritesReturnType() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "anyString", "unusedReturnType"); method.setGenerifiedType("String"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static String anyString() {\n" + " org.hamcrest.integration.EasyMockAdapter.adapt(\n" + " com.example.MyMatcher.anyString());\n" + " return null;\n" + " }\n" + "\n", output.toString()); } public void testWritesAdvancedGenerifiedMatcherType() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "weirdThing", "unusedReturnType"); method.setGenerifiedType("java.util.Map,?>"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static java.util.Map,?> weirdThing() {\n" + " org.hamcrest.integration.EasyMockAdapter.adapt(\n" + " com.example.MyMatcher.weirdThing());\n" + " return null;\n" + " }\n" + "\n", output.toString()); } public void testWritesParameters() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "between", "unusedReturnType"); method.addParameter("int[]", "lower"); method.addParameter("com.blah.Cheesable...", "upper"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static java.lang.Object between(int[] lower, com.blah.Cheesable... upper) {\n" + " org.hamcrest.integration.EasyMockAdapter.adapt(\n" + " com.example.MyMatcher.between(lower, upper));\n" + " return null;\n" + " }\n" + "\n", output.toString()); } public void testWritesExceptions() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "tricky", "unusedReturnType"); method.addException("java.io.IOException"); method.addException("com.foo.CheeselessException"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static java.lang.Object tricky() throws java.io.IOException, com.foo.CheeselessException {\n" + " org.hamcrest.integration.EasyMockAdapter.adapt(\n" + " com.example.MyMatcher.tricky());\n" + " return null;\n" + " }\n" + "\n", output.toString()); } // // public void testWritesGenericTypeParameters() throws IOException { // FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "tricky"); // method.addGenericTypeParameter("T"); // method.addGenericTypeParameter("V extends String & Cheese"); // method.addParameter("T", "t"); // method.addParameter("List", "v"); // // factoryWriter.writeMethod(method.getName(), method); // assertEquals("" + // " public static org.hamcrest.Matcher tricky(T t, List v) {\n" + // " return com.example.MyMatcher.tricky(t, v);\n" + // " }\n" + // "\n", // output.toString()); // } // // public void testWritesJavaDoc() throws IOException { // FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "needsDoc"); // method.setJavaDoc("This is a complicated method.\nIt needs docs.\n\n@see MoreStuff"); // // factoryWriter.writeMethod(method.getName(), method); // assertEquals("" + // " /**\n" + // " * This is a complicated method.\n" + // " * It needs docs.\n" + // " * \n" + // " * @see MoreStuff\n" + // " */\n" + // " public static org.hamcrest.Matcher needsDoc() {\n" + // " return com.example.MyMatcher.needsDoc();\n" + // " }\n" + // "\n", // output.toString()); // } // // public void testWritesMethodWithNameOverriden() throws IOException { // FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "eq"); // // factoryWriter.writeMethod("anotherName", method); // assertEquals("" + // " public static org.hamcrest.Matcher anotherName() {\n" + // " return com.example.MyMatcher.eq();\n" + // " }\n" + // "\n", // output.toString()); // } // primitives // arrays? // and/or/not/etc } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/HamcrestFactoryWriterTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/HamcrestFactoryWriterTe0000644000175000017500000001464411101755110033737 0ustar moellermoellerpackage org.hamcrest.generator; import java.io.IOException; import java.io.StringWriter; import junit.framework.TestCase; public class HamcrestFactoryWriterTest extends TestCase { private FactoryWriter factoryWriter; private StringWriter output = new StringWriter(); @Override protected void setUp() throws Exception { super.setUp(); factoryWriter = new HamcrestFactoryWriter(null, null, output); } public void testWritesMethodDelegationMethod() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "anyObject", "matcher.ReturnType"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static matcher.ReturnType anyObject() {\n" + " return com.example.MyMatcher.anyObject();\n" + " }\n" + "\n", output.toString()); } public void testWritesCompleteJavaSource() throws IOException { factoryWriter = new HamcrestFactoryWriter("com.some.package", "SomeClass", output); factoryWriter.writeHeader(); factoryWriter.writeMethod("method1", new FactoryMethod("com.example.MyMatcher", "method1", "matcher.ReturnType")); factoryWriter.writeMethod("method2", new FactoryMethod("com.example.MyMatcher", "method2", "matcher.ReturnType")); factoryWriter.writeFooter(); assertEquals("" + "// Generated source.\n" + "package com.some.package;\n" + "\n" + "public class SomeClass {\n" + "\n" + " public static matcher.ReturnType method1() {\n" + " return com.example.MyMatcher.method1();\n" + " }\n" + "\n" + " public static matcher.ReturnType method2() {\n" + " return com.example.MyMatcher.method2();\n" + " }\n" + "\n" + "}\n", output.toString()); } public void testWritesGenerifiedMatcherType() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "anyString", "matcher.ReturnType"); method.setGenerifiedType("String"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static matcher.ReturnType anyString() {\n" + " return com.example.MyMatcher.anyString();\n" + " }\n" + "\n", output.toString()); } public void testWritesAdvancedGenerifiedMatcherType() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "weirdThing", "matcher.ReturnType"); method.setGenerifiedType("java.util.Map,?>"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static matcher.ReturnType,?>> weirdThing() {\n" + " return com.example.MyMatcher.weirdThing();\n" + " }\n" + "\n", output.toString()); } public void testWritesParameters() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "between", "matcher.ReturnType"); method.addParameter("int[]", "lower"); method.addParameter("com.blah.Cheesable...", "upper"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static matcher.ReturnType between(int[] lower, com.blah.Cheesable... upper) {\n" + " return com.example.MyMatcher.between(lower, upper);\n" + " }\n" + "\n", output.toString()); } public void testWritesExceptions() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "tricky", "matcher.ReturnType"); method.addException("java.io.IOException"); method.addException("com.foo.CheeselessException"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static matcher.ReturnType tricky() throws java.io.IOException, com.foo.CheeselessException {\n" + " return com.example.MyMatcher.tricky();\n" + " }\n" + "\n", output.toString()); } public void testWritesGenericTypeParameters() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "tricky", "matcher.ReturnType"); method.addGenericTypeParameter("T"); method.addGenericTypeParameter("V extends String & Cheese"); method.addParameter("T", "t"); method.addParameter("List", "v"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " public static matcher.ReturnType tricky(T t, List v) {\n" + " return com.example.MyMatcher.tricky(t, v);\n" + " }\n" + "\n", output.toString()); } public void testWritesJavaDoc() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "needsDoc", "matcher.ReturnType"); method.setJavaDoc("This is a complicated method.\nIt needs docs.\n\n@see MoreStuff"); factoryWriter.writeMethod(method.getName(), method); assertEquals("" + " /**\n" + " * This is a complicated method.\n" + " * It needs docs.\n" + " * \n" + " * @see MoreStuff\n" + " */\n" + " public static matcher.ReturnType needsDoc() {\n" + " return com.example.MyMatcher.needsDoc();\n" + " }\n" + "\n", output.toString()); } public void testWritesMethodWithNameOverriden() throws IOException { FactoryMethod method = new FactoryMethod("com.example.MyMatcher", "eq", "matcher.ReturnType"); factoryWriter.writeMethod("anotherName", method); assertEquals("" + " public static matcher.ReturnType anotherName() {\n" + " return com.example.MyMatcher.eq();\n" + " }\n" + "\n", output.toString()); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/QDoxFactoryReaderTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/QDoxFactoryReaderTest.j0000644000175000017500000000463011074020300033556 0ustar moellermoellerpackage org.hamcrest.generator; import junit.framework.TestCase; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class QDoxFactoryReaderTest extends TestCase { public void testExtractsOriginalParameterNamesFromSource() { FactoryMethod method = new FactoryMethod("org.SomeClass", "someMethod", "unusedReturnType"); method.addParameter("java.lang.String", "badParamName"); String input = "" + "package org;\n" + "class SomeClass {\n" + " Matcher someMethod(String realParamName) { ... } \n" + "}\n"; FactoryMethod factoryMethod = wrapUsingQDoxedSource(method, "org.SomeClass", input); assertEquals("java.lang.String", factoryMethod.getParameters().get(0).getType()); assertEquals("realParamName", factoryMethod.getParameters().get(0).getName()); } public void testExtractsOriginalJavaDocFromSource() { FactoryMethod method = new FactoryMethod("org.SomeClass", "someMethod", "unusedReturnType"); String input = "" + "package org;\n" + "class SomeClass {\n" + " /**\n" + " * This class does something.\n" + " *\n" + " * @return stuff.\n" + " */\n" + " Matcher someMethod() { ... } \n" + "}\n"; FactoryMethod factoryMethod = wrapUsingQDoxedSource(method, "org.SomeClass", input); assertEquals("This class does something.\n\n@return stuff.\n", factoryMethod.getJavaDoc()); } private FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod, String className, String input) { List originalMethods = new ArrayList(); originalMethods.add(originalMethod); QDox qdox = new QDox(); qdox.addSource(new StringReader(input)); QDoxFactoryReader qDoxFactoryReader = new QDoxFactoryReader( originalMethods, qdox, className); return getFirstFactoryMethod(qDoxFactoryReader); } private FactoryMethod getFirstFactoryMethod(QDoxFactoryReader qDoxFactoryReader) { Iterator iterator = qDoxFactoryReader.iterator(); iterator.hasNext(); return iterator.next(); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/QuickReferenceWriterTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/QuickReferenceWriterTes0000644000175000017500000000411311074020473033713 0ustar moellermoellerpackage org.hamcrest.generator; import junit.framework.TestCase; import java.io.PrintStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class QuickReferenceWriterTest extends TestCase { private ByteArrayOutputStream actualBuffer; private ByteArrayOutputStream expectedBuffer; private PrintStream expected; private QuickReferenceWriter writer; @Override protected void setUp() throws Exception { super.setUp(); actualBuffer = new ByteArrayOutputStream(); writer = new QuickReferenceWriter(new PrintStream(actualBuffer)); expectedBuffer = new ByteArrayOutputStream(); expected = new PrintStream(expectedBuffer); } public void testWritesSimplifiedSummaryOfMatchers() throws IOException { FactoryMethod namedMethod = new FactoryMethod("SomeClass", "someMethod", "unusedReturnType"); namedMethod.addParameter("Cheese", "a"); namedMethod.addParameter("int", "b"); namedMethod.setGenerifiedType("String"); writer.writeMethod("namedMethod", namedMethod); FactoryMethod anotherMethod = new FactoryMethod("SomeClass", "anotherMethod", "unusedReturnType"); anotherMethod.setGenerifiedType("int"); writer.writeMethod("anotherMethod", anotherMethod); expected.println(" [String] namedMethod(Cheese a, int b)"); expected.println(" [int] anotherMethod()"); verify(); } public void testRemovesPackageNames() throws IOException { FactoryMethod namedMethod = new FactoryMethod("SomeClass", "someMethod", "unusedReturnType"); namedMethod.addParameter("com.blah.Foo", "a"); namedMethod.addParameter("com.foo.Cheese", "b"); namedMethod.setGenerifiedType("java.lang.Cheese"); writer.writeMethod("namedMethod", namedMethod); expected.println(" [Cheese] namedMethod(Foo a, Cheese b)"); verify(); } private void verify() { assertEquals(new String(expectedBuffer.toByteArray()), new String(actualBuffer.toByteArray())); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/ReflectiveFactoryReaderTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/generator/ReflectiveFactoryReader0000644000175000017500000002115011107220350033703 0ustar moellermoellerpackage org.hamcrest.generator; import junit.framework.TestCase; import org.hamcrest.BaseMatcher; import org.hamcrest.Factory; import org.hamcrest.Matcher; import java.io.IOException; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @SuppressWarnings("unused") public class ReflectiveFactoryReaderTest extends TestCase { public static class SimpleSetOfMatchers { @Factory public static Matcher firstMethod() { return null; } @Factory public static Matcher secondMethod() { return null; } } public void testIteratesOverFactoryMethods() { Iterable reader = new ReflectiveFactoryReader(SimpleSetOfMatchers.class); Iterator methods = reader.iterator(); assertTrue("Expected first method", methods.hasNext()); FactoryMethod firstMethod = methods.next(); assertEquals("firstMethod", firstMethod.getName()); assertEquals(SimpleSetOfMatchers.class.getName(), firstMethod.getMatcherClass()); assertTrue("Expected second method", methods.hasNext()); FactoryMethod secondMethod = methods.next(); assertEquals("secondMethod", secondMethod.getName()); assertEquals(SimpleSetOfMatchers.class.getName(), secondMethod.getMatcherClass()); assertFalse("Expected no more methods", methods.hasNext()); } public static class MatchersWithDodgySignatures { @Factory public Matcher notStatic() { return null; } @Factory static Matcher notPublic() { return null; } public static Matcher noAnnotation() { return null; } @Factory public static Matcher goodMethod() { return null; } @Factory public static Matcher anotherGoodMethod() { return null; } @Factory public static String wrongReturnType() { return null; } } public void testOnlyReadsPublicStaticAnnotatedMethodsThatReturnMatcher() { Iterable reader = new ReflectiveFactoryReader(MatchersWithDodgySignatures.class); Iterator methods = reader.iterator(); assertTrue("Expected first method", methods.hasNext()); assertEquals("goodMethod", methods.next().getName()); assertTrue("Expected second method", methods.hasNext()); assertEquals("anotherGoodMethod", methods.next().getName()); assertFalse("Expected no more methods", methods.hasNext()); } public static class GenerifiedMatchers { @Factory public static Matcher> generifiedType() { return null; } @SuppressWarnings("unchecked") @Factory public static Matcher noGenerifiedType() { return null; } @Factory public static Matcher, Factory>> crazyType() { return null; } } public void testReadsFullyQualifiedGenericType() { FactoryMethod method = readMethod(GenerifiedMatchers.class, "generifiedType"); assertEquals("java.util.Comparator", method.getGenerifiedType()); } public void testReadsNullGenerifiedTypeIfNotPresent() { FactoryMethod method = readMethod(GenerifiedMatchers.class, "noGenerifiedType"); assertNull(method.getGenerifiedType()); } public void testReadsGenericsInGenericType() { FactoryMethod method = readMethod(GenerifiedMatchers.class, "crazyType"); assertEquals( "java.util.Map, org.hamcrest.Factory>", method.getGenerifiedType()); } public static class ParamterizedMatchers { @Factory public static Matcher withParam(String someString, int[] numbers, Collection things) { return null; } @Factory public static Matcher withArray(String[] array) { return null; } @Factory public static Matcher withVarArgs(String... things) { return null; } @Factory public static Matcher withGenerifiedParam(Collection> things, Set[] x) { return null; } } public void testReadsParameterTypes() { FactoryMethod method = readMethod(ParamterizedMatchers.class, "withParam"); List params = method.getParameters(); assertEquals(3, params.size()); assertEquals("java.lang.String", params.get(0).getType()); assertEquals("int[]", params.get(1).getType()); assertEquals("java.util.Collection", params.get(2).getType()); } public void testReadsArrayAndVarArgParameterTypes() { FactoryMethod arrayMethod = readMethod(ParamterizedMatchers.class, "withArray"); assertEquals("java.lang.String[]", arrayMethod.getParameters().get(0).getType()); FactoryMethod varArgsMethod = readMethod(ParamterizedMatchers.class, "withVarArgs"); assertEquals("java.lang.String...", varArgsMethod.getParameters().get(0).getType()); } public void testReadsGenerifiedParameterTypes() { FactoryMethod method = readMethod(ParamterizedMatchers.class, "withGenerifiedParam"); assertEquals("java.util.Collection>", method.getParameters().get(0).getType()); assertEquals("java.util.Set[]", method.getParameters().get(1).getType()); } public void testCannotReadParameterNamesSoMakesThemUpInstead() { FactoryMethod method = readMethod(ParamterizedMatchers.class, "withParam"); List params = method.getParameters(); assertEquals("param1", params.get(0).getName()); assertEquals("param2", params.get(1).getName()); assertEquals("param3", params.get(2).getName()); } public static class ExceptionalMatchers { @Factory public static Matcher withExceptions() throws Error, IOException, RuntimeException { return null; } } public void testReadsExceptions() { FactoryMethod method = readMethod(ExceptionalMatchers.class, "withExceptions"); List exceptions = method.getExceptions(); assertEquals(3, exceptions.size()); assertEquals("java.lang.Error", exceptions.get(0)); assertEquals("java.io.IOException", exceptions.get(1)); assertEquals("java.lang.RuntimeException", exceptions.get(2)); } public static class WithJavaDoc { /** * Look at me! * * @return something */ @Factory public static Matcher documented() { return null; } } public void testCannotReadJavaDoc() { // JavaDoc information is not available through reflection alone. FactoryMethod method = readMethod(WithJavaDoc.class, "documented"); assertEquals(null, method.getJavaDoc()); } public static class G { @Factory public static & Comparable> Matcher> x(Set t, V v) { return null; } } public void testReadsGenericTypeParameters() { FactoryMethod method = readMethod(G.class, "x"); assertEquals("T", method.getGenericTypeParameters().get(0)); assertEquals("V extends java.util.List & java.lang.Comparable", method.getGenericTypeParameters().get(1)); assertEquals("java.util.Map", method.getGenerifiedType()); assertEquals("java.util.Set", method.getParameters().get(0).getType()); assertEquals("V", method.getParameters().get(1).getType()); } public static class SubclassOfMatcher { @Factory public static BaseMatcher subclassMethod() { return null; } } public void testCatchesSubclasses() { assertNotNull(readMethod(SubclassOfMatcher.class, "subclassMethod")); } private FactoryMethod readMethod(Class cls, String methodName) { for (FactoryMethod method : new ReflectiveFactoryReader(cls)) { if (method.getName().equals(methodName)) { return method; } } return null; } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/integration/0000755000175000017500000000000011675175275027604 5ustar moellermoeller././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/integration/EasyMock2AdapterTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/integration/EasyMock2AdapterTest.0000644000175000017500000000244011033250107033513 0ustar moellermoellerpackage org.hamcrest.integration; import junit.framework.TestCase; import org.easymock.IArgumentMatcher; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import static org.hamcrest.core.IsEqual.equalTo; public class EasyMock2AdapterTest extends TestCase { public static interface InterfaceToMock { void doStuff(String name, int number); } public void testAdaptsHamcrestMatcherToEasyMockArgumentsMatcher() { IArgumentMatcher easyMockMatcher = new EasyMock2Adapter(equalTo("expected")); assertTrue("Should have matched", easyMockMatcher.matches("expected")); assertFalse("Should not have matched", easyMockMatcher.matches("unexpected")); } public void testDelegatesDescriptionToUnderlyingMatcher() { IArgumentMatcher easyMockMatcher = new EasyMock2Adapter(new BaseMatcher() { public boolean matches(Object o) { return false; } public void describeTo(Description description) { description.appendText("is like "); description.appendValue("cheese"); } }); StringBuffer buffer = new StringBuffer(); easyMockMatcher.appendTo(buffer); assertEquals("is like \"cheese\"", buffer.toString()); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/integration/JMock1AdapterTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/integration/JMock1AdapterTest.jav0000644000175000017500000000240311033250107033502 0ustar moellermoellerpackage org.hamcrest.integration; import junit.framework.TestCase; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import static org.hamcrest.core.IsEqual.equalTo; import org.jmock.core.Constraint; public class JMock1AdapterTest extends TestCase { public static interface InterfaceToMock { void doStuff(String name, int number); } public void testAdaptsHamcrestMatcherToJMockConstraint() { Constraint jMockConstraint = new JMock1Adapter(equalTo("expected")); assertTrue("Should have matched", jMockConstraint.eval("expected")); assertFalse("Should not have matched", jMockConstraint.eval("unexpected")); } public void testDelegatesDescriptionToUnderlyingMatcher() { Constraint jMockConstraint = new JMock1Adapter(new BaseMatcher() { public boolean matches(Object o) { return false; } public void describeTo(Description description) { description.appendText("is like "); description.appendValue("cheese"); } }); StringBuffer buffer = new StringBuffer(); buffer = jMockConstraint.describeTo(buffer); assertEquals("is like \"cheese\"", buffer.toString()); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/internal/0000755000175000017500000000000010632277456027071 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/number/0000755000175000017500000000000011675175275026551 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/number/IsCloseToTest.java0000644000175000017500000000160511121051744032076 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.number; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import static org.hamcrest.number.IsCloseTo.closeTo; public class IsCloseToTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { double irrelevant = 0.1; return closeTo(irrelevant, irrelevant); } public void testEvaluatesToTrueIfArgumentIsEqualToADoubleValueWithinSomeError() { Matcher p = closeTo(1.0, 0.5); assertTrue(p.matches(1.0)); assertTrue(p.matches(0.5d)); assertTrue(p.matches(1.5d)); assertDoesNotMatch("too large", p, 2.0); assertMismatchDescription("<2.0> differed by <0.5>", p, 2.0); assertDoesNotMatch("number too small", p, 0.0); assertMismatchDescription("<0.0> differed by <0.5>", p, 0.0); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/number/OrderingComparisonTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/number/OrderingComparisonTest.jav0000644000175000017500000000503111175325207033701 0ustar moellermoeller/* Copyright (c) 2000-2009 hamcrest.org */ package org.hamcrest.number; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.number.OrderingComparison.comparesEqualTo; import static org.hamcrest.number.OrderingComparison.greaterThan; import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo; import static org.hamcrest.number.OrderingComparison.lessThan; import static org.hamcrest.number.OrderingComparison.lessThanOrEqualTo; import java.math.BigDecimal; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class OrderingComparisonTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return greaterThan(1); } public void testDescription() { assertDescription("a value greater than <1>", greaterThan(1)); assertDescription("a value equal to or greater than <1>", greaterThanOrEqualTo(1)); assertDescription("a value equal to <1>", comparesEqualTo(1)); assertDescription("a value less than or equal to <1>", lessThanOrEqualTo(1)); assertDescription("a value less than <1>", lessThan(1)); } public void testMismatchDescriptions() { assertMismatchDescription("<1> was less than <0>", greaterThan(1), 0); assertMismatchDescription("<1> was equal to <1>", greaterThan(1), 1); assertMismatchDescription("<0> was greater than <1>", lessThan(0), 1); } public void testComparesObjectsForGreaterThan() { assertThat(2, greaterThan(1)); assertThat(0, not(greaterThan(1))); } public void testComparesObjectsForLessThan() { assertThat(2, lessThan(3)); assertThat(0, lessThan(1)); } public void testComparesObjectsForEquality() { assertThat(3, comparesEqualTo(3)); assertThat("aa", comparesEqualTo("aa")); } public void testAllowsForInclusiveComparisons() { assertThat("less", 1, lessThanOrEqualTo(1)); assertThat("greater", 1, greaterThanOrEqualTo(1)); } public void testSupportsDifferentTypesOfComparableObjects() { assertThat(1.1, greaterThan(1.0)); assertThat("cc", greaterThan("bb")); } public void testComparesBigDecimalsWithDifferentScalesCorrectlyForIssue20() { assertThat(new BigDecimal("10.0"), greaterThanOrEqualTo(new BigDecimal("10"))); assertThat(new BigDecimal(10), greaterThanOrEqualTo(new BigDecimal("10.0"))); assertThat(new BigDecimal("2"), comparesEqualTo(new BigDecimal("2.000"))); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/object/0000755000175000017500000000000011675175275026527 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/object/HasToStringTest.java0000644000175000017500000000336411123147354032426 0ustar moellermoellerpackage org.hamcrest.object; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.object.HasToString.hasToString; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; public class HasToStringTest extends AbstractMatcherTest { private static final String TO_STRING_RESULT = "toString result"; private static final Object ARG = new Object() { @Override public String toString() { return TO_STRING_RESULT; } }; @Override protected Matcher createMatcher() { return hasToString(equalTo("irrelevant")); } public void testPassesResultOfToStringToNestedMatcher() { assertThat(ARG, hasToString(equalTo(TO_STRING_RESULT))); assertThat(ARG, not(hasToString(equalTo("OTHER STRING")))); } public void testProvidesConvenientShortcutForHasToStringEqualTo() { assertThat(ARG, hasToString(TO_STRING_RESULT)); assertThat(ARG, not(hasToString("OTHER STRING"))); } public void testHasReadableDescription() { Matcher toStringMatcher = equalTo(TO_STRING_RESULT); Matcher> matcher = hasToString(toStringMatcher); assertEquals("with toString() " + descriptionOf(toStringMatcher), descriptionOf(matcher)); } public void testMismatchContainsToStringValue() { String expectedMismatchString = "toString() was \"Cheese\""; assertMismatchDescription(expectedMismatchString, hasToString(TO_STRING_RESULT), "Cheese"); } private String descriptionOf(Matcher matcher) { return StringDescription.asString(matcher); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/object/IsCompatibleTypeTest.java0000644000175000017500000000335511111332021033416 0ustar moellermoellerpackage org.hamcrest.object; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.object.IsCompatibleType.typeCompatibleWith; public class IsCompatibleTypeTest extends AbstractMatcherTest { public static class BaseClass { } public static class ExtendedClass extends BaseClass { } public interface BaseInterface { } public interface ExtendedInterface extends BaseInterface { } public static class ClassImplementingBaseInterface implements BaseInterface { } @Override protected Matcher createMatcher() { return typeCompatibleWith(BaseClass.class); } public void testMatchesSameClass() { assertThat(BaseClass.class, typeCompatibleWith(BaseClass.class)); } public void testMatchesSameInterface() { assertThat(BaseInterface.class, typeCompatibleWith(BaseInterface.class)); } public void testMatchesExtendedClass() { assertThat(ExtendedClass.class, typeCompatibleWith(BaseClass.class)); } public void testMatchesClassImplementingInterface() { assertThat(ClassImplementingBaseInterface.class, typeCompatibleWith(BaseInterface.class)); } public void testMatchesExtendedInterface() { assertThat(ExtendedInterface.class, typeCompatibleWith(BaseInterface.class)); } // public void testDoesNotMatchIncompatibleTypes() { // assertThat(BaseClass.class, not(compatibleType(ExtendedClass.class))); // assertThat(Integer.class, not(compatibleType(String.class))); // } public void testHasReadableDescription() { assertDescription("type < java.lang.Runnable", typeCompatibleWith(Runnable.class)); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/object/IsEventFromTest.java0000644000175000017500000000346511123252226032417 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.object; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.object.IsEventFrom.eventFrom; import java.util.EventObject; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsEventFromTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return eventFrom(null); } public void testEvaluatesToTrueIfArgumentIsAnEventObjectFiredByASpecifiedSource() { Object o = "Source"; EventObject ev = new EventObject(o); EventObject ev2 = new EventObject("source 2"); Matcher isEventMatcher = eventFrom(o); assertThat(ev, isEventMatcher); assertMismatchDescription("source was \"source 2\"", isEventMatcher, ev2); } private static class DerivedEvent extends EventObject { private static final long serialVersionUID = 1L; public DerivedEvent(Object source) { super(source); } } public void testCanTestForSpecificEventClasses() { Object o = new Object(); DerivedEvent goodEv = new DerivedEvent(o); DerivedEvent wrongSource = new DerivedEvent("wrong source"); EventObject wrongType = new EventObject(o); EventObject wrongSourceAndType = new EventObject(new Object()); Matcher isEventMatcher = IsEventFrom.eventFrom(DerivedEvent.class, o); assertThat(goodEv, isEventMatcher); assertMismatchDescription("source was \"wrong source\"", isEventMatcher, wrongSource); assertMismatchDescription("item type was java.util.EventObject", isEventMatcher, wrongType); assertMismatchDescription("item type was java.util.EventObject", isEventMatcher, wrongSourceAndType); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/0000755000175000017500000000000011675175275026245 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/pattern/0000755000175000017500000000000011074571376027715 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/IsEmptyStringTest.java0000644000175000017500000000214511111344434032507 0ustar moellermoellerpackage org.hamcrest.text; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.text.IsEmptyString.isEmptyOrNullString; import static org.hamcrest.text.IsEmptyString.isEmptyString; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsEmptyStringTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return isEmptyOrNullString(); } public void testEmptyOrNullIsNull() { assertThat(null, isEmptyOrNullString()); } public void testEmptyIsNotNull() { assertThat(null, not(isEmptyString())); } public void testMatchesEmptyString() { assertMatches("empty string", isEmptyString(), ""); assertMatches("empty string", isEmptyOrNullString(), ""); } public void testDoesNotMatchNonEmptyString() { assertDoesNotMatch("non empty string", isEmptyString(), "a"); } public void testHasAReadableDescription() { assertDescription("an empty string", isEmptyString()); assertDescription("(null or an empty string)", isEmptyOrNullString()); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java0000644000175000017500000000301111111332021033540 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.text; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase; public class IsEqualIgnoringCaseTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return equalToIgnoringCase("irrelevant"); } public void testIgnoresCaseOfCharsInString() { assertThat("HELLO", equalToIgnoringCase("heLLo")); assertThat("hello", equalToIgnoringCase("heLLo")); assertThat("HelLo", equalToIgnoringCase("heLLo")); assertThat("bye", not(equalToIgnoringCase("heLLo"))); } public void testFailsIfAdditionalWhitespaceIsPresent() { assertThat("heLLo ", not(equalToIgnoringCase("heLLo"))); assertThat(" heLLo", not(equalToIgnoringCase("heLLo"))); } public void testFailsIfMatchingAgainstNull() { assertThat(null, not(equalToIgnoringCase("heLLo"))); } public void testRequiresNonNullStringToBeConstructed() { try { equalToIgnoringCase(null); fail("Expected exception"); } catch (IllegalArgumentException goodException) { // expected! } } public void testDescribesItselfAsCaseInsensitive() { assertDescription("equalToIgnoringCase(\"heLLo\")", equalToIgnoringCase("heLLo")); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/IsEqualIgnoringWhiteSpaceTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/IsEqualIgnoringWhiteSpaceTes0000644000175000017500000000326411111332021033627 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.text; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.text.IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class IsEqualIgnoringWhiteSpaceTest extends AbstractMatcherTest { private final Matcher matcher = equalToIgnoringWhiteSpace("Hello World how\n are we? "); @Override protected Matcher createMatcher() { return matcher; } public void testPassesIfWordsAreSameButWhitespaceDiffers() { assertThat("Hello World how are we?", matcher); assertThat(" Hello World how are \n\n\twe?", matcher); } public void testFailsIfTextOtherThanWhitespaceDiffers() { assertThat("Hello PLANET how are we?", not(matcher)); assertThat("Hello World how are we", not(matcher)); } public void testFailsIfWhitespaceIsAddedOrRemovedInMidWord() { assertThat("HelloWorld how are we?", not(matcher)); assertThat("Hello Wo rld how are we?", not(matcher)); } public void testFailsIfMatchingAgainstNull() { assertThat(null, not(matcher)); } public void testRequiresNonNullStringToBeConstructed() { try { new IsEqualIgnoringWhiteSpace(null); fail("Expected exception"); } catch (IllegalArgumentException goodException) { // expected! } } public void testHasAReadableDescription() { assertDescription("equalToIgnoringWhiteSpace(\"Hello World how\\n are we? \")", matcher); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/StringContainsInOrderTest.javalibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/StringContainsInOrderTest.ja0000644000175000017500000000171311111332021033614 0ustar moellermoellerpackage org.hamcrest.text; import static java.util.Arrays.asList; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class StringContainsInOrderTest extends AbstractMatcherTest { StringContainsInOrder m = new StringContainsInOrder(asList("a", "b", "c")); @Override protected Matcher createMatcher() { return m; } public void testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder() { assertMatches("substrings in order", m, "abc"); assertMatches("substrings separated", m, "1a2b3c4"); assertDoesNotMatch("substrings out of order", m, "cab"); assertDoesNotMatch("no substrings in string", m, "xyz"); assertDoesNotMatch("substring missing", m, "ac"); assertDoesNotMatch("empty string", m, ""); } public void testHasAReadableDescription() { assertDescription("a string containing \"a\", \"b\", \"c\" in order", m); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/StringContainsTest.java0000644000175000017500000000313411111332021032657 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.text; import static org.hamcrest.core.StringContains.containsString; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class StringContainsTest extends AbstractMatcherTest { static final String EXCERPT = "EXCERPT"; Matcher stringContains = containsString(EXCERPT); @Override protected Matcher createMatcher() { return stringContains; } public void testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() { assertTrue("should be true if excerpt at beginning", stringContains.matches(EXCERPT + "END")); assertTrue("should be true if excerpt at end", stringContains.matches("START" + EXCERPT)); assertTrue("should be true if excerpt in middle", stringContains.matches("START" + EXCERPT + "END")); assertTrue("should be true if excerpt is repeated", stringContains.matches(EXCERPT + EXCERPT)); assertFalse("should not be true if excerpt is not in string", stringContains.matches("Something else")); assertFalse("should not be true if part of excerpt is in string", stringContains.matches(EXCERPT.substring(1))); } public void testEvaluatesToTrueIfArgumentIsEqualToSubstring() { assertTrue("should be true if excerpt is entire string", stringContains.matches(EXCERPT)); } public void testHasAReadableDescription() { assertDescription("a string containing \"EXCERPT\"", stringContains); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/StringEndsWithTest.java0000644000175000017500000000316711111332021032634 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.text; import static org.hamcrest.core.StringEndsWith.endsWith; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class StringEndsWithTest extends AbstractMatcherTest { static final String EXCERPT = "EXCERPT"; Matcher stringEndsWith = endsWith(EXCERPT); @Override protected Matcher createMatcher() { return stringEndsWith; } public void testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() { assertFalse("should be false if excerpt at beginning", stringEndsWith.matches(EXCERPT + "END")); assertTrue("should be true if excerpt at end", stringEndsWith.matches("START" + EXCERPT)); assertFalse("should be false if excerpt in middle", stringEndsWith.matches("START" + EXCERPT + "END")); assertTrue("should be true if excerpt is at end and repeated", stringEndsWith.matches(EXCERPT + EXCERPT)); assertFalse("should be false if excerpt is not in string", stringEndsWith.matches("Something else")); assertFalse("should be false if part of excerpt is at end of string", stringEndsWith.matches(EXCERPT.substring(0, EXCERPT.length() - 2))); } public void testEvaluatesToTrueIfArgumentIsEqualToSubstring() { assertTrue("should be true if excerpt is entire string", stringEndsWith.matches(EXCERPT)); } public void testHasAReadableDescription() { assertDescription("a string ending with \"EXCERPT\"", stringEndsWith); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/text/StringStartsWithTest.java0000644000175000017500000000320711111332021033216 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest.text; import static org.hamcrest.core.StringStartsWith.startsWith; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; public class StringStartsWithTest extends AbstractMatcherTest { static final String EXCERPT = "EXCERPT"; Matcher stringStartsWith = startsWith(EXCERPT); @Override protected Matcher createMatcher() { return stringStartsWith; } public void testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() { assertTrue("should be true if excerpt at beginning", stringStartsWith.matches(EXCERPT + "END")); assertFalse("should be false if excerpt at end", stringStartsWith.matches("START" + EXCERPT)); assertFalse("should be false if excerpt in middle", stringStartsWith.matches("START" + EXCERPT + "END")); assertTrue("should be true if excerpt is at beginning and repeated", stringStartsWith.matches(EXCERPT + EXCERPT)); assertFalse("should be false if excerpt is not in string", stringStartsWith.matches("Something else")); assertFalse("should be false if part of excerpt is at start of string", stringStartsWith.matches(EXCERPT.substring(1))); } public void testEvaluatesToTrueIfArgumentIsEqualToSubstring() { assertTrue("should be true if excerpt is entire string", stringStartsWith.matches(EXCERPT)); } public void testHasAReadableDescription() { assertDescription("a string starting with \"EXCERPT\"", stringStartsWith); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/xml/0000755000175000017500000000000011675175275026061 5ustar moellermoellerlibhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/xml/HasXPathTest.java0000644000175000017500000001175611111346152031231 0ustar moellermoellerpackage org.hamcrest.xml; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.StringContains.containsString; import static org.hamcrest.xml.HasXPath.hasXPath; import java.io.ByteArrayInputStream; import java.util.HashSet; import java.util.Iterator; import javax.xml.namespace.NamespaceContext; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import org.w3c.dom.Document; /** * @author Joe Walnes */ public class HasXPathTest extends AbstractMatcherTest { private Document xml; private NamespaceContext ns; @Override protected void setUp() throws Exception { super.setUp(); xml = parse("" + "\n" + " Edam\n" + " Cheddar\n" + " Caravane\n" + " \n" + " " + "\n" ); ns = new NamespaceContext() { public String getNamespaceURI(String prefix) { return ("cheese".equals(prefix) ? "http://cheese.com" : null); } public String getPrefix(String namespaceURI) { return ("http://cheese.com".equals(namespaceURI) ? "cheese" : null); } public Iterator getPrefixes(String namespaceURI) { HashSet prefixes = new HashSet(); String prefix = getPrefix(namespaceURI); if (prefix != null) { prefixes.add(prefix); } return prefixes.iterator(); } }; } @Override protected Matcher createMatcher() { return hasXPath("//irrelevant"); } public void testAppliesMatcherToXPathInDocument() throws Exception { assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar"))); assertThat(xml, hasXPath("//something[1]/cheese", containsString("dam"))); assertThat(xml, hasXPath("//something[2]/cheese", not(containsString("dam")))); assertThat(xml, hasXPath("/root/@type", equalTo("food"))); assertThat(xml, hasXPath("//something[@id='b']/cheese", equalTo("Cheddar"))); assertThat(xml, hasXPath("//something[@id='b']/cheese")); } public void testMatchesEmptyElement() throws Exception { assertThat(xml, hasXPath("//emptySomething")); } public void testMatchesEmptyElementInNamespace() throws Exception { assertThat(xml, hasXPath("//cheese:emptySomething", ns)); } public void testFailsIfNodeIsMissing() throws Exception { assertThat(xml, not(hasXPath("/root/something[3]/cheese", ns, equalTo("Cheddar")))); assertThat(xml, not(hasXPath("//something[@id='c']/cheese", ns))); } public void testFailsIfNodeIsMissingInNamespace() throws Exception { assertThat(xml, not(hasXPath("//cheese:foreignSomething", equalTo("Badger")))); assertThat(xml, not(hasXPath("//cheese:foreignSomething"))); } public void testMatchesWithNamespace() throws Exception { assertThat(xml, hasXPath("//cheese:foreignSomething", ns)); assertThat(xml, hasXPath("//cheese:foreignSomething/@milk", ns, equalTo("camel"))); assertThat(xml, hasXPath("//cheese:foreignSomething/text()", ns, equalTo("Caravane"))); } public void testThrowsIllegalArgumentExceptionIfGivenIllegalExpression() { try { hasXPath("\\g:dfgd::DSgf/root/something[2]/cheese", equalTo("blah")); fail("Expected exception"); } catch (IllegalArgumentException expectedException) { // expected exception } } public void testDescribesItself() throws Exception { assertDescription("an XML document with XPath /some/path \"Cheddar\"", hasXPath("/some/path", equalTo("Cheddar"))); assertDescription("an XML document with XPath /some/path", hasXPath("/some/path")); } public void testDescribesMissingNodeMismatch() { assertMismatchDescription("xpath returned no results.", hasXPath("//honky"), xml); } public void testDescribesIncorrectNodeValueMismatch() { assertMismatchDescription("xpath result was \"Edam\"", hasXPath("//something[1]/cheese", equalTo("parmesan")), xml); } private static Document parse(String xml) throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder.parse(new ByteArrayInputStream(xml.getBytes())); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/AbstractMatcherTest.java0000644000175000017500000000333711121264160032013 0ustar moellermoeller/* Copyright (c) 2000-2006 hamcrest.org */ package org.hamcrest; import junit.framework.TestCase; public abstract class AbstractMatcherTest extends TestCase { /** * Create an instance of the Matcher so some generic safety-net tests can be run on it. */ protected abstract Matcher createMatcher(); protected static final Object ARGUMENT_IGNORED = new Object(); protected static final Object ANY_NON_NULL_ARGUMENT = new Object(); public static void assertMatches(String message, Matcher c, T arg) { assertTrue(message, c.matches(arg)); } public static void assertDoesNotMatch(String message, Matcher c, T arg) { assertFalse(message, c.matches(arg)); } public static void assertDescription(String expected, Matcher matcher) { Description description = new StringDescription(); description.appendDescriptionOf(matcher); assertEquals("Expected description", expected, description.toString()); } public static void assertMismatchDescription(String expected, Matcher matcher, T arg) { Description description = new StringDescription(); assertFalse("Precondtion: Matcher should not match item.", matcher.matches(arg)); matcher.describeMismatch(arg, description); assertEquals("Expected mismatch description", expected, description.toString()); } public void testIsNullSafe() { // should not throw a NullPointerException createMatcher().matches(null); } public void testCopesWithUnknownTypes() { // should not throw ClassCastException createMatcher().matches(new UnknownType()); } public static class UnknownType { } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/BaseMatcherTest.java0000644000175000017500000000110011033250113031077 0ustar moellermoellerpackage org.hamcrest; import junit.framework.TestCase; public class BaseMatcherTest extends TestCase { public void testDescribesItselfWithToStringMethod() { Matcher someMatcher = new BaseMatcher() { public boolean matches(Object item) { throw new UnsupportedOperationException(); } public void describeTo(Description description) { description.appendText("SOME DESCRIPTION"); } }; assertEquals("SOME DESCRIPTION", someMatcher.toString()); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/CustomMatcherTest.java0000644000175000017500000000077211044676453031542 0ustar moellermoellerpackage org.hamcrest; import static org.hamcrest.AbstractMatcherTest.assertDescription; import junit.framework.TestCase; public class CustomMatcherTest extends TestCase { public void testUsesStaticDescription() throws Exception { Matcher matcher = new CustomMatcher("I match strings") { public boolean matches(Object item) { return (item instanceof String); } }; assertDescription("I match strings", matcher); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/CustomTypeSafeMatcherTest.java0000644000175000017500000000200711121050074033151 0ustar moellermoellerpackage org.hamcrest; public class CustomTypeSafeMatcherTest extends AbstractMatcherTest { private static final String STATIC_DESCRIPTION = "I match non empty strings"; private Matcher customMatcher; @Override protected void setUp() throws Exception { customMatcher = new CustomTypeSafeMatcher(STATIC_DESCRIPTION) { @Override public boolean matchesSafely(String item) { return false; } @Override public void describeMismatchSafely(String item, Description mismatchDescription) { mismatchDescription.appendText("an " + item); } }; } public void testUsesStaticDescription() throws Exception { assertDescription(STATIC_DESCRIPTION, customMatcher); } public void testReportsMismatch() { assertMismatchDescription("an item", customMatcher, "item"); } @Override protected Matcher createMatcher() { return customMatcher; } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/FeatureMatcherTest.java0000644000175000017500000000403611175026464031654 0ustar moellermoellerpackage org.hamcrest; import static org.hamcrest.AbstractMatcherTest.assertDescription; import static org.hamcrest.AbstractMatcherTest.assertMatches; import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription; import junit.framework.TestCase; import org.hamcrest.core.IsEqual; public class FeatureMatcherTest extends TestCase { private final FeatureMatcher resultMatcher = resultMatcher(); public void testMatchesPartOfAnObject() { assertMatches("feature", resultMatcher, new Thingy("bar")); assertDescription("Thingy with result \"bar\"", resultMatcher); } public void testMismatchesPartOfAnObject() { assertMismatchDescription("result mismatch-description", resultMatcher, new Thingy("foo")); } public void testDoesNotThrowNullPointerException() { assertMismatchDescription("was null", resultMatcher, null); } public void testDoesNotThrowClassCastException() { resultMatcher.matches(new ShouldNotMatch()); StringDescription mismatchDescription = new StringDescription(); resultMatcher.describeMismatch(new ShouldNotMatch(), mismatchDescription); assertEquals("was ", mismatchDescription.toString()); } public static class Match extends IsEqual { public Match(String equalArg) { super(equalArg); } @Override public void describeMismatch(Object item, Description description) { description.appendText("mismatch-description"); } } public static class Thingy { private final String result; public Thingy(String result) { this.result = result; } public String getResult() { return result; } } public static class ShouldNotMatch { @Override public String toString() { return "ShouldNotMatch"; } } private static FeatureMatcher resultMatcher() { return new FeatureMatcher(new Match("bar"), "Thingy with result", "result") { @Override public String featureValueOf(Thingy actual) { return actual.getResult(); } }; } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/JavaLangMatcherAssertTest.java0000644000175000017500000000077111075717154033132 0ustar moellermoellerpackage org.hamcrest; import static org.hamcrest.JavaLangMatcherAssert.that; import static org.hamcrest.core.StringStartsWith.startsWith; import junit.framework.TestCase; public class JavaLangMatcherAssertTest extends TestCase { public void testWouldCauseFailingAssertion() throws Exception { assertEquals(false, that("Foo", startsWith("Bar"))); } public void testWouldCausePassingAssertion() throws Exception { assertEquals(true, that("Foo", startsWith("F"))); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/MatcherAssertTest.java0000644000175000017500000000505011112760270031506 0ustar moellermoellerpackage org.hamcrest; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import junit.framework.TestCase; public class MatcherAssertTest extends TestCase { public void testIncludesDescriptionOfTestedValueInErrorMessage() { String expected = "expected"; String actual = "actual"; String expectedMessage = "identifier\nExpected: \"expected\"\n but: was \"actual\""; try { assertThat("identifier", actual, equalTo(expected)); } catch (AssertionError e) { assertTrue(e.getMessage().startsWith(expectedMessage)); return; } fail("should have failed"); } public void testDescriptionCanBeElided() { String expected = "expected"; String actual = "actual"; String expectedMessage = "\nExpected: \"expected\"\n but: was \"actual\""; try { assertThat(actual, equalTo(expected)); } catch (AssertionError e) { assertTrue(e.getMessage().startsWith(expectedMessage)); return; } fail("should have failed"); } public void testCanTestBooleanDirectly() { assertThat("success reason message", true); try { assertThat("failing reason message", false); } catch (AssertionError e) { assertEquals("failing reason message", e.getMessage()); return; } fail("should have failed"); } public void testIncludesMismatchDescription() { Matcher matcherWithCustomMismatchDescription = new BaseMatcher() { public boolean matches(Object item) { return false; } public void describeTo(Description description) { description.appendText("Something cool"); } @Override public void describeMismatch(Object item, Description mismatchDescription) { mismatchDescription.appendText("Not cool"); } }; String expectedMessage = "\nExpected: Something cool\n but: Not cool"; try { assertThat("Value", matcherWithCustomMismatchDescription); fail("should have failed"); } catch (AssertionError e) { assertEquals(expectedMessage, e.getMessage()); } } public void testCanAssertSubtypes() { Integer aSub = new Integer(1); Number aSuper = aSub; assertThat(aSub, equalTo(aSuper)); } } libhamcrest-java-1.2/hamcrest-unit-test/src/main/java/org/hamcrest/TypeSafeMatcherTest.java0000644000175000017500000000246311202570227031773 0ustar moellermoellerpackage org.hamcrest; import junit.framework.TestCase; public class TypeSafeMatcherTest extends TestCase { private final Matcher matcher = new TypeSafeMatcherSubclass(); public static class TypeSafeMatcherSubclass extends TypeSafeMatcher { @Override public boolean matchesSafely(String item) { return false; } @Override public void describeMismatchSafely(String item, Description mismatchDescription) { mismatchDescription.appendText("The mismatch"); } public void describeTo(Description description) { } } public void testCanDetermineMatcherTypeFromProtectedMatchesSafelyMethod() { assertFalse(matcher.matches(null)); assertFalse(matcher.matches(10)); } public void testDescribesMismatches() { assertMismatchDescription("was null", null); assertMismatchDescription("was a java.lang.Integer (<3>)", new Integer(3)); assertMismatchDescription("The mismatch", "a string"); } private void assertMismatchDescription(String expectedDescription, Object actual) { StringDescription description = new StringDescription(); matcher.describeMismatch(actual, description); assertEquals(expectedDescription, description.toString()); } } libhamcrest-java-1.2/lib/0000755000175000017500000000000011107220351015206 5ustar moellermoellerlibhamcrest-java-1.2/BUILDING.txt0000644000175000017500000000360110632277510016411 0ustar moellermoeller ********************** ********************* Building Hamcrest ********************* ********************** --[ Build requirements ]------------------------------------- * JDK 1.5 Note: that this is a buildtime dependency for 1.5 specific features. However the final built jars should run on 1.4 and 1.3 JVMs with some features unavailable. * Ant 1.6 or greater To enable testing support, ensure junit.jar exists in ANT_HOME/lib. --[ Building from the command line ]------------------------- Execute the default ant target: ant This will do a full clean build, run all tests and (if successful) package up a distribution. The resulting builds reside in the 'build' directory. For a list of finer grained build operations: ant -projecthelp The default version number used in the build is 'SNAPSHOT'. To override this, you can pass a property to ant: ant -Dversion=MY.OTHER.VERSION --[ Building from the IDE ]---------------------------------- It is possible to compile and test the source directly from popular IDEs, without resorting to the command line. Steps: - Run 'ant library'. This generates additional Java coded necessary to compile. - Create a new project. - Add the following directories as source directories: hamcrest-core/src/main/java hamcrest-library/src/main/java hamcrest-generator/src/main/java hamcrest-integration/src/main/java build/temp/hamcrest-core/generated-code build/temp/hamcrest-library/generated-code - Add hamcrest-unit-test/src/main/java as a test directory. If this is unsupported by the IDE, add it as another source directory. - Include all jars in the lib directory in the classpath. - Compile as usual in the IDE. - If supported, run all tests under org.hamcrest from the IDEs JUnit runner. libhamcrest-java-1.2/CHANGES.txt0000644000175000017500000000444611123257210016263 0ustar moellermoeller== Version 1.3: RC3 == * Added FeatureMatcher * distinguish between instanceOf() and any() == Version 1.2: RC2 == * Added mismatch reporting * Added WithSamePropertyValuesAs matcher * Moved any() from IsAnything to IsInstanceOf. It now checks the type of the matched object * Moved MatcherAssert from integration to core * Tightened up generics. * Added IsMapContainingKey and IsMapContainingValue matchers to resolve a generics bug in hasKey and hasValue static factories previously declared in IsMapContaining (ngd) * Added IsCollectionOnlyContaining and IsArrayOnlyContaining which matches collections (and arrays) where all match a given matcher. E.g onlyContains(3,4,5) or onlyContains(lessThan(9)) * text module moved to separate project, hamcrest-text-patterns * added more colection matchers: xContainingInAnyOrder, xContainingInOrder, xWithSize * new text Matcher: IsEmptyString * hamcrest generator uses method return type == Version 1.1: Released Jun 30 2007 == * Hamcrest Generator now includes JavaDoc and parameter names in generated code by using QDox to parse the source code. * Created hamcrest-core.jar (and removed hamcrest-api.jar). Moved core set of matchers (and, eq, not, etc) to this package to make it more practical for external libraries to embed Hamcrest. * Created CoreMatchers (static import sugar) in hamcrest-core.jar. * StringBuilder can use any Appendable (not just StringBuffer). * Added sensible toString() method to BaseMatcher. * Created StringDescription.asString() alias (because toString() caused issues with static imports). * Relaxed isInstanceOf() matcher generic type so it can be used on any kind of object. e.g. assertThat(someUnknownObject, isInstanceOf(String.class)); * Added any(Class), null(Class) and notNull(Class) matchers, which returns Matcher. Helpful when the compiler struggles with type inference. * Modified anyOf() and allOf() to accept mixed-types. * TypeSafeMatcher.matchesSafely() is now public. * Generator recognizes @Factory methods that return subclass of Matcher. (Fix by David Saff) == Version 1.0: Released Dec 15 2006 == Initial release. * Support for namespaces in HasXPath * Bug fix for matching empty elements with HasXPath libhamcrest-java-1.2/LICENSE.txt0000644000175000017500000000274510632277407016313 0ustar moellermoellerBSD License Copyright (c) 2000-2006, www.hamcrest.org All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Hamcrest nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. libhamcrest-java-1.2/README.txt0000644000175000017500000000470111107220352016141 0ustar moellermoeller ************ ************************* Hamcrest ************************* ************ --[ What is Hamcrest? ]------------------------------------- Hamcrest is a library of matchers, which can be combined in to create flexible expressions of intent in tests. --[ Binaries ]----------------------------------------------- Depending on how you intend to use Hamcrest, you should use different Jars. * [hamcrest-core.jar] This is the core API to be used by third-party framework providers. This includes the a foundation set of matcher implementations for common operations. This API is stable and will rarely change. You will need this library as a minimum. * [hamcrest-library.jar] The ever-growing library of Matcher implementations. This will grow between releases. * [hamcrest-generator.jar] A tool to allow many Matcher implementations to be combined into a single class so users don't have to remember many classes/packages to import. Generates code. * [hamcrest-integration.jar] Provides integration between Hamcrest and other testing tools, including JUnit (3 and 4), TestNG, jMock and EasyMock. Alternatively, if you don't care: * [hamcrest-all.jar] Includes all of the above. For convenience, all the Jars also include source code. --[ Dependencies ]------------------------------------------- All libraries in the 'lib' directory are used at build time, or are optional extras used for tighter integration with third party libraries. ALL OF THE DEPENDENCIES ARE OPTIONAL. --[ Documentation ]------------------------------------------ Documentation can be found at: http://hamcrest.org/ --[ Source ]------------------------------------------------- The complete source for Hamcrest is bundled. This includes: * Matcher core classes [src/core] * Matcher libary [src/library] * Matcher integrations [src/integration] * Syntactic sugar generator [src/generator] * Unit tests [src/unit-test] * Ant build file [build.xml] * Dependencies [lib] To build, please read BUILDING.txt ------------------------------------------------------------- Developers: - Joe Walnes - Nat Pryce - Steve Freeman Contributors: - Robert Chatley - Tom White - Neil Dunn - Dan North - Magne Rasmussen - David Saff Also, thanks to everyone who has worked on DynaMock, nMock, jMock, EasyMock and MiniMock! These libraries inspired Hamcrest. libhamcrest-java-1.2/build.xml0000644000175000017500000002620711107653773016312 0ustar moellermoeller libhamcrest-java-1.2/core-matchers.xml0000644000175000017500000000154711107220350017724 0ustar moellermoeller libhamcrest-java-1.2/matchers.xml0000644000175000017500000000513111130363115016772 0ustar moellermoeller