Improve template testing
This commit is contained in:
parent
cfb8839359
commit
fc0963ad40
1 changed files with 27 additions and 22 deletions
|
@ -71,17 +71,6 @@ class GeneratedVersionTest {
|
||||||
logger.setUseParentHandlers(false);
|
logger.setUseParentHandlers(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deleteOnExit(File folder) {
|
|
||||||
folder.deleteOnExit();
|
|
||||||
for (var f : Objects.requireNonNull(folder.listFiles())) {
|
|
||||||
if (f.isDirectory()) {
|
|
||||||
deleteOnExit(f);
|
|
||||||
} else {
|
|
||||||
f.deleteOnExit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares two strings by removing all line separators and whitespace.
|
* Compares two strings by removing all line separators and whitespace.
|
||||||
*
|
*
|
||||||
|
@ -106,6 +95,17 @@ class GeneratedVersionTest {
|
||||||
return cleanedText1.equals(cleanedText2);
|
return cleanedText1.equals(cleanedText2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void deleteOnExit(File folder) {
|
||||||
|
folder.deleteOnExit();
|
||||||
|
for (var f : Objects.requireNonNull(folder.listFiles())) {
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
deleteOnExit(f);
|
||||||
|
} else {
|
||||||
|
f.deleteOnExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuildCustomTemplate() {
|
void testBuildCustomTemplate() {
|
||||||
var gv = new GeneratedVersion();
|
var gv = new GeneratedVersion();
|
||||||
|
@ -116,17 +116,22 @@ class GeneratedVersionTest {
|
||||||
gv.setClassName("MyVersion");
|
gv.setClassName("MyVersion");
|
||||||
|
|
||||||
var t = gv.buildTemplate();
|
var t = gv.buildTemplate();
|
||||||
assertThat(compareTextIgnoringLineSeparators(t.getContent(),"package com.example.my;" +
|
var v = gv.getProject().version();
|
||||||
"public final class MyVersion {" +
|
assertThat(v).extracting("majorInt", "minorInt", "revisionInt").as("version")
|
||||||
" public static final int PROJECT = \"My App\";" +
|
.containsExactly(2, 1, 3);
|
||||||
" public static final int MAJOR = 2;" +
|
assertThat(compareTextIgnoringLineSeparators(t.getContent(),
|
||||||
" public static final int MINOR = 1;" +
|
String.format("package %s;" +
|
||||||
" public static final int REVISION = 3;" +
|
"public final class %s {" +
|
||||||
" public static final String QUALIFIER = \"\";" +
|
" public static final int PROJECT = \"%s\";" +
|
||||||
" private MyVersion() {" +
|
" public static final int MAJOR = %d;" +
|
||||||
" // no-op" +
|
" public static final int MINOR = %d;" +
|
||||||
" }" +
|
" public static final int REVISION = %d;" +
|
||||||
"}")).isTrue();
|
" public static final String QUALIFIER = \"\";" +
|
||||||
|
" private MyVersion() {" +
|
||||||
|
" // no-op" +
|
||||||
|
" }" +
|
||||||
|
"}", gv.getPackageName(), gv.getClassName(), gv.getProjectName(), v.majorInt(),
|
||||||
|
v.minorInt(), v.revisionInt()))).as("template").isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue