View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.jci.compilers;
19  
20  import java.util.Map;
21  
22  import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23  
24  import junit.framework.TestCase;
25  
26  public final class EclipseJavaCompilerSettingsTestCase extends TestCase {
27  
28  	public void testDefaultSettings() {
29  		final Map<String, String> m = new EclipseJavaCompilerSettings().toNativeSettings();
30  		assertEquals(CompilerOptions.DO_NOT_GENERATE, m.get(CompilerOptions.OPTION_SuppressWarnings));
31  		assertEquals(CompilerOptions.DO_NOT_GENERATE, m.get(CompilerOptions.OPTION_ReportDeprecation));
32  		assertEquals(CompilerOptions.VERSION_1_4, m.get(CompilerOptions.OPTION_TargetPlatform));
33  		assertEquals(CompilerOptions.VERSION_1_4, m.get(CompilerOptions.OPTION_Source));
34  		assertEquals("UTF-8", m.get(CompilerOptions.OPTION_Encoding));
35  	}
36  
37  	public void testSourceVersion() {
38  		final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
39  		s.setSourceVersion("1.1");
40  		assertEquals(CompilerOptions.VERSION_1_1, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
41  		s.setSourceVersion("1.2");
42  		assertEquals(CompilerOptions.VERSION_1_2, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
43  		s.setSourceVersion("1.3");
44  		assertEquals(CompilerOptions.VERSION_1_3, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
45  		s.setSourceVersion("1.4");
46  		assertEquals(CompilerOptions.VERSION_1_4, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
47  		s.setSourceVersion("1.5");
48  		assertEquals(CompilerOptions.VERSION_1_5, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
49  		s.setSourceVersion("1.6");
50  		assertEquals(CompilerOptions.VERSION_1_6, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
51          s.setSourceVersion("1.7");
52          assertEquals(CompilerOptions.VERSION_1_7, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
53  	}
54  
55  	public void testTargetVersion() {
56  		final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
57  		s.setTargetVersion("1.1");
58  		assertEquals(CompilerOptions.VERSION_1_1, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
59  		s.setTargetVersion("1.2");
60  		assertEquals(CompilerOptions.VERSION_1_2, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
61  		s.setTargetVersion("1.3");
62  		assertEquals(CompilerOptions.VERSION_1_3, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
63  		s.setTargetVersion("1.4");
64  		assertEquals(CompilerOptions.VERSION_1_4, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
65  		s.setTargetVersion("1.5");
66  		assertEquals(CompilerOptions.VERSION_1_5, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
67  		s.setTargetVersion("1.6");
68  		assertEquals(CompilerOptions.VERSION_1_6, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
69          s.setTargetVersion("1.7");
70          assertEquals(CompilerOptions.VERSION_1_7, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
71  	}
72  
73  	public void testEncoding() {
74  		final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
75  		s.setSourceEncoding("ASCII");
76  		assertEquals("ASCII", s.toNativeSettings().get(CompilerOptions.OPTION_Encoding));
77  	}
78  
79  	public void testWarnings() {
80  		final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
81  		s.setWarnings(true);
82  		assertEquals(CompilerOptions.GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_SuppressWarnings));
83  		s.setWarnings(false);
84  		assertEquals(CompilerOptions.DO_NOT_GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_SuppressWarnings));
85  	}
86  
87  	public void testDeprecations() {
88  		final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
89  		s.setDeprecations(true);
90  		assertEquals(CompilerOptions.GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_ReportDeprecation));
91  		s.setDeprecations(false);
92  		assertEquals(CompilerOptions.DO_NOT_GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_ReportDeprecation));
93  	}
94  }