1 | package tudelft.utilities.j2p;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.lang.reflect.InvocationTargetException;
|
---|
7 | import java.lang.reflect.Method;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.Test;
|
---|
12 |
|
---|
13 | import testcode.PrintStreamExample;
|
---|
14 |
|
---|
15 | public 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() throws IOException, ClassNotFoundException {
|
---|
26 | System.out.println("TRANSLATION:");
|
---|
27 | System.out.println(translate(TESTDIR + SOURCECODE));
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void runInPython() throws Exception {
|
---|
32 |
|
---|
33 | List<String> res = runPython(translate(TESTDIR + SOURCECODE),
|
---|
34 | SOURCECODE.replace(".java", ".py"));
|
---|
35 | System.out.println("expected was:");
|
---|
36 | runMain();
|
---|
37 | System.out.println("Actual: " + res);
|
---|
38 | assertEquals(Arrays.asList("He11.0True", "bye"), res);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void runMain() throws NoSuchMethodException, SecurityException,
|
---|
42 | IllegalAccessException, IllegalArgumentException,
|
---|
43 | InvocationTargetException {
|
---|
44 | Method m = mainprogram.getMethod("main", String[].class);
|
---|
45 | String[] params = null;
|
---|
46 | m.invoke(null, (Object) params);
|
---|
47 | }
|
---|
48 | }
|
---|