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
Line 
1package testcode;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5
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 */
13public class AssertTest {
14
15 public AssertTest() {
16 test1();
17 test2();
18 testAssertTrue();
19 test3argversions();
20 }
21
22 /**
23 * The test code
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);
37 System.out.println("Test2 did not fail properly");
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 }
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 }
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 }
67}
Note: See TracBrowser for help on using the repository browser.