001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.jci.compilers;
019
020 import java.util.Map;
021
022 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
023
024 import junit.framework.TestCase;
025
026 public final class EclipseJavaCompilerSettingsTestCase extends TestCase {
027
028 public void testDefaultSettings() {
029 final Map<String, String> m = new EclipseJavaCompilerSettings().toNativeSettings();
030 assertEquals(CompilerOptions.DO_NOT_GENERATE, m.get(CompilerOptions.OPTION_SuppressWarnings));
031 assertEquals(CompilerOptions.DO_NOT_GENERATE, m.get(CompilerOptions.OPTION_ReportDeprecation));
032 assertEquals(CompilerOptions.VERSION_1_4, m.get(CompilerOptions.OPTION_TargetPlatform));
033 assertEquals(CompilerOptions.VERSION_1_4, m.get(CompilerOptions.OPTION_Source));
034 assertEquals("UTF-8", m.get(CompilerOptions.OPTION_Encoding));
035 }
036
037 public void testSourceVersion() {
038 final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
039 s.setSourceVersion("1.1");
040 assertEquals(CompilerOptions.VERSION_1_1, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
041 s.setSourceVersion("1.2");
042 assertEquals(CompilerOptions.VERSION_1_2, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
043 s.setSourceVersion("1.3");
044 assertEquals(CompilerOptions.VERSION_1_3, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
045 s.setSourceVersion("1.4");
046 assertEquals(CompilerOptions.VERSION_1_4, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
047 s.setSourceVersion("1.5");
048 assertEquals(CompilerOptions.VERSION_1_5, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
049 s.setSourceVersion("1.6");
050 assertEquals(CompilerOptions.VERSION_1_6, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
051 s.setSourceVersion("1.7");
052 assertEquals(CompilerOptions.VERSION_1_7, s.toNativeSettings().get(CompilerOptions.OPTION_Source));
053 }
054
055 public void testTargetVersion() {
056 final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
057 s.setTargetVersion("1.1");
058 assertEquals(CompilerOptions.VERSION_1_1, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
059 s.setTargetVersion("1.2");
060 assertEquals(CompilerOptions.VERSION_1_2, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
061 s.setTargetVersion("1.3");
062 assertEquals(CompilerOptions.VERSION_1_3, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
063 s.setTargetVersion("1.4");
064 assertEquals(CompilerOptions.VERSION_1_4, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
065 s.setTargetVersion("1.5");
066 assertEquals(CompilerOptions.VERSION_1_5, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
067 s.setTargetVersion("1.6");
068 assertEquals(CompilerOptions.VERSION_1_6, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
069 s.setTargetVersion("1.7");
070 assertEquals(CompilerOptions.VERSION_1_7, s.toNativeSettings().get(CompilerOptions.OPTION_TargetPlatform));
071 }
072
073 public void testEncoding() {
074 final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
075 s.setSourceEncoding("ASCII");
076 assertEquals("ASCII", s.toNativeSettings().get(CompilerOptions.OPTION_Encoding));
077 }
078
079 public void testWarnings() {
080 final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
081 s.setWarnings(true);
082 assertEquals(CompilerOptions.GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_SuppressWarnings));
083 s.setWarnings(false);
084 assertEquals(CompilerOptions.DO_NOT_GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_SuppressWarnings));
085 }
086
087 public void testDeprecations() {
088 final EclipseJavaCompilerSettings s = new EclipseJavaCompilerSettings();
089 s.setDeprecations(true);
090 assertEquals(CompilerOptions.GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_ReportDeprecation));
091 s.setDeprecations(false);
092 assertEquals(CompilerOptions.DO_NOT_GENERATE, s.toNativeSettings().get(CompilerOptions.OPTION_ReportDeprecation));
093 }
094 }