diff --git a/jte-models/src/main/jte/statictemplates/kmethod.jte b/jte-models/src/main/jte/statictemplates/kmethod.jte index 329805c7..a2ec9e23 100644 --- a/jte-models/src/main/jte/statictemplates/kmethod.jte +++ b/jte-models/src/main/jte/statictemplates/kmethod.jte @@ -8,8 +8,8 @@ !{String outputClass = config.contentType() == ContentType.Html ? "HtmlTemplateOutput" : "TemplateOutput";} override fun ${Util.methodName(template)}(${Util.kotlinTypedParams(template, false)}): JteModel = StaticJteModel<${outputClass}>( ContentType.${config.contentType()}, - { output, interceptor -> ${template.className()}.render(output, interceptor${Util.paramNames(template)}) }, + { output, interceptor -> ${template.fullyQualifiedClassName()}.render(output, interceptor${Util.paramNames(template)}) }, "${template.name()}", "${template.packageName()}", - ${template.className()}.JTE_LINE_INFO + ${template.fullyQualifiedClassName()}.JTE_LINE_INFO ) diff --git a/jte-models/src/test/java/gg/jte/models/generator/TestModelExtension.java b/jte-models/src/test/java/gg/jte/models/generator/TestModelExtension.java index 09668992..fe8b9575 100644 --- a/jte-models/src/test/java/gg/jte/models/generator/TestModelExtension.java +++ b/jte-models/src/test/java/gg/jte/models/generator/TestModelExtension.java @@ -256,10 +256,10 @@ class StaticTemplates : Templates { \s override fun hello(content: gg.jte.Content): JteModel = StaticJteModel( ContentType.Plain, - { output, interceptor -> JtehelloGenerated.render(output, interceptor, content) }, + { output, interceptor -> test.myktemplates.JtehelloGenerated.render(output, interceptor, content) }, "hello.kte", "test.myktemplates", - JtehelloGenerated.JTE_LINE_INFO + test.myktemplates.JtehelloGenerated.JTE_LINE_INFO ) }"""), @@ -339,10 +339,10 @@ class StaticTemplates : Templates { \s override fun hello(): JteModel = StaticJteModel( ContentType.Plain, - { output, interceptor -> JtehelloGenerated.render(output, interceptor) }, + { output, interceptor -> test.myktemplates.JtehelloGenerated.render(output, interceptor) }, "hello.kte", "test.myktemplates", - JtehelloGenerated.JTE_LINE_INFO + test.myktemplates.JtehelloGenerated.JTE_LINE_INFO ) }"""), diff --git a/test/jte-runtime-cp-test-gradle-convention/src/test/java/gg/jte/TemplateEngineTest.java b/test/jte-runtime-cp-test-gradle-convention/src/test/java/gg/jte/TemplateEngineTest.java index d75c49da..d7c8f0d7 100644 --- a/test/jte-runtime-cp-test-gradle-convention/src/test/java/gg/jte/TemplateEngineTest.java +++ b/test/jte-runtime-cp-test-gradle-convention/src/test/java/gg/jte/TemplateEngineTest.java @@ -46,7 +46,7 @@ void templateNotFound() { void exceptionLineNumber1() { thenRenderingFailsWithException("exceptionLineNumber1.jte") .hasCauseInstanceOf(NullPointerException.class) - .hasMessage("Failed to render exceptionLineNumber1.jte, error at exceptionLineNumber1.jte:5"); + .hasMessage("Failed to render exceptionLineNumber1.kte, error at exceptionLineNumber1.kte:5"); } @Test diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/build.gradle b/test/jte-runtime-cp-test-models-gradle-kotlin/build.gradle new file mode 100644 index 00000000..ff1d1d8a --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/build.gradle @@ -0,0 +1,38 @@ +plugins { + id("org.jetbrains.kotlin.jvm") version "1.9.22" + id("gg.jte.gradle") version("3.1.8-SNAPSHOT") +} + +repositories { + mavenCentral() + mavenLocal() +} + +group = "gg.jte.testgroup" + +test { + useJUnitPlatform() +} + +dependencies { + implementation("gg.jte:jte-runtime:3.1.8-SNAPSHOT") + implementation("gg.jte:jte-kotlin:3.1.8-SNAPSHOT") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.22") + + testImplementation("org.assertj:assertj-core:3.23.1") + testImplementation("org.junit.jupiter:junit-jupiter:5.6.2") + + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.6.2" + jteGenerate "gg.jte:jte-models:3.1.8-SNAPSHOT" +} + +jte { + generate() + binaryStaticContent = true + jteExtension("gg.jte.models.generator.ModelExtension") { + language = "Kotlin" + implementationAnnotation = "@test.Dummy" + includePattern = ".*" + excludePattern = ".*Excluded.*" + } +} diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar b/test/jte-runtime-cp-test-models-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..ccebba77 Binary files /dev/null and b/test/jte-runtime-cp-test-models-gradle-kotlin/gradle/wrapper/gradle-wrapper.jar differ diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties b/test/jte-runtime-cp-test-models-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..fc10b601 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/gradlew b/test/jte-runtime-cp-test-models-gradle-kotlin/gradlew new file mode 100755 index 00000000..79a61d42 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/gradlew.bat b/test/jte-runtime-cp-test-models-gradle-kotlin/gradlew.bat new file mode 100644 index 00000000..93e3f59f --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/settings.gradle b/test/jte-runtime-cp-test-models-gradle-kotlin/settings.gradle new file mode 100644 index 00000000..e72c0c2f --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + mavenLocal() + mavenCentral() + gradlePluginPortal() + } +} + +buildCache { + local { + directory "${System.getProperty("test.build.cache.dir")}" + } +} diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/exceptionLineNumber1.kte b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/exceptionLineNumber1.kte new file mode 100644 index 00000000..46717530 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/exceptionLineNumber1.kte @@ -0,0 +1,3 @@ +@param model: test.Model + +${model.thatThrows()} \ No newline at end of file diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/helloWorld.kte b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/helloWorld.kte new file mode 100644 index 00000000..51399e63 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/helloWorld.kte @@ -0,0 +1,2 @@ +@param model: test.Model +${model.hello} World \ No newline at end of file diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/layout.kte b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/layout.kte new file mode 100644 index 00000000..5b6d97a8 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/layout.kte @@ -0,0 +1,4 @@ +@param content: gg.jte.Content +Header +${content} +Footer diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/main.kte b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/main.kte new file mode 100644 index 00000000..97c4a9dd --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/main.kte @@ -0,0 +1,3 @@ +@template.layout(content = @` +Main +`) \ No newline at end of file diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/modelExampleExcluded.kte b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/modelExampleExcluded.kte new file mode 100644 index 00000000..e69de29b diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/tag/unused.kte b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/tag/unused.kte new file mode 100644 index 00000000..a1e6838c --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/jte/tag/unused.kte @@ -0,0 +1,3 @@ +@param param1: String +@param param2: String +One is ${param1}, two is ${param2}. \ No newline at end of file diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/kotlin/test/Dummy.kt b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/kotlin/test/Dummy.kt new file mode 100644 index 00000000..aaa63782 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/kotlin/test/Dummy.kt @@ -0,0 +1,6 @@ +package test + +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.CLASS) +annotation class Dummy \ No newline at end of file diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/kotlin/test/Model.kt b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/kotlin/test/Model.kt new file mode 100644 index 00000000..43cd8268 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/main/kotlin/test/Model.kt @@ -0,0 +1,7 @@ +package test + +@Suppress("unused") +class Model { + val hello: String = "Hello" + fun thatThrows(): String = throw java.lang.NullPointerException("Oops") +} \ No newline at end of file diff --git a/test/jte-runtime-cp-test-models-gradle-kotlin/src/test/kotlin/gg/jte/TemplateEngineTest.kt b/test/jte-runtime-cp-test-models-gradle-kotlin/src/test/kotlin/gg/jte/TemplateEngineTest.kt new file mode 100644 index 00000000..76304034 --- /dev/null +++ b/test/jte-runtime-cp-test-models-gradle-kotlin/src/test/kotlin/gg/jte/TemplateEngineTest.kt @@ -0,0 +1,94 @@ +package gg.jte + +import gg.jte.generated.precompiled.Templates +import gg.jte.generated.precompiled.DynamicTemplates +import gg.jte.generated.precompiled.StaticTemplates + +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.MethodSource + +import org.assertj.core.api.Assertions +import org.assertj.core.api.ThrowableAssert + +import java.util.stream.Stream +import java.util.function.Predicate + +/** + * To run these tests, you first need to run the gradle precompile task: + */ +class TemplateEngineTest { + val model: test.Model = test.Model() + + @ParameterizedTest + @MethodSource("templates") + fun helloWorld(templates: Templates) { + val output: String = templates.helloWorld(model).render() + Assertions.assertThat(output).isEqualTo("Hello World") + } + + @ParameterizedTest + @MethodSource("templates") + fun exceptionLineNumber1(templates: Templates) { + val cause: Throwable = + Assertions.catchThrowable(ThrowableAssert.ThrowingCallable { + templates.exceptionLineNumber1( + model + ).render() + }) + Assertions.assertThat(cause).isInstanceOf(TemplateException::class.java) + .hasCauseInstanceOf(NullPointerException::class.java) + .hasMessage("Failed to render exceptionLineNumber1.kte, error at exceptionLineNumber1.kte:3") + } + + @ParameterizedTest + @MethodSource("templates") + fun unusedTag(templates: Templates) { + val output: String = templates.tagUnused("One", "Two").render() + Assertions.assertThat(output).isEqualTo("One is One, two is Two.") + } + + @ParameterizedTest + @MethodSource("templates") + fun normalContent(templates: Templates) { + val output: String = templates.main().render() + Assertions.assertThat(output).containsIgnoringWhitespaces("Header", "Main", "Footer") + } + + @ParameterizedTest + @MethodSource("templates") + fun excludedTemplates(templates: Templates) { + Assertions.assertThat(templates::class.java.getMethods()).noneMatch { m -> m.getName().contains("Exclude") } + } + + @ParameterizedTest + @MethodSource("templates") + fun nestedContent(templates: Templates) { + val output: String = templates.layout(templates.helloWorld(model)).render() + Assertions.assertThat(output) + .containsIgnoringWhitespaces("Header", "Hello World", "Footer") + } + + @ParameterizedTest + @MethodSource("templates") + fun hasAnnotation(templates: Templates) { + val clazz: Class = templates::class.java + val annotations: Array = clazz.getDeclaredAnnotations() + Assertions.assertThat(annotations) + .anyMatch(Predicate { a: Annotation? -> a is test.Dummy }) + } + + companion object { + private val templateEngine: TemplateEngine = TemplateEngine.createPrecompiled(ContentType.Html) + + private val staticTemplates: Templates = StaticTemplates() + private val dynamicTemplates: Templates = DynamicTemplates(templateEngine) + @JvmStatic + fun templates(): Stream { + return Stream.of( + Arguments.of(staticTemplates), + Arguments.of(dynamicTemplates) + ) + } + } +} \ No newline at end of file