Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Aug 12, 2023
1 parent a57c5af commit 0796716
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified lib/bld/bld-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.1-SNAPSHOT
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.2-SNAPSHOT
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.0-SNAPSHOT
bld.extension-tests=com.uwyn.rife2:bld-tests-badge:1.2.0
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation=
Expand Down
15 changes: 12 additions & 3 deletions src/bld/java/rife/render/TemplateRenderersBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.extension.JacocoReportOperation;
import rife.bld.extension.PmdOperation;
import rife.bld.extension.TestsBadgeOperation;
import rife.bld.publish.PublishDeveloper;
import rife.bld.publish.PublishInfo;
import rife.bld.publish.PublishLicense;
import rife.bld.publish.PublishScm;

import java.io.IOException;
import java.util.List;

import static rife.bld.dependencies.Repository.*;
Expand Down Expand Up @@ -60,17 +62,24 @@ public TemplateRenderersBuild() {
scope(compile)
.include(dependency("com.uwyn.rife2", "rife2", version(1, 7, 0)));
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 9, 3)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0)))
.include(dependency("org.assertj:assertj-core:3.24.2"));
}

public static void main(String[] args) {
new TemplateRenderersBuild().start(args);
}

@BuildCommand(summary = "Generates Jacoco Reports")
public void jacoco() throws IOException {
new JacocoReportOperation()
.fromProject(this)
.execute();
}

@BuildCommand(summary = "Runs PMD analysis")
public void pmd() throws Exception {
public void pmd() {
new PmdOperation()
.fromProject(this)
.failOnViolation(true)
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/rife/render/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void testLowercase() {
var bean = new ValueBean("this IS a TEST.");
t.setBean(bean);
assertThat(t.getContent()).isEqualTo(bean.getValue() + ": this is a test.");
bean = new ValueBean("");
t.setBean(bean);
assertThat(t.getContent()).isEqualTo(bean.getValue() + ": ");
}

@Test
Expand All @@ -54,6 +57,8 @@ void testTrim() {
var t = TemplateFactory.TXT.get("trim");
t.setAttribute(FOO, "\t" + SAMPLE_TEXT + " \n");
assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT);
t.setAttribute(FOO, "");
assertThat(t.getContent()).isEmpty();
}

@Test
Expand All @@ -68,5 +73,7 @@ void testUppercase() {
var t = TemplateFactory.TXT.get("uppercase");
t.setAttribute("bar", SAMPLE_TEXT);
assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT.toUpperCase(Localization.getLocale()));
t.setAttribute("bar", "");
assertThat(t.getContent()).isEmpty();
}
}
4 changes: 3 additions & 1 deletion src/test/java/rife/render/TestFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ void testFormatCreditCard() {
t.setAttribute(TestCase.FOO, "374380141731053");
assertThat(t.getContent()).as("UK AMEX").isEqualTo("1053");
t.setAttribute(TestCase.FOO, "000000000000001");
assertThat(t.getContent()).isEmpty();
assertThat(t.getContent()).as("000000000000001").isEmpty();
t.setAttribute(TestCase.FOO, "");
assertThat(t.getContent()).as("").isEmpty();
}

@Test
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/rife/render/TestRenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ void testAbbreviate() {

assertThat(RenderUtils.abbreviate(TestCase.SAMPLE_TEXT, -1, "")).as("max=-1")
.isEqualTo(TestCase.SAMPLE_TEXT);

assertThat(RenderUtils.abbreviate("", 10, "")).as("").isEmpty();
}

@Test
void testEncode() {
var p = new Properties();
p.put(RenderUtils.ENCODING_PROPERTY, "blah");
assertThat(RenderUtils.encode(TestCase.SAMPLE_TEXT, p)).as("invalid encoding").isEqualTo(TestCase.SAMPLE_TEXT);
p.put(RenderUtils.ENCODING_PROPERTY, "json");
assertThat(RenderUtils.encode("This is a \"•test\"", p)).as("json").isEqualTo("This is a \\\"\\u2022test\\\"");
p.put(RenderUtils.ENCODING_PROPERTY, "html");
assertThat(RenderUtils.encode("<a test &>", p)).as("html").isEqualTo("&lt;a test &amp;&gt;");
p.put(RenderUtils.ENCODING_PROPERTY, "js");
Expand All @@ -52,8 +58,22 @@ void testEncode() {
assertThat(RenderUtils.encode("Joe's Café & Bar", p)).as("xml").isEqualTo("Joe&apos;s Café &amp; Bar");
}

@Test
void testEncodeJs() {
assertThat(RenderUtils.encodeJs("")).isEmpty();
}

@Test
void testFetchUrl() {
var s = "default";
assertThat(RenderUtils.fetchUrl("blah", s)).isEqualTo(s);
assertThat(RenderUtils.fetchUrl("https://www.google.com/404", s)).isEqualTo(s);
assertThat(RenderUtils.fetchUrl("https://www.notreallythere.com/", s)).isEqualTo(s);
}

@Test
void testHtmlEntities() {
assertThat(RenderUtils.htmlEntities("")).isEmpty();
assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN))
.isEqualTo("&#77;&#246;&#99;&#104;&#116;&#101;&#110;&#32;&#83;&#105;&#101;&#32;&#101;&#105;&#110;&#32;&#112;&#97;&#97;&#114;&#32;&#196;&#112;&#102;&#101;&#108;&#63;");
}
Expand All @@ -62,6 +82,8 @@ void testHtmlEntities() {
void testMask() {
var foo = "4342256562440179";

assertThat(RenderUtils.mask("", " ", 2, false)).isEmpty();

assertThat(RenderUtils.mask(foo, "?", 4, false)).as("mask=?")
.isEqualTo("????????????0179");

Expand All @@ -74,18 +96,26 @@ void testMask() {

@Test
void testNormalize() {
assertThat(RenderUtils.normalize("")).isEmpty();
assertThat(RenderUtils.normalize(SAMPLE_GERMAN)).isEqualTo("mochten-sie-ein-paar-apfel");
}

@Test
void testQrCode() {
assertThat(RenderUtils.qrCode("", "12")).isEmpty();
}

@Test
void testRot13() {
var encoded = "Zöpugra Fvr rva cnne Äcsry?";
assertThat(RenderUtils.rot13("")).isEmpty();
assertThat(RenderUtils.rot13(SAMPLE_GERMAN)).as("encode").isEqualTo(encoded);
assertThat(RenderUtils.rot13(encoded)).as("decode").isEqualTo(SAMPLE_GERMAN);
}

@Test
void testSwapCase() {
assertThat(RenderUtils.swapCase("")).isEmpty();
assertThat(RenderUtils.swapCase(SAMPLE_GERMAN)).isEqualTo("mÖCHTEN sIE EIN PAAR äPFEL?");
}

Expand Down

0 comments on commit 0796716

Please sign in to comment.