13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- package com .diffplug .gradle . spotless ;
16
+ package com .diffplug .spotless . generic ;
17
17
18
+ import java .io .File ;
18
19
import java .nio .charset .StandardCharsets ;
19
20
20
21
import org .junit .Assert ;
21
22
import org .junit .Test ;
22
23
24
+ import com .diffplug .spotless .FormatterStep ;
23
25
import com .diffplug .spotless .ResourceHarness ;
24
26
import com .diffplug .spotless .generic .LicenseHeaderStep ;
25
27
@@ -28,42 +30,46 @@ public class LicenseHeaderStepTest extends ResourceHarness {
28
30
private static final String KEY_FILE_NOTAPPLIED = "license/MissingLicense.test" ;
29
31
private static final String KEY_FILE_APPLIED = "license/HasLicense.test" ;
30
32
33
+ // If this constant changes, don't forget to change the similarly-named one in
34
+ // plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java as well
35
+ private static final String LICENSE_HEADER_DELIMITER = "package " ;
36
+
31
37
@ Test
32
- public void fromString () throws Throwable {
33
- LicenseHeaderStep step = new LicenseHeaderStep (getTestResource (KEY_LICENSE ), JavaExtension . LICENSE_HEADER_DELIMITER );
34
- assertOnResources (step :: format , KEY_FILE_NOTAPPLIED , KEY_FILE_APPLIED );
38
+ public void fromHeader () throws Throwable {
39
+ FormatterStep step = LicenseHeaderStep . createFromHeader (getTestResource (KEY_LICENSE ), LICENSE_HEADER_DELIMITER );
40
+ assertOnResources (step , KEY_FILE_NOTAPPLIED , KEY_FILE_APPLIED );
35
41
}
36
42
37
43
@ Test
38
44
public void fromFile () throws Throwable {
39
- LicenseHeaderStep step = new LicenseHeaderStep (createTestFile (KEY_LICENSE ), StandardCharsets .UTF_8 , JavaExtension . LICENSE_HEADER_DELIMITER );
40
- assertOnResources (step :: format , KEY_FILE_NOTAPPLIED , KEY_FILE_APPLIED );
45
+ FormatterStep step = LicenseHeaderStep . createFromFile (createTestFile (KEY_LICENSE ), StandardCharsets .UTF_8 , LICENSE_HEADER_DELIMITER );
46
+ assertOnResources (step , KEY_FILE_NOTAPPLIED , KEY_FILE_APPLIED );
41
47
}
42
48
43
49
@ Test
44
50
public void efficient () throws Throwable {
45
- LicenseHeaderStep step = new LicenseHeaderStep ("LicenseHeader\n " , "contentstart" );
51
+ FormatterStep step = LicenseHeaderStep . createFromHeader ("LicenseHeader\n " , "contentstart" );
46
52
String alreadyCorrect = "LicenseHeader\n contentstart" ;
47
- Assert .assertEquals (alreadyCorrect , step .format (alreadyCorrect ));
53
+ Assert .assertEquals (alreadyCorrect , step .format (alreadyCorrect , new File ( "" ) ));
48
54
// If no change is required, it should return the exact same string for efficiency reasons
49
- Assert .assertSame (alreadyCorrect , step .format (alreadyCorrect ));
55
+ Assert .assertSame (alreadyCorrect , step .format (alreadyCorrect , new File ( "" ) ));
50
56
}
51
57
52
58
@ Test
53
59
public void sanitized () throws Throwable {
54
60
// The sanitizer should add a \n
55
- LicenseHeaderStep step = new LicenseHeaderStep ("LicenseHeader" , "contentstart" );
61
+ FormatterStep step = LicenseHeaderStep . createFromHeader ("LicenseHeader" , "contentstart" );
56
62
String alreadyCorrect = "LicenseHeader\n contentstart" ;
57
- Assert .assertEquals (alreadyCorrect , step .format (alreadyCorrect ));
58
- Assert .assertSame (alreadyCorrect , step .format (alreadyCorrect ));
63
+ Assert .assertEquals (alreadyCorrect , step .format (alreadyCorrect , new File ( "" ) ));
64
+ Assert .assertSame (alreadyCorrect , step .format (alreadyCorrect , new File ( "" ) ));
59
65
}
60
66
61
67
@ Test
62
68
public void sanitizerDoesntGoTooFar () throws Throwable {
63
69
// if the user wants extra lines after the header, we shouldn't clobber them
64
- LicenseHeaderStep step = new LicenseHeaderStep ("LicenseHeader\n \n " , "contentstart" );
70
+ FormatterStep step = LicenseHeaderStep . createFromHeader ("LicenseHeader\n \n " , "contentstart" );
65
71
String alreadyCorrect = "LicenseHeader\n \n contentstart" ;
66
- Assert .assertEquals (alreadyCorrect , step .format (alreadyCorrect ));
67
- Assert .assertSame (alreadyCorrect , step .format (alreadyCorrect ));
72
+ Assert .assertEquals (alreadyCorrect , step .format (alreadyCorrect , new File ( "" ) ));
73
+ Assert .assertSame (alreadyCorrect , step .format (alreadyCorrect , new File ( "" ) ));
68
74
}
69
75
}
0 commit comments