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

Last change on this file since 1231 was 1219, checked in by wouter, 6 weeks ago

#368 fix heavy overloaded assertion translation , checking actual types

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 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 }
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 }
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 }
69}
Note: See TracBrowser for help on using the repository browser.