Skip to content

Commit 9ac3e36

Browse files
author
nat.pryce
committed
Fixed test so it doesn't matter if assertions are enabled or not
1 parent a856cf7 commit 9ac3e36

1 file changed

Lines changed: 5 additions & 19 deletions

File tree

‎hamcrest-unit-test/src/main/java/org/hamcrest/JavaLangMatcherAssertTest.java‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,11 @@
55
import junit.framework.TestCase;
66

77
public class JavaLangMatcherAssertTest extends TestCase {
8-
static boolean assertsEnabled = false;
9-
static {
10-
assert (assertsEnabled = true); // Intentional side-effect!!!
8+
public void testWouldCauseFailingAssertion() throws Exception {
9+
assertEquals(false, that("Foo", startsWith("Bar")));
1110
}
12-
13-
public void testFailingAssertion() throws Exception {
14-
boolean thrown = false;
15-
try {
16-
assert that("Foo", startsWith("Bar"));
17-
// Can't fail() here since catch block will catch JUnit exception.
18-
} catch (AssertionError expected) {
19-
thrown = true;
20-
}
21-
if (assertsEnabled && ! thrown) {
22-
fail();
23-
}
24-
}
25-
26-
public void testPassingAssertion() throws Exception {
27-
assert that("Foo", startsWith("F"));
11+
12+
public void testWouldCausePassingAssertion() throws Exception {
13+
assertEquals(true, that("Foo", startsWith("F")));
2814
}
2915
}

0 commit comments

Comments
 (0)