1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jci.compilers;
19
20 import junit.framework.TestCase;
21
22 public final class JavacJavaCompilerSettingsTestCase extends TestCase {
23
24 private static void assertEquals(String[] expected, String[] result) {
25 assertEquals(expected.length, result.length);
26
27 for (int i = 0; i < expected.length; i++) {
28 assertEquals("Unexpected value at index " + i, expected[i], result[i]);
29 }
30 }
31
32 public void testDefaultSettings() {
33 final String[] expected = {
34 "-nowarn",
35 "-target", "1.4",
36 "-source", "1.4",
37 "-encoding", "UTF-8"
38 };
39
40 final String[] s = new JavacJavaCompilerSettings().toNativeSettings();
41
42 assertEquals(expected, s);
43 }
44
45 public void testSourceVersion() {
46 final JavacJavaCompilerSettings s = new JavacJavaCompilerSettings();
47 s.setSourceVersion("1.1");
48 assertEquals("1.1", s.toNativeSettings()[4]);
49 s.setSourceVersion("1.2");
50 assertEquals("1.2", s.toNativeSettings()[4]);
51 s.setSourceVersion("1.3");
52 assertEquals("1.3", s.toNativeSettings()[4]);
53 s.setSourceVersion("1.4");
54 assertEquals("1.4", s.toNativeSettings()[4]);
55 s.setSourceVersion("1.5");
56 assertEquals("1.5", s.toNativeSettings()[4]);
57 s.setSourceVersion("1.6");
58 assertEquals("1.6", s.toNativeSettings()[4]);
59 }
60
61 public void testTargetVersion() {
62 final JavacJavaCompilerSettings s = new JavacJavaCompilerSettings();
63 s.setTargetVersion("1.1");
64 assertEquals("1.1", s.toNativeSettings()[2]);
65 s.setTargetVersion("1.2");
66 assertEquals("1.2", s.toNativeSettings()[2]);
67 s.setTargetVersion("1.3");
68 assertEquals("1.3", s.toNativeSettings()[2]);
69 s.setTargetVersion("1.4");
70 assertEquals("1.4", s.toNativeSettings()[2]);
71 s.setTargetVersion("1.5");
72 assertEquals("1.5", s.toNativeSettings()[2]);
73 s.setTargetVersion("1.6");
74 assertEquals("1.6", s.toNativeSettings()[2]);
75 }
76
77 public void testEncoding() {
78 final JavacJavaCompilerSettings s = new JavacJavaCompilerSettings();
79 s.setSourceEncoding("ASCII");
80 assertEquals("ASCII", s.toNativeSettings()[6]);
81 }
82
83 public void testWarnings() {
84 final JavacJavaCompilerSettings s = new JavacJavaCompilerSettings();
85 s.setWarnings(true);
86 assertFalse("-nowarn".equals(s.toNativeSettings()[0]));
87 s.setWarnings(false);
88 assertEquals("-nowarn", s.toNativeSettings()[0]);
89
90 }
91
92 public void testDeprecations() {
93 final JavacJavaCompilerSettings s = new JavacJavaCompilerSettings();
94 s.setDeprecations(true);
95 assertEquals("-deprecation", s.toNativeSettings()[0]);
96 s.setDeprecations(false);
97 assertFalse("-deprecation".equals(s.toNativeSettings()[0]));
98 }
99 }