|
| 1 | +/* |
| 2 | + * Copyright 2016 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.gradle.spotless.java; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | + |
| 20 | +import org.junit.Assert; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +import com.diffplug.gradle.spotless.GradleIntegrationTest; |
| 24 | + |
| 25 | +public class JavaDefaultTargetTest extends GradleIntegrationTest { |
| 26 | + @Test |
| 27 | + public void integration() throws IOException { |
| 28 | + write("build.gradle", |
| 29 | + "plugins {", |
| 30 | + " id 'com.diffplug.gradle.spotless'", |
| 31 | + "}", |
| 32 | + "repositories { mavenCentral() }", |
| 33 | + "", |
| 34 | + "apply plugin: 'groovy'", |
| 35 | + "", |
| 36 | + "spotless {", |
| 37 | + " java {", |
| 38 | + " googleJavaFormat()", |
| 39 | + " }", |
| 40 | + "}"); |
| 41 | + String input = getTestResource("java/googlejavaformat/JavaCodeUnformatted.test"); |
| 42 | + write("src/main/java/test.java", input); |
| 43 | + write("src/main/groovy/test.java", input); |
| 44 | + write("src/main/groovy/test.groovy", input); |
| 45 | + |
| 46 | + // write appends a line ending so re-read to see what groovy currently looks like |
| 47 | + String groovyInput = read("src/main/groovy/test.groovy"); |
| 48 | + |
| 49 | + gradleRunner().forwardOutput().withArguments("spotlessApply").build(); |
| 50 | + |
| 51 | + String result = read("src/main/java/test.java"); |
| 52 | + String output = getTestResource("java/googlejavaformat/JavaCodeFormatted.test"); |
| 53 | + Assert.assertEquals("Java code in the java directory should be formatted.", output, result); |
| 54 | + |
| 55 | + result = read("src/main/groovy/test.java"); |
| 56 | + Assert.assertEquals("Java code in the groovy directory should be formatted.", output, result); |
| 57 | + |
| 58 | + result = read("src/main/groovy/test.groovy"); |
| 59 | + Assert.assertEquals("Groovy code in the groovy directory should not be formatted.", groovyInput, result); |
| 60 | + } |
| 61 | +} |
0 commit comments