public void hasLines(String... lines) { hasContent(String.join("\n", Arrays.asList(lines))); }
@Test public void testStepCheckFail() throws IOException { File testFile = setFile("testFile").toContent("apple"); checkTask.setTarget(Collections.singleton(testFile)); checkTask.addStep(FormatterStep.createNeverUpToDate("double-p", content -> content.replace("pp", "p"))); String diff = String.join("\n", " @@ -1 +1 @@", " -apple", " +aple"); Assertions.assertThatThrownBy(() -> execute(checkTask)).hasStackTraceContaining(diff); assertFile(testFile).hasContent("apple"); }
@Test public void testStepApply() throws Exception { File testFile = setFile("testFile").toContent("apple"); applyTask.setTarget(Collections.singleton(testFile)); applyTask.addStep(FormatterStep.createNeverUpToDate("double-p", content -> content.replace("pp", "p"))); execute(applyTask); assertFile(testFile).hasContent("aple"); } }
/** XML extension is discontinued. */ @Test @Deprecated public void fromContentXml() throws Exception { String license = " Licensed under Apache-2.0 "; writePomWithXmlSteps( "<licenseHeader>", " <content>", "<!--" + license + "-->", " </content>", "</licenseHeader>"); String path = "src/test.xml"; setFile(path).toContent("<a/>"); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent("<!--" + license + "-->\n<a/>"); }
@Test public void paddedCellApply() throws Exception { Bundle cycle = cycle().paddedCell(); Bundle converge = converge().paddedCell(); Bundle diverge = diverge().paddedCell(); execute(cycle.apply); execute(converge.apply); execute(diverge.apply); assertFile(cycle.file).hasContent("A"); // cycle -> first element in cycle assertFile(converge.file).hasContent(""); // converge -> converges assertFile(diverge.file).hasContent("CCC"); // diverge -> no change execute(cycle.check); execute(converge.check); execute(diverge.check); }
@Test public void fromContentCpp() throws Exception { String cppLicense = "//my license"; writePomWithCppSteps( "<licenseHeader>", " <content>", cppLicense, " </content>", "</licenseHeader>"); String path = "src/test/cpp/file.c++"; String cppContent = "#include <whatsoever.h>"; setFile(path).toContent(cppContent); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent(cppLicense + '\n' + cppContent); }
@Test public void fromContentKotlin() throws Exception { writePomWithKotlinSteps( "<licenseHeader>", " <content>", KOTLIN_LICENSE_HEADER, " </content>", "</licenseHeader>"); String path = "src/main/kotlin/test.kt"; String noLicenseHeader = getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); setFile(path).toContent(noLicenseHeader); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent(KOTLIN_LICENSE_HEADER + '\n' + noLicenseHeader); }
public void sameAsResource(String resource) throws IOException { hasContent(getTestResource(resource)); }
public void hasContent(String expected) { hasContent(expected, StandardCharsets.UTF_8); }
@Test public void itWritesToFile() throws IOException { jsonWriter.put("mystring", "stringvalue"); final File file = newFile("target.json"); jsonWriter.toJsonFile(file); assertFile(file).hasContent("{\n \"mystring\": \"stringvalue\"\n}"); } }
private void runTest(String sourceContent, String targetContent) throws Exception { String path = "src/main/java/test.java"; setFile(path).toContent(sourceContent); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent(targetContent); } }
private void runTest() throws Exception { String noTrailingNewline = "public class Java {}"; String hasTrailingNewline = noTrailingNewline + "\n"; setFile("src/main/java/test.java").toContent(noTrailingNewline); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("src/main/java/test.java").hasContent(hasTrailingNewline); } }
private void runTest(String sourceContent, String targetContent) throws Exception { String path = "src/main/java/test.java"; setFile(path).toContent(sourceContent); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent(targetContent); } }
private void runTest() throws Exception { String notFormatted = "<a><b> c</b></a>"; String formatted = "<a>\n\t<b> c</b>\n</a>"; //writePomWithFormatSteps includes java. WTP does not care about file extensions. setFile("src/main/java/test.java").toContent(notFormatted); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("src/main/java/test.java").hasContent(formatted); } }
private void runTest(String sourceContent, String targetContent) throws Exception { String path = "src/main/java/test.java"; setFile(path).toContent(sourceContent); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent(targetContent); }
@Override protected void applyIsUpToDate(boolean upToDate) throws IOException { super.applyIsUpToDate(upToDate); assertFile("README.md").hasContent("abc"); }
private void assertResolveDependenciesWorks() throws Exception { String path = "src/main/java/test.java"; String unformattedContent = "package a;"; setFile(path).toContent(unformattedContent); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent(unformattedContent.replace(" ", " ")); } }
@Test public void testStepCheckPass() throws Exception { File testFile = setFile("testFile").toContent("aple"); checkTask.setTarget(Collections.singleton(testFile)); checkTask.addStep(FormatterStep.createNeverUpToDate("double-p", content -> content.replace("pp", "p"))); execute(checkTask); assertFile(testFile).hasContent("aple"); }
@Test public void testLineEndingsApply() throws Exception { File testFile = setFile("testFile").toContent("\r\n"); applyTask.setLineEndingsPolicy(LineEnding.UNIX.createPolicy()); applyTask.setTarget(Collections.singleton(testFile)); execute(applyTask); assertFile(testFile).hasContent("\n"); }
private void runTest(String sourceContent, String targetContent) throws Exception { String path = "src/main/java/test.java"; setFile(path).toContent(sourceContent); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).hasContent(targetContent); }