Skip to content

Commit a856cf7

Browse files
author
smgfreeman
committed
probable fix for asserts test. Can't test on a Mac.
1 parent 6e77d9c commit a856cf7

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
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!!!
11+
}
812

913
public void testFailingAssertion() throws Exception {
10-
boolean thrown;
14+
boolean thrown = false;
1115
try {
1216
assert that("Foo", startsWith("Bar"));
1317
// Can't fail() here since catch block will catch JUnit exception.
14-
thrown = false;
1518
} catch (AssertionError expected) {
1619
thrown = true;
1720
}
18-
if (thrown) {
21+
if (assertsEnabled && ! thrown) {
1922
fail();
2023
}
2124
}
2225

2326
public void testPassingAssertion() throws Exception {
24-
assert that("Foo", startsWith("Far"));
27+
assert that("Foo", startsWith("F"));
2528
}
2629
}

0 commit comments

Comments
 (0)