Moved from Gradle to bld
This commit is contained in:
parent
5df56b7820
commit
630b57b604
108 changed files with 447 additions and 786 deletions
39
src/test/java/rife/render/DisableOnCiCondition.java
Normal file
39
src/test/java/rife/render/DisableOnCiCondition.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
/**
|
||||
* Disables tests on CI condition.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class DisableOnCiCondition implements ExecutionCondition {
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||
if (System.getenv("CI") != null) {
|
||||
return ConditionEvaluationResult.disabled("Test disabled on CI");
|
||||
} else {
|
||||
return ConditionEvaluationResult.enabled("Test enabled");
|
||||
}
|
||||
}
|
||||
}
|
37
src/test/java/rife/render/DisabledOnCi.java
Normal file
37
src/test/java/rife/render/DisabledOnCi.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.extension.ExtendWith;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Disables tests on CI annotation.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ExtendWith(DisableOnCiCondition.class)
|
||||
public @interface DisabledOnCi {
|
||||
}
|
72
src/test/java/rife/render/TestCase.java
Normal file
72
src/test/java/rife/render/TestCase.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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 rife.tools.Localization;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestCase {
|
||||
static final String FOO = "foo";
|
||||
static final String SAMPLE_TEXT = "This is a test.";
|
||||
|
||||
@Test
|
||||
void testCapitalize() {
|
||||
var t = TemplateFactory.TXT.get("capitalize");
|
||||
t.setAttribute(FOO, SAMPLE_TEXT.toLowerCase(Localization.getLocale()));
|
||||
assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLowercase() {
|
||||
var t = TemplateFactory.TXT.get("lowercase");
|
||||
var bean = new ValueBean("this IS a TEST.");
|
||||
t.setBean(bean);
|
||||
assertThat(t.getContent()).isEqualTo(bean.getValue() + ": this is a test.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSwapCase() {
|
||||
var t = TemplateFactory.TXT.get("swapCase");
|
||||
t.setAttribute(FOO, "tHiS iS a TeSt");
|
||||
assertThat(t.getContent()).isEqualTo("ThIs Is A tEsT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTrim() {
|
||||
var t = TemplateFactory.TXT.get("trim");
|
||||
t.setAttribute(FOO, "\t" + SAMPLE_TEXT + " \n");
|
||||
assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUncapitalize() {
|
||||
var t = TemplateFactory.TXT.get("uncapitalize");
|
||||
t.setAttribute(FOO, SAMPLE_TEXT);
|
||||
assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT.toLowerCase(Localization.getLocale()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUppercase() {
|
||||
var t = TemplateFactory.TXT.get("uppercase");
|
||||
t.setAttribute("bar", SAMPLE_TEXT);
|
||||
assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT.toUpperCase(Localization.getLocale()));
|
||||
}
|
||||
}
|
72
src/test/java/rife/render/TestDateTime.java
Normal file
72
src/test/java/rife/render/TestDateTime.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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 testBestTime() {
|
||||
var t = TemplateFactory.HTML.get("beatTime");
|
||||
assertThat(t.getContent()).matches("@\\d{3}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDateIso() {
|
||||
var t = TemplateFactory.HTML.get("dateIso");
|
||||
assertThatCode(() -> RenderUtils.ISO_8601_DATE_FORMATTER.parse(t.getContent())).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDateTimeIso() {
|
||||
var t = TemplateFactory.HTML.get("dateTimeIso");
|
||||
assertThatCode(() -> RenderUtils.ISO_8601_FORMATTER.parse(t.getContent())).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDateTimeRfc2822() {
|
||||
var t = TemplateFactory.HTML.get("dateTimeRfc2822");
|
||||
assertThatCode(() -> RenderUtils.RFC_2822_FORMATTER.parse(t.getContent())).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDateTimeUtc() {
|
||||
var t = TemplateFactory.HTML.get("dateTimeUtc");
|
||||
var content = t.getContent();
|
||||
assertThatCode(() -> RenderUtils.ISO_8601_FORMATTER.parse(content)).doesNotThrowAnyException();
|
||||
assertThat(content).endsWith("Z");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTimeIso() {
|
||||
var t = TemplateFactory.HTML.get("timeIso");
|
||||
assertThatCode(() -> RenderUtils.ISO_8601_TIME_FORMATTER.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>" + year);
|
||||
}
|
||||
}
|
121
src/test/java/rife/render/TestEncode.java
Normal file
121
src/test/java/rife/render/TestEncode.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
class TestEncode {
|
||||
@Test
|
||||
void testEncodeBase64() {
|
||||
var t = TemplateFactory.TXT.get("encodeBase64");
|
||||
t.setValue(TestCase.FOO, TestCase.SAMPLE_TEXT);
|
||||
assertThat(t.getContent()).isEqualTo(t.getValue(TestCase.FOO) + ": VGhpcyBpcyBhIHRlc3Qu");
|
||||
|
||||
t = TemplateFactory.HTML.get("encodeBase64");
|
||||
t.setValue(TestCase.FOO, TestCase.SAMPLE_TEXT + " URL Encoded.");
|
||||
assertThat(t.getContent()).as("with URL encoding").contains("VGhpcyBpcyBhIHRlc3QuIFVSTCBFbmNvZGVkLg%3D%3D");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeHtml() {
|
||||
var t = TemplateFactory.HTML.get("encodeHtml");
|
||||
t.setAttribute(TestCase.FOO, "<a test &>");
|
||||
assertThat(t.getContent()).isEqualTo("<a test &>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeHtmlEntities() {
|
||||
var t = TemplateFactory.HTML.get("encodeHtmlEntities");
|
||||
t.setAttribute(TestCase.FOO, "john@doe.com");
|
||||
assertThat(t.getContent()).isEqualTo(
|
||||
"<a href=\"mailto:john@doe.com\">Email</a>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeJs() {
|
||||
var t = TemplateFactory.TXT.get("encodeJs");
|
||||
t.setAttribute(TestCase.FOO, "'\"\\/");
|
||||
assertThat(t.getContent()).isEqualTo("\\'\\\"\\\\\\/");
|
||||
|
||||
t = TemplateFactory.HTML.get("encodeJs");
|
||||
t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"');
|
||||
assertThat(t.getContent()).as("with unicode")
|
||||
.isEqualTo("\\u005C\\u0022\\u0054\\u0068\\u0069\\u0073\\u0020\\u0069\\u0073\\u0020\\u0061\\u0020\\u0074\\u0065\\u0073\\u0074\\u002E\\u005C\\u0022");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeJson() {
|
||||
var t = TemplateFactory.JSON.get("encodeJson");
|
||||
t.setAttribute(TestCase.FOO, "This is a \"•test\"");
|
||||
assertThat(t.getContent()).isEqualTo("{\n \"foo\": \"This is a \\\"\\u2022test\\\"\"\n}");
|
||||
|
||||
t = TemplateFactory.HTML.get("encodeJson");
|
||||
t.setAttribute(TestCase.FOO, "\"<test>\"");
|
||||
assertThat(t.getContent()).as("with html").isEqualTo("\\"<test>\\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeRot13() {
|
||||
var t = TemplateFactory.TXT.get("rot13");
|
||||
var rot13 = "Guvf vf n grfg.";
|
||||
|
||||
// Encode
|
||||
var bean = new ValueBean(TestCase.SAMPLE_TEXT);
|
||||
t.setBean(bean);
|
||||
assertThat(t.getContent()).as("encode").isEqualTo(bean.getValue() + ": " + rot13);
|
||||
|
||||
// Decode
|
||||
t.setValue("value", rot13);
|
||||
assertThat(t.getContent()).as("decode").isEqualTo(rot13 + ": " + TestCase.SAMPLE_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeUnicode() {
|
||||
var t = TemplateFactory.TXT.get("encodeUnicode");
|
||||
t.setAttribute(TestCase.FOO, TestCase.SAMPLE_TEXT);
|
||||
assertThat(t.getContent()).isEqualTo(
|
||||
"\\u0054\\u0068\\u0069\\u0073\\u0020\\u0069\\u0073\\u0020\\u0061\\u0020\\u0074\\u0065\\u0073\\u0074\\u002E");
|
||||
|
||||
t = TemplateFactory.HTML.get("encodeUnicode");
|
||||
t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"');
|
||||
assertThat(t.getContent()).as("with js")
|
||||
.contains("'\\\\u0022\\\\u0054\\\\u0068\\\\u0069\\\\u0073\\\\u0020\\\\u0069\\\\u0073\\\\u0020\\\\u0061\\\\u0020\\\\u0074\\\\u0065\\\\u0073\\\\u0074\\\\u002E\\\\u0022'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeUrl() {
|
||||
var t = TemplateFactory.HTML.get("encodeUrl");
|
||||
t.setAttribute(TestCase.FOO, "a test &");
|
||||
assertThat(t.getContent()).isEqualTo("<a href=\"https://example.com/a%20test%20%26\">a test &</a>");
|
||||
|
||||
t = TemplateFactory.HTML.get("encodeUrlwithUnicode");
|
||||
t.setAttribute(TestCase.FOO, "a=test");
|
||||
assertThat(t.getContent()).as("with unicode")
|
||||
.contains("https://foo.com/\\u0061\\u0025\\u0033\\u0044\\u0074\\u0065\\u0073\\u0074");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncodeXml() {
|
||||
var t = TemplateFactory.XML.get("encodeXml");
|
||||
t.setAttribute(TestCase.FOO, "a test &");
|
||||
assertThat(t.getContent()).isEqualTo("<test>\n <foo>a test &</foo>\n</test>");
|
||||
}
|
||||
}
|
118
src/test/java/rife/render/TestFormat.java
Normal file
118
src/test/java/rife/render/TestFormat.java
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.template.TemplateFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestFormat {
|
||||
@Test
|
||||
void testAbbreviate() {
|
||||
var t = TemplateFactory.HTML.get("abbreviate");
|
||||
t.setAttribute(TestCase.FOO, TestCase.SAMPLE_TEXT);
|
||||
assertThat(t.getContent()).as("activate.html").endsWith("…").hasSize(19);
|
||||
|
||||
t = TemplateFactory.TXT.get("abbreviate");
|
||||
t.setAttribute(TestCase.FOO, TestCase.SAMPLE_TEXT);
|
||||
assertThat(t.getContent()).as("activate.txt").endsWith("...").hasSize(8);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFormatCreditCard() {
|
||||
var t = TemplateFactory.TXT.get("formatCreditCard");
|
||||
t.setAttribute(TestCase.FOO, "4342 2565 6244 0179");
|
||||
assertThat(t.getContent()).as("US VISA").isEqualTo("0179");
|
||||
t.setAttribute(TestCase.FOO, "5130-3899-9169-8324");
|
||||
assertThat(t.getContent()).as("FR MASTERCARD").isEqualTo("8324");
|
||||
t.setAttribute(TestCase.FOO, "374380141731053");
|
||||
assertThat(t.getContent()).as("UK AMEX").isEqualTo("1053");
|
||||
t.setAttribute(TestCase.FOO, "000000000000001");
|
||||
assertThat(t.getContent()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMask() {
|
||||
var t = TemplateFactory.HTML.get("mask");
|
||||
var foo = "374380141731053";
|
||||
t.setAttribute(TestCase.FOO, foo);
|
||||
assertThat(t.getContent()).as("mask.html")
|
||||
.isEqualTo("3743•••••••••••");
|
||||
|
||||
t = TemplateFactory.TXT.get("mask");
|
||||
t.setAttribute(TestCase.FOO, foo);
|
||||
assertThat(t.getContent()).as("mask.txt").isEqualTo("***************");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNormalize() {
|
||||
var t = TemplateFactory.HTML.get("normalize");
|
||||
var foo = "News for January 6, 2023 (Paris)";
|
||||
t.setValue(TestCase.FOO, foo);
|
||||
assertThat(t.getContent()).isEqualTo("<a href=\"news/20230106/news-for-january-6-2023-paris\">"
|
||||
+ foo + "</a>");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisabledOnCi
|
||||
void testQrCode() {
|
||||
var t = TemplateFactory.SVG.get("qrCode");
|
||||
var foo = "https://example.com/";
|
||||
t.setAttribute(TestCase.FOO, foo);
|
||||
assertThat(t.getContent()).startsWith("<?xml").contains("<desc>" + foo + "</desc").contains("width=\"200\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisabledOnCi
|
||||
void testShortenUrl() {
|
||||
var t = TemplateFactory.HTML.get("shortenUrl");
|
||||
var url = "https://example.com/";
|
||||
var shortUrl = "https://is.gd/AG3Hwv";
|
||||
t.setValue(TestCase.FOO, url);
|
||||
assertThat(t.getContent()).isEqualTo(String.format("<a href=\"%s\">%s</a>", shortUrl, url));
|
||||
t.setValue(TestCase.FOO, TestCase.FOO);
|
||||
assertThat(t.getContent()).isEqualTo("<a href=\"foo\">foo</a>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUptime() {
|
||||
var t = TemplateFactory.TXT.get("uptime");
|
||||
assertThat(t.getContent()).as("uptime.txt").isEqualTo("0 minute\n0 minuto\n0 minute");
|
||||
|
||||
t = TemplateFactory.HTML.get("uptime");
|
||||
t.setAttribute(Uptime.class.getName(), 547800300076L);
|
||||
assertThat(t.getContent()).as("uptime.html")
|
||||
.isEqualTo("17 années, 4 mois, 2 semaines, 1 jour, 6 heures, 45 minutes");
|
||||
t.setAttribute(Uptime.class.getName(), 120000L);
|
||||
assertThat(t.getContent()).as("uptime.html: 2 min").isEqualTo("2 minutes");
|
||||
|
||||
t = TemplateFactory.JSON.get("uptime");
|
||||
t.setAttribute(Uptime.class.getName(), 5999964460000L);
|
||||
assertThat(t.getContent()).as("uptime.json")
|
||||
.isEqualTo("190 years 3 months 4 days 47 minutes");
|
||||
t.setAttribute(Uptime.class.getName(), 34822860000L);
|
||||
assertThat(t.getContent()).as("uptime.json: 1 year...")
|
||||
.isEqualTo("1 year 1 month 1 week 1 day 1 hour 1 minute");
|
||||
|
||||
t = TemplateFactory.TXT.get("uptime2");
|
||||
t.setAttribute(Uptime.class.getName(), 547800388076L);
|
||||
assertThat(t.getContent()).as("uptime2.txt").isEqualTo("17YRS-4MOS-2WKS-1D-6H-46M");
|
||||
}
|
||||
}
|
100
src/test/java/rife/render/TestRenderUtils.java
Normal file
100
src/test/java/rife/render/TestRenderUtils.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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 java.util.Properties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestRenderUtils {
|
||||
static final String SAMPLE_GERMAN = "Möchten Sie ein paar Äpfel?";
|
||||
|
||||
@Test
|
||||
void testAbbreviate() {
|
||||
assertThat(RenderUtils.abbreviate(TestCase.SAMPLE_TEXT, 9, "")).as("max=9")
|
||||
.isEqualTo("This is a");
|
||||
|
||||
assertThat(RenderUtils.abbreviate(TestCase.SAMPLE_TEXT, 0, "")).as("max=0").isEmpty();
|
||||
|
||||
assertThat(RenderUtils.abbreviate(TestCase.SAMPLE_TEXT, -1, "")).as("max=-1")
|
||||
.isEqualTo(TestCase.SAMPLE_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEncode() {
|
||||
var p = new Properties();
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "html");
|
||||
assertThat(RenderUtils.encode("<a test &>", p)).as("html").isEqualTo("<a test &>");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "js");
|
||||
assertThat(RenderUtils.encode("\"test'", p)).as("js").isEqualTo("\\\"test\\'");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "unicode");
|
||||
assertThat(RenderUtils.encode("test", p)).as("unicode").isEqualTo("\\u0074\\u0065\\u0073\\u0074");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "url");
|
||||
assertThat(RenderUtils.encode("a = test", p)).as("url").isEqualTo("a%20%3D%20test");
|
||||
p.put(RenderUtils.ENCODING_PROPERTY, "xml");
|
||||
assertThat(RenderUtils.encode("Joe's Café & Bar", p)).as("xml").isEqualTo("Joe's Café & Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHtmlEntities() {
|
||||
assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN))
|
||||
.isEqualTo("Möchten Sie ein paar Äpfel?");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMask() {
|
||||
var foo = "4342256562440179";
|
||||
|
||||
assertThat(RenderUtils.mask(foo, "?", 4, false)).as("mask=?")
|
||||
.isEqualTo("????????????0179");
|
||||
|
||||
assertThat(RenderUtils.mask(foo, "-", 22, true)).as("unmasked=22")
|
||||
.isEqualTo("----------------");
|
||||
|
||||
assertThat(RenderUtils.mask(foo, "•", -1, false)).as("mask=•")
|
||||
.isEqualTo("••••••••••••••••");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNormalize() {
|
||||
assertThat(RenderUtils.normalize(SAMPLE_GERMAN)).isEqualTo("mochten-sie-ein-paar-apfel");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRot13() {
|
||||
var encoded = "Zöpugra Fvr rva cnne Äcsry?";
|
||||
assertThat(RenderUtils.rot13(SAMPLE_GERMAN)).as("encode").isEqualTo(encoded);
|
||||
assertThat(RenderUtils.rot13(encoded)).as("decode").isEqualTo(SAMPLE_GERMAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSwapCase() {
|
||||
assertThat(RenderUtils.swapCase(SAMPLE_GERMAN)).isEqualTo("mÖCHTEN sIE EIN PAAR äPFEL?");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateCreditCard() {
|
||||
assertThat(RenderUtils.validateCreditCard("4505 4672 3366 6430")).as("visa").isTrue();
|
||||
assertThat(RenderUtils.validateCreditCard("5189-5923-3915-0425")).as("mastercard").isTrue();
|
||||
assertThat(RenderUtils.validateCreditCard("3433634926643302")).as("amex").isTrue();
|
||||
assertThat(RenderUtils.validateCreditCard("6011 1076-8252 0629")).as("discover").isTrue();
|
||||
assertThat(RenderUtils.validateCreditCard("0123456789012345")).as("invalid").isFalse();
|
||||
}
|
||||
}
|
34
src/test/java/rife/render/ValueBean.java
Normal file
34
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue