Skip to content

Commit

Permalink
Cleanup no longer needed version switches
Browse files Browse the repository at this point in the history
  • Loading branch information
casid committed May 23, 2023
1 parent b731ca9 commit a51d63d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 51 deletions.
4 changes: 0 additions & 4 deletions jte/src/test/java/gg/jte/PreCompileTemplatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ void precompileAll() {

@Test
void precompileAll_externalClassLoader() {
if (TestUtils.isLegacyJavaVersion()) {
return;
}

ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader externalClassLoader = new URLClassLoader(new URL[] {contextClassLoader.getResource("external/external.jar")});
Expand Down
8 changes: 0 additions & 8 deletions jte/src/test/java/gg/jte/TemplateEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ void variable() {

@Test
void variable_modern() {
if (TestUtils.isLegacyJavaVersion()) {
return;
}

givenTemplate("!{var y = 50;}${y}");
thenOutputIs("50");
}
Expand Down Expand Up @@ -1266,10 +1262,6 @@ void missingContentType() {

@Test
void compileArgs_enablePreview() {
if (TestUtils.isLegacyJavaVersion()) {
return;
}

templateEngine.setCompileArgs("--enable-preview");
givenRawTemplate("Hello World!");
thenRenderingFailsWithException().hasMessageContaining("--enable-preview must be used with either -source or --release");
Expand Down
24 changes: 0 additions & 24 deletions jte/src/test/java/gg/jte/TemplateEngine_HotReloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ void template() {
whenFileIsWritten(TEMPLATE, "@param String name\nHello ${name}!");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();

whenFileIsWritten(TEMPLATE, "@param String name\nHello ${name}!!!");
thenTemplateOutputIs("Hello hot reload!!!");
}
Expand All @@ -51,8 +49,6 @@ void tagUsedByTemplate() {
whenFileIsWritten(TEMPLATE, "@param String name\n@template.tag.name(name)");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();

whenFileIsWritten("tag/name.jte", "@param String name\nHello ${name}!!!");
thenTemplateOutputIs("Hello hot reload!!!");
}
Expand All @@ -65,8 +61,6 @@ void tagUsedByTemplates() {
thenTemplateOutputIs("test1.jte", "test1: Hello hot reload!");
thenTemplateOutputIs("test2.jte", "test2: Hello hot reload!");

waitUntilFileChangesPossible();

whenFileIsWritten("tag/name.jte", "@param String name\nHello ${name}!!!");
thenTemplateOutputIs("test1.jte", "test1: Hello hot reload!!!");
thenTemplateOutputIs("test2.jte", "test2: Hello hot reload!!!");
Expand All @@ -78,13 +72,11 @@ void newDependencyAdded() {
whenFileIsWritten(TEMPLATE, "@param String name\n@template.tag.name(name)");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/nested.jte", "@param String name\nnested ${name}");
whenFileIsWritten("tag/name.jte", "@param String name\nHello @template.tag.nested(name)!!!");

thenTemplateOutputIs("Hello nested hot reload!!!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/nested.jte", "@param String name\nnested, ${name}");

thenTemplateOutputIs("Hello nested, hot reload!!!");
Expand All @@ -96,24 +88,20 @@ void anotherDependencyAdded() {
whenFileIsWritten(TEMPLATE, "@param String name\n@template.tag.name(name)");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/nested.jte", "@param String name\nnested ${name}");
whenFileIsWritten("tag/name.jte", "@param String name\nHello @template.tag.nested(name)!!!");

thenTemplateOutputIs("Hello nested hot reload!!!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/nested.jte", "@param String name\nnested, ${name}");

thenTemplateOutputIs("Hello nested, hot reload!!!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/beforeNested.jte", "@param String name\nbefore ${name}.");
whenFileIsWritten("tag/name.jte", "@param String name\nHello @template.tag.beforeNested(name) @template.tag.nested(name)!!!");

thenTemplateOutputIs("Hello before hot reload. nested, hot reload!!!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/beforeNested.jte", "@param String name\nbefore2 ${name}.");

thenTemplateOutputIs("Hello before2 hot reload. nested, hot reload!!!");
Expand All @@ -125,18 +113,15 @@ void newDependencyAddedAndDeleted() {
whenFileIsWritten(TEMPLATE, "@param String name\n@template.tag.name(name)");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/nested.jte", "@param String name\nnested ${name}");
whenFileIsWritten("tag/name.jte", "@param String name\nHello @template.tag.nested(name)!!!");

thenTemplateOutputIs("Hello nested hot reload!!!");

waitUntilFileChangesPossible();
whenFileIsWritten("tag/nested.jte", "@param String name\nnested, ${name}");

thenTemplateOutputIs("Hello nested, hot reload!!!");

waitUntilFileChangesPossible();
whenFileIsDeleted("tag/nested.jte");
whenFileIsWritten("tag/name.jte", "@param String name\nHello ${name}!!!");

Expand All @@ -149,8 +134,6 @@ void paramWithDefaultValueAdded() {
whenFileIsWritten(TEMPLATE, "@param String name\n@template.tag.name(name)");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();

whenFileIsWritten("tag/name.jte", "@param String name\n@param String suffix = \"?!\"\nHello ${name}${suffix}");
thenTemplateOutputIs("Hello hot reload?!");
}
Expand All @@ -162,8 +145,6 @@ void binaryContent_oneCharacterReplaced() {
whenFileIsWritten(TEMPLATE, "@param String name\n@template.tag.name(name)");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();

whenFileIsWritten("tag/name.jte", "@param String name\nHello ${name}?");
thenTemplateOutputIs("Hello hot reload?");
}
Expand All @@ -173,8 +154,6 @@ void cacheIsNotUsedAfterCompilationError() {
whenFileIsWritten(TEMPLATE, "@param String name\nHello ${name}!");
thenTemplateOutputIs("Hello hot reload!");

waitUntilFileChangesPossible();

whenFileIsWritten(TEMPLATE, "@param String name\nHello ${name2}");
thenCompilationFails();
thenCompilationFails(); // Should continue failing and not use an old template from the cache
Expand Down Expand Up @@ -222,7 +201,4 @@ private void whenFileIsDeleted(String name) {
}
}

private void waitUntilFileChangesPossible() {
TestUtils.sleepIfLegacyJavaVersion(1000); // File.getLastModified() only has seconds precision on most Java 8 versions
}
}
16 changes: 1 addition & 15 deletions jte/src/test/java/gg/jte/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,7 @@ public class TestUtils {

private static final double JAVA_VERSION = Double.parseDouble(System.getProperty("java.specification.version", "0"));

public static boolean isLegacyJavaVersion() {
return JAVA_VERSION < 11;
}

public static boolean isInstanceOfPatternMatchingJavaVersion() {
return JAVA_VERSION >= 14;
}

public static void sleepIfLegacyJavaVersion(long millis) {
if (isLegacyJavaVersion()) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return JAVA_VERSION >= 14; // Not really needed since we compile with jdk 17, but leave as pattern for the next Java version features.
}
}

0 comments on commit a51d63d

Please sign in to comment.