Skip to content

Commit 633ab42

Browse files
committed
added link to hamcrest extensions
2 parents 872b4e7 + 96e113d commit 633ab42

14 files changed

Lines changed: 503 additions & 282 deletions

File tree

‎.idea/workspace.xml‎

Lines changed: 72 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
[![][logo]][website]
2+
Java Hamcrest
3+
=============
4+
Licensed under [BSD License][].
5+
6+
What is Hamcrest?
7+
-----------------
8+
Hamcrest is a library of matchers, which can be combined in to create flexible expressions of intent in tests.
9+
10+
Downloads
11+
---------
12+
You can obtain Hamcrest binaries from [maven central][], or from [google code downloads][].
13+
14+
Binaries
15+
--------
16+
Depending on how you intend to use Hamcrest, you should use different Jars.
17+
18+
* __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.
19+
* __hamcrest-library.jar__ -- The ever-growing library of Matcher implementations. This will grow between releases.
20+
* __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.
21+
* __hamcrest-integration.jar__ -- Provides integration between Hamcrest and other testing tools, including JUnit (3 and 4), TestNG, jMock and EasyMock.
22+
23+
Alternatively, if you don't care:
24+
25+
* __hamcrest-all.jar__ -- Includes all of the above.
26+
27+
Sources and JavaDoc jars are available for all of the above.
28+
29+
Extensions
30+
----------
31+
32+
For Hamcrest extension projects see [hamcrest extensions][this list].
33+
34+
Dependencies
35+
------------
36+
All libraries in the `lib` directory are used at build time, or are optional extras used for tighter integration with third party libraries.
37+
38+
ALL OF THE DEPENDENCIES ARE OPTIONAL.
39+
40+
Documentation
41+
-------------
42+
Documentation can be found on the [google code wiki][].
43+
44+
Source
45+
------
46+
The complete source for Hamcrest is bundled. This includes:
47+
* Matcher core classes [src/core]
48+
* Matcher library [src/library]
49+
* Matcher integrations [src/integration]
50+
* Syntactic sugar generator [src/generator]
51+
* Unit tests [src/unit-test]
52+
* Ant build file [build.xml]
53+
* Dependencies [lib]
54+
55+
To build, please read BUILDING.txt
56+
57+
Acknowledgements
58+
----------------
59+
Developers:
60+
* Joe Walnes
61+
* Nat Pryce
62+
* Steve Freeman
63+
64+
Contributors:
65+
* Robert Chatley
66+
* Tom White
67+
* Neil Dunn
68+
* Dan North
69+
* Magne Rasmussen
70+
* David Saff
71+
* Tom Denley
72+
73+
Also, thanks to everyone who has worked on DynaMock, nMock, jMock, EasyMock and MiniMock! These libraries inspired Hamcrest.
74+
75+
76+
[logo]: https://raw.github.com/hamcrest/JavaHamcrest/master/doc/images/logo.jpg
77+
[website]: http://code.google.com/p/hamcrest
78+
[BSD License]: http://opensource.org/licenses/BSD-3-Clause
79+
[Maven central]: http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.hamcrest
80+
[google code downloads]: http://code.google.com/p/hamcrest/downloads/list?can=2&q=label%3AJava
81+
[google code wiki]: http://code.google.com/p/hamcrest/wiki/Tutorial
82+
[hamcrest extensions]: https://github.com/hamcrest/JavaHamcrest/wiki/Related-Projects

‎README.txt‎

Lines changed: 0 additions & 97 deletions
This file was deleted.

‎doc/images/logo.jpg‎

8.26 KB
Loading

‎hamcrest-core/src/main/java/org/hamcrest/core/Is.java‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,6 @@ public static <T> Matcher<T> is(T value) {
6666
return is(equalTo(value));
6767
}
6868

69-
/**
70-
* A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.
71-
* <p/>
72-
* For example:
73-
* <pre>assertThat(cheese, is(Cheddar.class))</pre>
74-
* instead of:
75-
* <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>
76-
*
77-
* @deprecated use isA(Class<T> type) instead.
78-
*/
79-
@Factory
80-
@Deprecated
81-
public static <T> Matcher<T> is(Class<T> type) {
82-
final Matcher<T> typeMatcher = instanceOf(type);
83-
return is(typeMatcher);
84-
}
85-
8669
/**
8770
* A shortcut to the frequently used <code>is(instanceOf(SomeClass.class))</code>.
8871
* <p/>

‎hamcrest-core/src/main/java/org/hamcrest/core/IsCollectionContaining.java‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,31 @@ public IsCollectionContaining(Matcher<? super T> elementMatcher) {
2020

2121
@Override
2222
protected boolean matchesSafely(Iterable<? super T> collection, Description mismatchDescription) {
23-
boolean isPastFirst = false;
23+
boolean empty = true;
2424
for (Object item : collection) {
25-
if (elementMatcher.matches(item)){
25+
empty = false;
26+
if (elementMatcher.matches(item)) {
2627
return true;
2728
}
29+
}
30+
31+
if (empty) {
32+
mismatchDescription.appendText("was an empty collection");
33+
return false;
34+
}
35+
36+
mismatchDescription.appendText("was a collection that did not contain ")
37+
.appendDescriptionOf(elementMatcher)
38+
.appendText(" -- mismatches were: [");
39+
boolean isPastFirst = false;
40+
for (Object item : collection) {
2841
if (isPastFirst) {
2942
mismatchDescription.appendText(", ");
3043
}
3144
elementMatcher.describeMismatch(item, mismatchDescription);
3245
isPastFirst = true;
3346
}
47+
mismatchDescription.appendText("]");
3448
return false;
3549
}
3650

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsArray.java‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ public boolean matchesSafely(T[] array) {
3131

3232
@Override
3333
public void describeMismatchSafely(T[] actual, Description mismatchDescription) {
34-
if (actual.length != elementMatchers.length) {
35-
mismatchDescription.appendText("array length was " + actual.length);
36-
return;
37-
}
38-
for (int i = 0; i < actual.length; i++) {
39-
if (!elementMatchers[i].matches(actual[i])) {
40-
mismatchDescription.appendText("element " + i + " was ").appendValue(actual[i]);
41-
return;
34+
if (actual.length != elementMatchers.length) {
35+
mismatchDescription.appendText("array length was ").appendValue(actual.length);
36+
return;
37+
}
38+
for (int i = 0; i < actual.length; i++) {
39+
if (!elementMatchers[i].matches(actual[i])) {
40+
mismatchDescription.appendText("element ").appendValue(i).appendText(" ");
41+
elementMatchers[i].describeMismatch(actual[i], mismatchDescription);
42+
return;
43+
}
4244
}
43-
}
4445
}
4546

4647
@Override

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrder.java‎

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package org.hamcrest.collection;
22

3-
import org.hamcrest.Description;
4-
import org.hamcrest.Factory;
5-
import org.hamcrest.Matcher;
6-
import org.hamcrest.TypeSafeDiagnosingMatcher;
7-
83
import java.util.ArrayList;
94
import java.util.Arrays;
105
import java.util.Collection;
116
import java.util.List;
127

13-
import static java.util.Arrays.asList;
8+
import org.hamcrest.Description;
9+
import org.hamcrest.Factory;
10+
import org.hamcrest.Matcher;
11+
import org.hamcrest.TypeSafeDiagnosingMatcher;
12+
1413
import static org.hamcrest.core.IsEqual.equalTo;
1514

1615
public class IsIterableContainingInAnyOrder<T> extends TypeSafeDiagnosingMatcher<Iterable<? extends T>> {
@@ -80,28 +79,6 @@ private boolean isMatched(S item) {
8079
mismatchDescription.appendText("Not matched: ").appendValue(item);
8180
return false;
8281
}
83-
84-
}
85-
86-
/**
87-
* Creates a matcher for {@link Iterable}s that matches when a single pass over the
88-
* examined {@link Iterable} yields a single item that satisfies the specified matcher.
89-
* For a positive match, the examined iterable must only yield one item.
90-
* <p/>
91-
* For example:
92-
* <pre>assertThat(Arrays.asList("foo"), containsInAnyOrder(equalTo("foo")))</pre>
93-
*
94-
* @deprecated use contains(Matcher<? super E> itemMatcher) instead
95-
*
96-
* @param itemMatcher
97-
* the matcher that must be satisfied by the single item provided by an
98-
* examined {@link Iterable}
99-
*/
100-
@SuppressWarnings("unchecked")
101-
@Deprecated
102-
@Factory
103-
public static <E> Matcher<Iterable<? extends E>> containsInAnyOrder(final Matcher<? super E> itemMatcher) {
104-
return containsInAnyOrder(new ArrayList<Matcher<? super E>>(asList(itemMatcher)));
10582
}
10683

10784
/**

0 commit comments

Comments
 (0)