source: java2python/src/test/java/tudelft/utilities/j2p/t/PrintStreamExampleTest.java@ 391

Last change on this file since 391 was 391, checked in by wouter, 2 years ago

#115 working at translators for annotations

File size: 1.4 KB
Line 
1package tudelft.utilities.j2p.t;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.lang.reflect.InvocationTargetException;
7import java.lang.reflect.Method;
8import java.util.Arrays;
9import java.util.List;
10
11import org.junit.Test;
12
13import testcode.PrintStreamExample;
14
15public class PrintStreamExampleTest extends PyTest {
16
17 private static final Class<PrintStreamExample> mainprogram = PrintStreamExample.class;
18
19 private static final String TESTDIR = "src/test/java/";
20// private static final String FULLNAME = "testcode/PrintStreamExample.java";
21 private static final String SOURCECODE = mainprogram.getCanonicalName()
22 .replaceAll("\\.", "/") + ".java";
23
24 @Test
25 public void test()
26 throws IOException, ClassNotFoundException, TranslationException {
27 System.out.println("TRANSLATION:");
28 System.out.println(translate(TESTDIR + SOURCECODE));
29 }
30
31 @Test
32 public void runInPython() throws Exception {
33
34 List<String> res = runPython(translate(TESTDIR + SOURCECODE),
35 SOURCECODE.replace(".java", ".py"));
36 System.out.println("expected was:");
37 runMain();
38 System.out.println("Actual: " + res);
39 assertEquals(Arrays.asList("He11.0True", "bye"), res);
40 }
41
42 public void runMain() throws NoSuchMethodException, SecurityException,
43 IllegalAccessException, IllegalArgumentException,
44 InvocationTargetException {
45 Method m = mainprogram.getMethod("main", String[].class);
46 String[] params = null;
47 m.invoke(null, (Object) params);
48 }
49}
Note: See TracBrowser for help on using the repository browser.