[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();
|
---|
[481] | 19 | }
|
---|
| 20 |
|
---|
| 21 | /**
|
---|
| 22 | * The test code for Value
|
---|
| 23 | *
|
---|
| 24 | * @throws Exception
|
---|
| 25 | */
|
---|
| 26 | public static void main(String[] args) throws Exception {
|
---|
| 27 | new AssertTest();
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public static void test1() {
|
---|
| 31 | assertEquals(1, 1);
|
---|
| 32 | System.out.println("1ok");
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | public static void test2() {
|
---|
| 36 | try {
|
---|
| 37 | assertEquals("not equal", 1, 2);
|
---|
| 38 | System.out.println("Test did not fail properly");
|
---|
| 39 | return;
|
---|
| 40 | } catch (AssertionError e) {
|
---|
| 41 | if (!e.getMessage().contains("not equal")) {
|
---|
| 42 | System.out.println(
|
---|
| 43 | "Test threw as expected but message does not contain 'not equal'");
|
---|
| 44 | return;
|
---|
| 45 | }
|
---|
| 46 | System.out.println("2ok");
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
[501] | 49 |
|
---|
| 50 | public static void testAssertTrue() {
|
---|
| 51 | try {
|
---|
| 52 | assertTrue("not true", false);
|
---|
| 53 | System.out.println("3ko");
|
---|
| 54 | } catch (AssertionError e) {
|
---|
| 55 | if (!e.getMessage().contains("not true"))
|
---|
| 56 | System.out.println("3missing message");
|
---|
| 57 | else
|
---|
| 58 | System.out.println("3ok");
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
[481] | 61 | } |
---|