aboutsummaryrefslogtreecommitdiff
path: root/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/test/java/org/pablotron/luigi/tests/CacheTest.java')
-rw-r--r--java/src/test/java/org/pablotron/luigi/tests/CacheTest.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java b/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java
new file mode 100644
index 0000000..c91b727
--- /dev/null
+++ b/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java
@@ -0,0 +1,46 @@
+import java.util.Map;
+import java.util.HashMap;
+
+import org.pablotron.luigi.Template;
+import org.pablotron.luigi.Filter;
+import org.pablotron.luigi.Cache;
+import org.pablotron.luigi.LuigiError;
+import org.pablotron.luigi.UnknownKeyError;
+import org.pablotron.luigi.UnknownFilterError;
+import org.pablotron.luigi.UnknownTemplateError;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
+public final class CacheTest {
+ private static Map<String, String> TEST_ARGS = new HashMap<String, String>() {{
+ put("bar", "foo");
+ }};
+
+ private static Map<String, String> TEST_TEMPLATES = new HashMap<String, String>() {{
+ put("foo", "foo%{bar}foo");
+ put("foo-custom", "foo%{bar | custom-filter}foo");
+ }};
+
+ private static Map<String, Filter.Handler> TEST_FILTERS = new HashMap<String, Filter.Handler>() {{
+ put("custom-filter", new Filter.Handler() {
+ public String filter(String val, String args[], Map<String, String> row) {
+ return String.format("-custom-%s-filter-", val);
+ }
+ });
+ }};
+
+ @Test
+ public void testCache() throws LuigiError {
+ final Cache cache = new Cache(TEST_TEMPLATES);
+
+ assertEquals("foofoofoo", cache.run("foo", TEST_ARGS));
+ }
+
+ @Test
+ public void testCacheWithCustomFilters() throws LuigiError {
+ final Cache cache = new Cache(TEST_TEMPLATES, TEST_FILTERS);
+ assertEquals("foo-custom-foo-filter-foo", cache.run("foo-custom", TEST_ARGS));
+ }
+};