From f422534cd4cf1ba32523c9fc798c207065038ca5 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 6 Sep 2018 08:40:23 -0400 Subject: java: add pom.xml, mv sources to src/main/java/org/pablotron, add src/test, add initial junit tests, update makefile and .gitignore --- .../org/pablotron/luigi/tests/TemplateTest.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java (limited to 'java/src/test') diff --git a/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java b/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java new file mode 100644 index 0000000..5ff9ede --- /dev/null +++ b/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java @@ -0,0 +1,69 @@ +import java.util.Map; +import java.util.HashMap; + +import org.pablotron.luigi.LuigiError; +import org.pablotron.luigi.Template; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; + + +public final class TemplateTest { + private static final Map TEST_ARGS = new HashMap() {{ + put("bar", "foo"); + }}; + + private static final Map TEST_MULTIPLE_ARGS = new HashMap() {{ + put("bar", "foo"); + put("baz", "bar"); + }}; + + @Test + public void testNew() throws LuigiError { + final Template t = new Template(""); + + assertNotNull(t); + } + + @Test + public void testRun() throws LuigiError { + final Template t = new Template("foo%{bar}"); + final String r = t.run(TEST_ARGS); + + assertEquals("foofoo", r); + } + + @Test + public void testMultipleKeys() throws LuigiError { + final Template t = new Template("foo%{bar}%{baz}"); + final String r = t.run(TEST_MULTIPLE_ARGS); + + assertEquals("foofoobar", r); + } + + @Test + public void testWhitespace() throws LuigiError { + final Template t = new Template("%{ bar}%{ bar }%{bar }"); + final String r = t.run(TEST_ARGS); + + assertEquals("foofoofoo", r); + } + + @Test + public void testNewlines() throws LuigiError { + final Template t = new Template("%{\nbar}%{\n bar\n }%{bar\n}"); + final String r = t.run(TEST_ARGS); + + assertEquals("foofoofoo", r); + } + + @Test + public void testToString() throws LuigiError { + final Template t = new Template("foo%{bar}"); + final String r = t.toString(); + + assertEquals("foo%{bar}", r); + } +}; -- cgit v1.2.3