Skip to content

Commit

Permalink
use assertFile instead of assertThat.isEqualTo for all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasbalke committed Feb 22, 2018
1 parent 0ab7ca0 commit 23a1d1b
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.diffplug.spotless.maven.generic;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import com.diffplug.spotless.maven.MavenIntegrationTest;
Expand Down Expand Up @@ -82,9 +80,9 @@ public void fromContentFormat() throws Exception {
}

private void runTest() throws Exception {
setFile("src/main/java/test.java").toResource("license/MissingLicense.test");
String path = "src/main/java/test.java";
setFile(path).toResource("license/MissingLicense.test");
mavenRunner().withArguments("spotless:apply").runNoError();
String actual = read("src/main/java/test.java");
assertThat(actual).isEqualTo(getTestResource("license/HasLicense.test"));
assertFile(path).sameAsResource("license/HasLicense.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.diffplug.spotless.maven.generic;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import com.diffplug.spotless.maven.MavenIntegrationTest;
Expand All @@ -35,9 +33,9 @@ public void fromContent() throws Exception {
}

private void runTest() throws Exception {
setFile("src/main/java/test.java").toResource("replace/JavaCodeUnformatted.test");
String path = "src/main/java/test.java";
setFile(path).toResource("replace/JavaCodeUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
String actual = read("src/main/java/test.java");
assertThat(actual).isEqualTo(getTestResource("replace/JavaCodeFormatted.test"));
assertFile(path).sameAsResource("replace/JavaCodeFormatted.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.diffplug.spotless.maven.generic;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import com.diffplug.spotless.maven.MavenIntegrationTest;
Expand All @@ -35,9 +33,9 @@ public void fromContent() throws Exception {
}

private void runTest() throws Exception {
setFile("src/main/java/test.java").toResource("replace/JavaCodeUnformatted.test");
String path = "src/main/java/test.java";
setFile(path).toResource("replace/JavaCodeUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
String actual = read("src/main/java/test.java");
assertThat(actual).isEqualTo(getTestResource("replace/JavaCodeFormatted.test"));
assertFile(path).sameAsResource("replace/JavaCodeFormatted.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.diffplug.spotless.maven.generic;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import com.diffplug.spotless.maven.MavenIntegrationTest;
Expand All @@ -31,10 +29,10 @@ public void fromContentToTabs() throws Exception {
}

private void runTest() throws Exception {
setFile("src/main/java/test.java").toResource("trailingWhitespace/JavaCodeUnformated.test");
String path = "src/main/java/test.java";
setFile(path).toResource("trailingWhitespace/JavaCodeUnformated.test");
mavenRunner().withArguments("spotless:apply").runNoError();
String actual = read("src/main/java/test.java");
assertThat(actual).isEqualTo(getTestResource("trailingWhitespace/JavaCodeFormated.test"));
assertFile(path).sameAsResource("trailingWhitespace/JavaCodeFormated.test");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public void testEclipse() throws Exception {
"</eclipse>");
setFile("formatter.xml").toResource("java/eclipse/formatter.xml");

setFile("src/main/java/test.java").toResource("java/eclipse/JavaCodeUnformatted.test");
String path = "src/main/java/test.java";
setFile(path).toResource("java/eclipse/JavaCodeUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/java/test.java").sameAsResource("java/eclipse/JavaCodeFormatted.test");
assertFile(path).sameAsResource("java/eclipse/JavaCodeFormatted.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public void specificVersionDefaultStyle() throws Exception {
" <version>1.2</version>",
"</googleJavaFormat>");

setFile("src/main/java/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/java/test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
runTest("java/googlejavaformat/JavaCodeFormatted.test");
}

@Test
Expand All @@ -40,8 +38,13 @@ public void specificVersionSpecificStyle() throws Exception {
" <style>AOSP</style>",
"</googleJavaFormat>");

setFile("src/main/java/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
runTest("java/googlejavaformat/JavaCodeFormattedAOSP.test");
}

private void runTest(String targetResource) throws Exception {
String path = "src/main/java/test.java";
setFile(path).toResource("java/googlejavaformat/JavaCodeUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/java/test.java").sameAsResource("java/googlejavaformat/JavaCodeFormattedAOSP.test");
assertFile(path).sameAsResource(targetResource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public void order() throws Exception {
}

private void runTest() throws Exception {
setFile("src/main/java/test.java").toResource("java/importsorter/JavaCodeUnsortedImports.test");
String path = "src/main/java/test.java";
setFile(path).toResource("java/importsorter/JavaCodeUnsortedImports.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/java/test.java").sameAsResource("java/importsorter/JavaCodeSortedImports.test");
assertFile(path).sameAsResource("java/importsorter/JavaCodeSortedImports.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public class RemoveUnusedImportsStepTest extends MavenIntegrationTest {
public void testRemoveUnusedInports() throws Exception {
writePomWithJavaSteps("<removeUnusedImports/>");

setFile("src/main/java/test.java").toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test");
String path = "src/main/java/test.java";
setFile(path).toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/java/test.java").sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test");
assertFile(path).sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ public class ScalafmtTest extends MavenIntegrationTest {
public void testScalafmtWithDefaultConfig() throws Exception {
writePomWithScalaSteps("<scalafmt/>");

setFile("src/main/scala/test.scala").toResource("scala/scalafmt/basic.dirty");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/scala/test.scala").sameAsResource("scala/scalafmt/basic.clean");
runTest("scala/scalafmt/basic.clean");
}

@Test
public void testScalafmtWithCustomConfig() throws Exception {
setFile("scalafmt.conf").toResource("scala/scalafmt/scalafmt.conf");

writePomWithScalaSteps(
"<scalafmt>",
" <file>${project.basedir}/scalafmt.conf</file>",
"</scalafmt>");
setFile("scalafmt.conf").toResource("scala/scalafmt/scalafmt.conf");

setFile("src/main/scala/test.scala").toResource("scala/scalafmt/basic.dirty");
runTest("scala/scalafmt/basic.cleanWithCustomConf");
}

private void runTest(String s) throws Exception {
String path = "src/main/scala/test.scala";
setFile(path).toResource("scala/scalafmt/basic.dirty");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile("src/main/scala/test.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf");
assertFile(path).sameAsResource(s);
}
}
5 changes: 0 additions & 5 deletions testlib/src/main/resources/lineEndings/JavaCode-UNIX.test

This file was deleted.

5 changes: 0 additions & 5 deletions testlib/src/main/resources/lineEndings/JavaCode-WINDOWS.test

This file was deleted.

0 comments on commit 23a1d1b

Please sign in to comment.