|
| 1 | +/* |
| 2 | + * Copyright 2020 DiffPlug |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.diffplug.spotless.maven.groovy; |
| 17 | + |
| 18 | +import com.diffplug.spotless.maven.MavenRunner; |
| 19 | + |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import com.diffplug.spotless.maven.MavenIntegrationHarness; |
| 23 | + |
| 24 | +public class ImportOrderTest extends MavenIntegrationHarness { |
| 25 | + @Test |
| 26 | + public void file() throws Exception { |
| 27 | + setFile("import.properties").toResource("java/importsorter/import.properties"); |
| 28 | + writePomWithGroovySteps( |
| 29 | + "<importOrder>", |
| 30 | + " <file>${basedir}/import.properties</file>", |
| 31 | + "</importOrder>"); |
| 32 | + runTest(); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void order() throws Exception { |
| 37 | + writePomWithGroovySteps( |
| 38 | + "<importOrder>", |
| 39 | + " <order>java,javax,org,\\#com</order>", |
| 40 | + "</importOrder>"); |
| 41 | + runTest(); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void standard() throws Exception { |
| 46 | + writePomWithGroovySteps("<importOrder />"); |
| 47 | + runTest("java/importsorter/GroovyCodeSortedMisplacedImportsDefault.test"); |
| 48 | + } |
| 49 | + |
| 50 | + private void runTest() throws Exception { |
| 51 | + runTest("java/importsorter/GroovyCodeSortedMisplacedImports.test"); |
| 52 | + } |
| 53 | + |
| 54 | + private void runTest(String expectedResource) throws Exception { |
| 55 | + String path = "src/main/groovy/test.groovy"; |
| 56 | + setFile(path).toResource("java/importsorter/GroovyCodeUnsortedMisplacedImports.test"); |
| 57 | + mavenRunner().withArguments("spotless:apply").runNoError(); |
| 58 | + assertFile(path).sameAsResource(expectedResource); |
| 59 | + } |
| 60 | +} |
0 commit comments