Added some tests
This commit is contained in:
parent
b92b01a6cc
commit
76256f7468
13 changed files with 162 additions and 1 deletions
27
.idea/misc.xml
generated
27
.idea/misc.xml
generated
|
@ -17,6 +17,33 @@
|
||||||
<pattern value="rife2.render.Year" />
|
<pattern value="rife2.render.Year" />
|
||||||
<pattern value="rife2.render.EncodeBase64" />
|
<pattern value="rife2.render.EncodeBase64" />
|
||||||
<pattern value="rife2.render.EncodeUnicode" />
|
<pattern value="rife2.render.EncodeUnicode" />
|
||||||
|
<pattern value="rife.render.Capitalize" />
|
||||||
|
<pattern value="rife.render.EncodeBase64" />
|
||||||
|
<pattern value="rife.render.EncodeHtml" />
|
||||||
|
<pattern value="rife.render.EncodeHtmlEntities" />
|
||||||
|
<pattern value="rife.render.EncodeJson" />
|
||||||
|
<pattern value="rife.render.EncodeQp" />
|
||||||
|
<pattern value="rife.render.EncodeUnicode" />
|
||||||
|
<pattern value="rife.render.EncodeUrl" />
|
||||||
|
<pattern value="rife.render.EncodeXml" />
|
||||||
|
<pattern value="rife.render.ValueBean" method="getValue" />
|
||||||
|
<pattern value="rife.render.Lowercase" />
|
||||||
|
<pattern value="rife.render.Rot13" />
|
||||||
|
<pattern value="rife.render.SwapCase" />
|
||||||
|
<pattern value="rife.render.TestDateTime" />
|
||||||
|
<pattern value="rife.render.TestEncode" />
|
||||||
|
<pattern value="rife.render.Trim" />
|
||||||
|
<pattern value="rife.render.Uncapitalize" />
|
||||||
|
<pattern value="rife.render.Uppercase" />
|
||||||
|
<pattern value="rife.render.Year" />
|
||||||
|
<pattern value="rife.render.ValueBean" method="setValue" />
|
||||||
|
<pattern value="rife.render.TestDateTime" method="testDateIso" />
|
||||||
|
<pattern value="rife.render.TestDateTime" method="testDateTimeIso" />
|
||||||
|
<pattern value="rife.render.TestDateTime" method="testDateTimeRfc2822" />
|
||||||
|
<pattern value="rife.render.TestEncode" method="testEncodeUrl" />
|
||||||
|
<pattern value="rife.render.TestDateTime" method="testTimeIso" />
|
||||||
|
<pattern value="rife.render.TestDateTime" method="testYear" />
|
||||||
|
<pattern value="rife.render.ValueBean" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="PDMPlugin">
|
<component name="PDMPlugin">
|
||||||
|
|
|
@ -25,6 +25,7 @@ dependencies {
|
||||||
|
|
||||||
testImplementation(platform("org.junit:junit-bom:5.9.2"))
|
testImplementation(platform("org.junit:junit-bom:5.9.2"))
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
|
testImplementation("org.assertj:assertj-core:3.24.2")
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import rife.template.Template;
|
||||||
import rife.template.ValueRenderer;
|
import rife.template.ValueRenderer;
|
||||||
import rife.tools.Localization;
|
import rife.tools.Localization;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class SwapCase implements ValueRenderer {
|
||||||
* @param src the String to swap the case of
|
* @param src the String to swap the case of
|
||||||
* @return the modified String or null
|
* @return the modified String or null
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("PMD.AvoidReassigningLoopVariables")
|
||||||
public static String swapCase(final String src) {
|
public static String swapCase(final String src) {
|
||||||
if (src == null || src.isEmpty()) {
|
if (src == null || src.isEmpty()) {
|
||||||
return src;
|
return src;
|
||||||
|
|
57
lib/src/test/java/rife/render/TestDateTime.java
Normal file
57
lib/src/test/java/rife/render/TestDateTime.java
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 the original author or 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rife.render;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import rife.template.TemplateFactory;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
|
||||||
|
class TestDateTime {
|
||||||
|
@Test
|
||||||
|
void testDateIso() {
|
||||||
|
var t = TemplateFactory.HTML.get("dateIso");
|
||||||
|
assertThatCode(() -> DateIso.iso8601Formatter.parse(t.getContent())).doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDateTimeIso() {
|
||||||
|
var t = TemplateFactory.HTML.get("dateTimeIso");
|
||||||
|
assertThatCode(() -> DateTimeIso.iso8601Formatter.parse(t.getContent())).doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDateTimeRfc2822() {
|
||||||
|
var t = TemplateFactory.HTML.get("dateTimeRfc2822");
|
||||||
|
assertThatCode(() -> DateTimeRfc2822.rfc2822Formatter.parse(t.getContent())).doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTimeIso() {
|
||||||
|
var t = TemplateFactory.HTML.get("timeIso");
|
||||||
|
assertThatCode(() -> TimeIso.iso8601Formatter.parse(t.getContent())).doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testYear() {
|
||||||
|
var t = TemplateFactory.HTML.get("year");
|
||||||
|
var year = java.time.Year.now().toString();
|
||||||
|
assertThat(t.getContent()).isEqualTo(year + "<br>\n" + year);
|
||||||
|
}
|
||||||
|
}
|
34
lib/src/test/java/rife/render/TestEncode.java
Normal file
34
lib/src/test/java/rife/render/TestEncode.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 the original author or 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rife.render;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import rife.template.TemplateFactory;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
class TestEncode {
|
||||||
|
@Disabled("Until renderer can access beans")
|
||||||
|
@Test
|
||||||
|
void testEncodeUrl() {
|
||||||
|
var t = TemplateFactory.HTML.get("encodeUrl");
|
||||||
|
t.setBean(new ValueBean("a test &"));
|
||||||
|
var encodedValue = "a%20test%20%26";
|
||||||
|
assertThat(t.getContent()).isEqualTo(encodedValue + "<br>\n" + encodedValue);
|
||||||
|
}
|
||||||
|
}
|
34
lib/src/test/java/rife/render/ValueBean.java
Normal file
34
lib/src/test/java/rife/render/ValueBean.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2023 the original author or 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rife.render;
|
||||||
|
|
||||||
|
public class ValueBean {
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
ValueBean(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
1
lib/src/test/resources/templates/dateIso.html
Normal file
1
lib/src/test/resources/templates/dateIso.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{v render:rife.render.DateIso/}}
|
1
lib/src/test/resources/templates/dateTimeIso.html
Normal file
1
lib/src/test/resources/templates/dateTimeIso.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{v render:rife.render.DateTimeIso/}}
|
1
lib/src/test/resources/templates/dateTimeRfc2822.html
Normal file
1
lib/src/test/resources/templates/dateTimeRfc2822.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{v render:rife.render.DateTimeRfc2822/}}
|
2
lib/src/test/resources/templates/encodeUrl.html
Normal file
2
lib/src/test/resources/templates/encodeUrl.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
}<!--v render:rife.render.EncodeUrl:value/--><br>
|
||||||
|
{{v render:rife.render.EncodeUrl:value/}}
|
1
lib/src/test/resources/templates/timeIso.html
Normal file
1
lib/src/test/resources/templates/timeIso.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{v render:rife.render.TimeIso/}}
|
2
lib/src/test/resources/templates/year.html
Normal file
2
lib/src/test/resources/templates/year.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<!--v render:rife.render.Year/--><br>
|
||||||
|
{{v render:rife.render.Year/}}
|
Loading…
Add table
Add a link
Reference in a new issue