Skip to content

Commit

Permalink
Forced all tests to go through the Builder API.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jun 30, 2020
1 parent 6e39b83 commit 80ff5df
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ public String apply(String input) throws Exception {

private static final long serialVersionUID = 2L;

public static FormatterStep createFromHeader(String header, String delimiterExpr) {
// TODO Auto-generated method stub
return null;
}

private static final String NAME = "licenseHeader";
private static final String DEFAULT_YEAR_DELIMITER = "-";
private static final List<String> YEAR_TOKENS = Arrays.asList("$YEAR", "$today.year");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ public class CppDefaultsTest extends ResourceHarness {
@Test
public void testDelimiterExpr() throws Exception {
final String header = "/*My tests header*/";
FormatterStep step = LicenseHeaderStep.createFromHeader(header, CppDefaults.DELIMITER_EXPR);
FormatterStep step = LicenseHeaderStep.headerDelimiter(header, CppDefaults.DELIMITER_EXPR).build();
final File dummyFile = setFile("src/main/cpp/file1.dummy").toContent("");
for (String testSource : Arrays.asList(
"//Accpet multiple spaces between composed term.@using namespace std;",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,7 @@ public class CssDefaultsTest extends ResourceHarness {
@Test
public void testDelimiterExpr() throws Exception {
final String header = "/*My tests header*/";
FormatterStep step = LicenseHeaderStep.createFromHeader(header, CssDefaults.DELIMITER_EXPR);
FormatterStep step = LicenseHeaderStep.headerDelimiter(header, CssDefaults.DELIMITER_EXPR).build();
final File dummyFile = setFile("src/main/cpp/file1.dummy").toContent("");
for (String testSource : Arrays.asList(
"/* Starts with element selector */@\np {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public class LicenseHeaderStepTest extends ResourceHarness {

@Test
public void fromHeader() throws Throwable {
FormatterStep step = LicenseHeaderStep.createFromHeader(getTestResource(KEY_LICENSE), LICENSE_HEADER_DELIMITER);
FormatterStep step = LicenseHeaderStep.headerDelimiter(getTestResource(KEY_LICENSE), LICENSE_HEADER_DELIMITER).build();
assertOnResources(step, KEY_FILE_NOTAPPLIED, KEY_FILE_APPLIED);
}

@Test
public void should_apply_license_containing_YEAR_token() throws Throwable {
StepHarness.forStep(LicenseHeaderStep.createFromHeader(licenseWith(HEADER_WITH_YEAR), LICENSE_HEADER_DELIMITER))
StepHarness.forStep(LicenseHeaderStep.headerDelimiter(licenseWith(HEADER_WITH_YEAR), LICENSE_HEADER_DELIMITER).build())
.test(getTestResource(KEY_FILE_WITHOUT_LICENSE), fileContainingYear(HEADER_WITH_YEAR, currentYear()))
.testUnaffected(fileContainingYear(HEADER_WITH_YEAR, currentYear()))
.testUnaffected(fileContainingYear(HEADER_WITH_YEAR, "2003"))
Expand All @@ -66,7 +66,7 @@ public void should_apply_license_containing_YEAR_token() throws Throwable {
.test(fileContainingYear(HEADER_WITH_YEAR + "\n **/\n/* Something after license.", "2003"), fileContainingYear(HEADER_WITH_YEAR, "2003"))
.test(fileContainingYear(HEADER_WITH_YEAR, "not a year"), fileContainingYear(HEADER_WITH_YEAR, currentYear()));
// Check with variant
StepHarness.forStep(LicenseHeaderStep.createFromHeader(licenseWith(HEADER_WITH_YEAR_VARIANT), LICENSE_HEADER_DELIMITER))
StepHarness.forStep(LicenseHeaderStep.headerDelimiter(licenseWith(HEADER_WITH_YEAR_VARIANT), LICENSE_HEADER_DELIMITER).build())
.test(getTestResource(KEY_FILE_WITHOUT_LICENSE), fileContainingYear(HEADER_WITH_YEAR_VARIANT, currentYear()))
.testUnaffected(fileContainingYear(HEADER_WITH_YEAR_VARIANT, currentYear()))
.test(fileContaining("This is a fake license. Copyright "), fileContainingYear(HEADER_WITH_YEAR_VARIANT, currentYear()))
Expand All @@ -75,7 +75,7 @@ public void should_apply_license_containing_YEAR_token() throws Throwable {
.test(fileContaining("This is a fake license. CopyrightACME corp."), fileContainingYear(HEADER_WITH_YEAR_VARIANT, currentYear()));

//Check when token is of the format $today.year
StepHarness.forStep(LicenseHeaderStep.createFromHeader(licenseWith(HEADER_WITH_YEAR_INTELLIJ), LICENSE_HEADER_DELIMITER))
StepHarness.forStep(LicenseHeaderStep.headerDelimiter(licenseWith(HEADER_WITH_YEAR_INTELLIJ), LICENSE_HEADER_DELIMITER).build())
.test(fileContaining(HEADER_WITH_YEAR_INTELLIJ), fileWithLicenseContaining(HEADER_WITH_YEAR_INTELLIJ, currentYear(), "$today.year"));
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public void should_apply_license_containing_YEAR_token_with_special_character_in

@Test
public void should_apply_license_containing_YEAR_token_with_custom_separator() throws Throwable {
StepHarness.forStep(LicenseHeaderStep.createFromHeader(licenseWith(HEADER_WITH_YEAR), LICENSE_HEADER_DELIMITER))
StepHarness.forStep(LicenseHeaderStep.headerDelimiter(licenseWith(HEADER_WITH_YEAR), LICENSE_HEADER_DELIMITER).build())
.test(getTestResource(KEY_FILE_WITHOUT_LICENSE), fileContainingYear(HEADER_WITH_YEAR, currentYear()))
.testUnaffected(fileContainingYear(HEADER_WITH_YEAR, currentYear()))
.testUnaffected(fileContainingYear(HEADER_WITH_YEAR, "2003"))
Expand All @@ -136,7 +136,7 @@ private String currentYear() {

@Test
public void efficient() throws Throwable {
FormatterStep step = LicenseHeaderStep.createFromHeader("LicenseHeader\n", "contentstart");
FormatterStep step = LicenseHeaderStep.headerDelimiter("LicenseHeader\n", "contentstart").build();
String alreadyCorrect = "LicenseHeader\ncontentstart";
Assert.assertEquals(alreadyCorrect, step.format(alreadyCorrect, new File("")));
// If no change is required, it should return the exact same string for efficiency reasons
Expand All @@ -146,7 +146,7 @@ public void efficient() throws Throwable {
@Test
public void sanitized() throws Throwable {
// The sanitizer should add a \n
FormatterStep step = LicenseHeaderStep.createFromHeader("LicenseHeader", "contentstart");
FormatterStep step = LicenseHeaderStep.headerDelimiter("LicenseHeader", "contentstart").build();
String alreadyCorrect = "LicenseHeader\ncontentstart";
Assert.assertEquals(alreadyCorrect, step.format(alreadyCorrect, new File("")));
Assert.assertSame(alreadyCorrect, step.format(alreadyCorrect, new File("")));
Expand All @@ -155,7 +155,7 @@ public void sanitized() throws Throwable {
@Test
public void sanitizerDoesntGoTooFar() throws Throwable {
// if the user wants extra lines after the header, we shouldn't clobber them
FormatterStep step = LicenseHeaderStep.createFromHeader("LicenseHeader\n\n", "contentstart");
FormatterStep step = LicenseHeaderStep.headerDelimiter("LicenseHeader\n\n", "contentstart").build();
String alreadyCorrect = "LicenseHeader\n\ncontentstart";
Assert.assertEquals(alreadyCorrect, step.format(alreadyCorrect, new File("")));
Assert.assertSame(alreadyCorrect, step.format(alreadyCorrect, new File("")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,7 @@ public class XmlDefaultsTest extends ResourceHarness {
@Test
public void testDelimiterExpr() throws Exception {
final String header = "<!--My tests header-->";
FormatterStep step = LicenseHeaderStep.createFromHeader(header, XmlDefaults.DELIMITER_EXPR);
FormatterStep step = LicenseHeaderStep.headerDelimiter(header, XmlDefaults.DELIMITER_EXPR).build();
final File dummyFile = setFile("src/main/file.dummy").toContent("");
for (String testSource : Arrays.asList(
"<!--XML starts with element-->@\n<a></a>",
Expand Down

0 comments on commit 80ff5df

Please sign in to comment.