/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.revelc.code.impsort.maven.plugin;

import static net.revelc.code.impsort.maven.plugin.AbstractImpSortMojo.getLanguageLevel;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

import com.github.javaparser.ParserConfiguration.LanguageLevel;

public class AbstractImpSortMojoTest {

  @Test
  public void testLanguageLevel() {
    assertSame(LanguageLevel.POPULAR, getLanguageLevel(null));
    assertSame(LanguageLevel.POPULAR, getLanguageLevel(""));
    assertSame(LanguageLevel.JAVA_1_0, getLanguageLevel("1.0"));
    assertSame(LanguageLevel.JAVA_1_1, getLanguageLevel("1.1"));
    assertSame(LanguageLevel.JAVA_1_2, getLanguageLevel("1.2"));
    assertSame(LanguageLevel.JAVA_1_3, getLanguageLevel("1.3"));
    assertSame(LanguageLevel.JAVA_1_4, getLanguageLevel("1.4"));
    assertSame(LanguageLevel.JAVA_5, getLanguageLevel("1.5"));
    assertSame(LanguageLevel.JAVA_5, getLanguageLevel("5"));
    assertSame(LanguageLevel.JAVA_6, getLanguageLevel("1.6"));
    assertSame(LanguageLevel.JAVA_6, getLanguageLevel("6"));
    assertSame(LanguageLevel.JAVA_7, getLanguageLevel("1.7"));
    assertSame(LanguageLevel.JAVA_7, getLanguageLevel("7"));
    assertSame(LanguageLevel.JAVA_8, getLanguageLevel("1.8"));
    assertSame(LanguageLevel.JAVA_8, getLanguageLevel("8"));
    assertSame(LanguageLevel.JAVA_9, getLanguageLevel("1.9"));
    assertSame(LanguageLevel.JAVA_9, getLanguageLevel("9"));
    assertSame(LanguageLevel.JAVA_10, getLanguageLevel("10"));
    assertSame(LanguageLevel.JAVA_11, getLanguageLevel("11"));
    assertSame(LanguageLevel.JAVA_12, getLanguageLevel("12"));
    assertSame(LanguageLevel.JAVA_13, getLanguageLevel("13"));
    assertSame(LanguageLevel.JAVA_14, getLanguageLevel("14"));
    assertThrows(IllegalArgumentException.class, () -> getLanguageLevel("1.10"));
    assertThrows(IllegalArgumentException.class, () -> getLanguageLevel("1.11"));
    assertThrows(IllegalArgumentException.class, () -> getLanguageLevel("1.12"));
    assertThrows(IllegalArgumentException.class, () -> getLanguageLevel("1.13"));
    assertThrows(IllegalArgumentException.class, () -> getLanguageLevel("1.14"));
    // make sure preview works
    assertSame(LanguageLevel.JAVA_14_PREVIEW, getLanguageLevel("14_PREVIEW"));
    assertSame(LanguageLevel.JAVA_16_PREVIEW, getLanguageLevel("16_PREVIEW"));
  }

}

@@ -811,16 +811,149 @@
 tThrows;
+%0Aimport static org.junit.jupiter.api.Assertions.assertTrue;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Set;%0Aimport java.util.TreeSet;
 %0A%0Aimport
@@ -1263,530 +1263,259 @@
     
-assertSame(LanguageLevel.JAVA_1_0, getLanguageLevel(%221.0%22));%0A    assertSame(LanguageLevel.JAVA_1_1, getLanguageLevel(%221.1%22));%0A    assertSame(LanguageLevel.JAVA_1_2, getLanguageLevel(%221.2%22));%0A    assertSame(LanguageLevel.JAVA_1_3, getLanguageLevel(%221.3%22));%0A    assertSame(LanguageLevel.JAVA_1_4, getLanguageLevel(%221.4%22));%0A    assertSame(LanguageLevel.JAVA_5, getLanguageLevel(%221.5%22));%0A    assertSame(LanguageLevel.JAVA_5, getLanguageLevel(%225%22));%0A    assertSame(LanguageLevel.JAVA_6, getLanguageLevel(%221.6%22));%0A    assertS
+var prefix = %22JAVA_%22;%0A    var previewSuffix = %22_PREVIEW%22;%0A    // only these can be represented using single digit or 1.%3Cdigit%3E, as in Java 5 or Java 1.5%0A    var expectedOneDotOrSingle = new TreeSet%3C%3E(Set.of(%225%22, %226%22, %227%22, %228%22, %229%22));%0A    Arrays.stre
 am
-e
 (Lan
@@ -1529,1323 +1529,1050 @@
 vel.
-JAVA_6, getLanguageLevel(%226%22));%0A    assertSame(LanguageLevel.JAVA_7, getLanguageLevel(%221.7%22));%0A    assertSame(LanguageLevel.JAVA_7, getLanguageLevel(%227%22));%0A    assertSame(LanguageLevel.JAVA_8, getLanguageLevel(%221.8%22));%0A    assertSame(LanguageLevel.JAVA_8, getLanguageLevel(%228%22));%0A    assertSame(LanguageLevel.JAVA_9, getLanguageLevel(%221.9%22));%0A    assertSame(LanguageLevel.JAVA_9, getLanguageLevel(%229%22));%0A    assertSame(LanguageLevel.JAVA_10, getLanguageLevel(%2210%22));%0A    assertSame(LanguageLevel.JAVA_11, getLanguageLevel(%2211%22));%0A    assertSame(LanguageLevel.JAVA_12, getLanguageLevel(%2212%22));%0A    assertSame(LanguageLevel.JAVA_13, getLanguageLevel(%2213%22));%0A    assertSame(LanguageLevel.JAVA_14, getLanguageLevel(%2214%22));%0A    assertThrows(IllegalArgumentException.class, () -%3E getLanguageLevel(%221.10%22));%0A    assertThrows(IllegalArgumentException.class, () -%3E getLanguageLevel(%221.11%22));%0A    assertThrows(IllegalArgumentException.class, () -%3E getLanguageLevel(%221.12%22));%0A    assertThrows(IllegalArgumentException.class, () -%3E getLanguageLevel(%221.13%22));%0A    assertThrows(IllegalArgumentException.class, () -%3E getLanguageLevel(%221.14%22));%0A    // make sure preview works%0A    assertSame(LanguageLevel.JAVA_14_PREVIEW, getLanguageLevel(%2214_PREVIEW%22));%0A    assertSame(LanguageLevel.JAVA_16_PREVIEW, getLanguageLevel(%2216_PREVIEW%22)
+values()).forEach(level -%3E %7B%0A      assertTrue(level.name().startsWith(prefix));%0A      String version = level.name().substring(prefix.length());%0A      if (!version.endsWith(previewSuffix)) %7B%0A        version = version.replace('_', '.');%0A      %7D%0A      if (version.length() == 1) %7B%0A        // check that the versions that can be represented by either X or 1.X are the same%0A        assertTrue(expectedOneDotOrSingle.remove(version), %22Unexpectedly saw %22 + version);%0A        assertSame(level, getLanguageLevel(%221.%22 + version));%0A      %7D else if (!version.contains(%22.%22) && !version.contains(previewSuffix)) %7B%0A        // make sure versions above Java 9 can't be represented as 1.X, as in 1.10%0A        final var v = version;%0A        assertThrows(IllegalArgumentException.class, () -%3E getLanguageLevel(%221.%22 + v));%0A      %7D%0A      // basic check to make sure our getter method returns the correct level%0A      assertSame(level, getLanguageLevel(version));%0A    %7D);%0A    assertTrue(expectedOneDotOrSingle.isEmpty(), %22Did not encounter %22 + expectedOneDotOrSingle
 );%0A 

Improve compiler compliance level test