source: java2python/junit-t/assert/testcode/AssertTest.java@ 1282

Last change on this file since 1282 was 1243, checked in by wouter, 2 months ago

#390 fix copy/paste error

File size: 1.5 KB
RevLine 
[481]1package testcode;
2
3import static org.junit.Assert.assertEquals;
[501]4import 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]13public class AssertTest {
14
15 public AssertTest() {
16 test1();
17 test2();
[501]18 testAssertTrue();
[1219]19 test3argversions();
[481]20 }
21
22 /**
[1243]23 * The test code
[481]24 */
25 public static void main(String[] args) throws Exception {
26 new AssertTest();
27 }
28
29 public static void test1() {
30 assertEquals(1, 1);
31 System.out.println("1ok");
32 }
33
34 public static void test2() {
35 try {
36 assertEquals("not equal", 1, 2);
[1243]37 System.out.println("Test2 did not fail properly");
[481]38 return;
39 } catch (AssertionError e) {
40 if (!e.getMessage().contains("not equal")) {
41 System.out.println(
42 "Test threw as expected but message does not contain 'not equal'");
43 return;
44 }
45 System.out.println("2ok");
46 }
47 }
[501]48
49 public static void testAssertTrue() {
50 try {
51 assertTrue("not true", false);
52 System.out.println("3ko");
53 } catch (AssertionError e) {
54 if (!e.getMessage().contains("not true"))
55 System.out.println("3missing message");
56 else
57 System.out.println("3ok");
58 }
59 }
[1219]60
61 public static void test3argversions() {
62 assertEquals("niet gelijk", 0, 0); // message
63 assertEquals(1.0d, 1.1d, 0.11d); // tolerance
64 assertEquals(1.0d, 0.9d, 0.11d); // tolerance
65 System.out.println("4ok");
66 }
[481]67}
Note: See TracBrowser for help on using the repository browser.