[481] | 1 | package testcode;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
[501] | 4 | import static org.junit.Assert.assertTrue;
|
---|
[481] | 5 |
|
---|
[939] | 6 | /**
|
---|
| 7 | * This test is a bit weird/old school, it's not a junit test in java, but just
|
---|
| 8 | * assumes someone calls main function. The tests print ok if test succeeded
|
---|
| 9 | * This mechanism should be used only in core as there is no @Test available
|
---|
| 10 | * there.
|
---|
| 11 | *
|
---|
| 12 | */
|
---|
[481] | 13 | public class AssertTest {
|
---|
| 14 |
|
---|
| 15 | public AssertTest() {
|
---|
| 16 | test1();
|
---|
| 17 | test2();
|
---|
[501] | 18 | testAssertTrue();
|
---|
[1219] | 19 | test3argversions();
|
---|
[481] | 20 | }
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * The test code for Value
|
---|
| 24 | *
|
---|
| 25 | * @throws Exception
|
---|
| 26 | */
|
---|
| 27 | public static void main(String[] args) throws Exception {
|
---|
| 28 | new AssertTest();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public static void test1() {
|
---|
| 32 | assertEquals(1, 1);
|
---|
| 33 | System.out.println("1ok");
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public static void test2() {
|
---|
| 37 | try {
|
---|
| 38 | assertEquals("not equal", 1, 2);
|
---|
| 39 | System.out.println("Test did not fail properly");
|
---|
| 40 | return;
|
---|
| 41 | } catch (AssertionError e) {
|
---|
| 42 | if (!e.getMessage().contains("not equal")) {
|
---|
| 43 | System.out.println(
|
---|
| 44 | "Test threw as expected but message does not contain 'not equal'");
|
---|
| 45 | return;
|
---|
| 46 | }
|
---|
| 47 | System.out.println("2ok");
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
[501] | 50 |
|
---|
| 51 | public static void testAssertTrue() {
|
---|
| 52 | try {
|
---|
| 53 | assertTrue("not true", false);
|
---|
| 54 | System.out.println("3ko");
|
---|
| 55 | } catch (AssertionError e) {
|
---|
| 56 | if (!e.getMessage().contains("not true"))
|
---|
| 57 | System.out.println("3missing message");
|
---|
| 58 | else
|
---|
| 59 | System.out.println("3ok");
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
[1219] | 62 |
|
---|
| 63 | public static void test3argversions() {
|
---|
| 64 | assertEquals("niet gelijk", 0, 0); // message
|
---|
| 65 | assertEquals(1.0d, 1.1d, 0.11d); // tolerance
|
---|
| 66 | assertEquals(1.0d, 0.9d, 0.11d); // tolerance
|
---|
| 67 | System.out.println("4ok");
|
---|
| 68 | }
|
---|
[481] | 69 | } |
---|