package testcode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * This test is a bit weird/old school, it's not a junit test in java, but just * assumes someone calls main function. The tests print ok if test succeeded * This mechanism should be used only in core as there is no @Test available * there. * */ public class AssertTest { public AssertTest() { test1(); test2(); testAssertTrue(); test3argversions(); } /** * The test code */ public static void main(String[] args) throws Exception { new AssertTest(); } public static void test1() { assertEquals(1, 1); System.out.println("1ok"); } public static void test2() { try { assertEquals("not equal", 1, 2); System.out.println("Test2 did not fail properly"); return; } catch (AssertionError e) { if (!e.getMessage().contains("not equal")) { System.out.println( "Test threw as expected but message does not contain 'not equal'"); return; } System.out.println("2ok"); } } public static void testAssertTrue() { try { assertTrue("not true", false); System.out.println("3ko"); } catch (AssertionError e) { if (!e.getMessage().contains("not true")) System.out.println("3missing message"); else System.out.println("3ok"); } } public static void test3argversions() { assertEquals("niet gelijk", 0, 0); // message assertEquals(1.0d, 1.1d, 0.11d); // tolerance assertEquals(1.0d, 0.9d, 0.11d); // tolerance System.out.println("4ok"); } }