From 878e07414367b4cc69843c3e9d91da02bc7c7043 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 6 Sep 2018 18:18:55 -0400 Subject: java: mv src/main/java/org/pablotron/luigi/{,errors/}*Errors.java and update code --- java/src/main/java/org/pablotron/luigi/Cache.java | 3 +- java/src/main/java/org/pablotron/luigi/Filter.java | 2 + .../main/java/org/pablotron/luigi/FilterError.java | 7 ---- .../main/java/org/pablotron/luigi/LuigiError.java | 7 ---- java/src/main/java/org/pablotron/luigi/Parser.java | 2 +- .../main/java/org/pablotron/luigi/Template.java | 2 +- java/src/main/java/org/pablotron/luigi/Test.java | 2 +- .../org/pablotron/luigi/UnknownEntryError.java | 13 ------- .../org/pablotron/luigi/UnknownFilterError.java | 7 ---- .../java/org/pablotron/luigi/UnknownKeyError.java | 7 ---- .../org/pablotron/luigi/UnknownTemplateError.java | 7 ---- .../java/org/pablotron/luigi/actions/Action.java | 2 +- .../org/pablotron/luigi/actions/FilterAction.java | 6 +-- .../org/pablotron/luigi/actions/TextAction.java | 6 +-- .../org/pablotron/luigi/errors/FilterError.java | 7 ++++ .../org/pablotron/luigi/errors/LuigiError.java | 7 ++++ .../pablotron/luigi/errors/UnknownEntryError.java | 13 +++++++ .../pablotron/luigi/errors/UnknownFilterError.java | 7 ++++ .../pablotron/luigi/errors/UnknownKeyError.java | 7 ++++ .../luigi/errors/UnknownTemplateError.java | 7 ++++ .../java/org/pablotron/luigi/tests/CacheTest.java | 5 +-- .../pablotron/luigi/tests/DefaultFiltersTest.java | 7 +--- .../java/org/pablotron/luigi/tests/ErrorsTest.java | 44 ++++++++++++++++++++++ .../org/pablotron/luigi/tests/FiltersTest.java | 6 +-- .../org/pablotron/luigi/tests/TemplateTest.java | 4 +- 25 files changed, 112 insertions(+), 75 deletions(-) delete mode 100644 java/src/main/java/org/pablotron/luigi/FilterError.java delete mode 100644 java/src/main/java/org/pablotron/luigi/LuigiError.java delete mode 100644 java/src/main/java/org/pablotron/luigi/UnknownEntryError.java delete mode 100644 java/src/main/java/org/pablotron/luigi/UnknownFilterError.java delete mode 100644 java/src/main/java/org/pablotron/luigi/UnknownKeyError.java delete mode 100644 java/src/main/java/org/pablotron/luigi/UnknownTemplateError.java create mode 100644 java/src/main/java/org/pablotron/luigi/errors/FilterError.java create mode 100644 java/src/main/java/org/pablotron/luigi/errors/LuigiError.java create mode 100644 java/src/main/java/org/pablotron/luigi/errors/UnknownEntryError.java create mode 100644 java/src/main/java/org/pablotron/luigi/errors/UnknownFilterError.java create mode 100644 java/src/main/java/org/pablotron/luigi/errors/UnknownKeyError.java create mode 100644 java/src/main/java/org/pablotron/luigi/errors/UnknownTemplateError.java create mode 100644 java/src/test/java/org/pablotron/luigi/tests/ErrorsTest.java diff --git a/java/src/main/java/org/pablotron/luigi/Cache.java b/java/src/main/java/org/pablotron/luigi/Cache.java index 4a591bc..7be8f6c 100644 --- a/java/src/main/java/org/pablotron/luigi/Cache.java +++ b/java/src/main/java/org/pablotron/luigi/Cache.java @@ -4,7 +4,8 @@ import java.util.Map; import java.util.HashMap; import org.pablotron.luigi.Filter; import org.pablotron.luigi.Template; -import org.pablotron.luigi.LuigiError; +import org.pablotron.luigi.errors.LuigiError; +import org.pablotron.luigi.errors.UnknownTemplateError; import org.pablotron.luigi.actions.Action; public final class Cache { diff --git a/java/src/main/java/org/pablotron/luigi/Filter.java b/java/src/main/java/org/pablotron/luigi/Filter.java index d2cd432..676c328 100644 --- a/java/src/main/java/org/pablotron/luigi/Filter.java +++ b/java/src/main/java/org/pablotron/luigi/Filter.java @@ -4,6 +4,8 @@ import java.util.Map; import java.util.HashMap; import java.nio.charset.Charset; +import org.pablotron.luigi.errors.FilterError; + public final class Filter { public interface Handler { public String filter( diff --git a/java/src/main/java/org/pablotron/luigi/FilterError.java b/java/src/main/java/org/pablotron/luigi/FilterError.java deleted file mode 100644 index cb631a7..0000000 --- a/java/src/main/java/org/pablotron/luigi/FilterError.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.pablotron.luigi; - -public class FilterError extends LuigiError { - public FilterError(final String message) { - super(message); - } -}; diff --git a/java/src/main/java/org/pablotron/luigi/LuigiError.java b/java/src/main/java/org/pablotron/luigi/LuigiError.java deleted file mode 100644 index edeb7c7..0000000 --- a/java/src/main/java/org/pablotron/luigi/LuigiError.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.pablotron.luigi; - -public class LuigiError extends Exception { - public LuigiError(final String message) { - super(message); - } -}; diff --git a/java/src/main/java/org/pablotron/luigi/Parser.java b/java/src/main/java/org/pablotron/luigi/Parser.java index 5be4a9c..01e44f8 100644 --- a/java/src/main/java/org/pablotron/luigi/Parser.java +++ b/java/src/main/java/org/pablotron/luigi/Parser.java @@ -8,7 +8,7 @@ import org.pablotron.luigi.actions.Action; import org.pablotron.luigi.actions.FilterAction; import org.pablotron.luigi.actions.TextAction; import org.pablotron.luigi.FilterReference; -import org.pablotron.luigi.LuigiError; +import org.pablotron.luigi.errors.LuigiError; public final class Parser { private static final Pattern RE_ACTION = Pattern.compile( diff --git a/java/src/main/java/org/pablotron/luigi/Template.java b/java/src/main/java/org/pablotron/luigi/Template.java index e5f25a9..91c6f9f 100644 --- a/java/src/main/java/org/pablotron/luigi/Template.java +++ b/java/src/main/java/org/pablotron/luigi/Template.java @@ -3,7 +3,7 @@ package org.pablotron.luigi; import java.util.Map; import org.pablotron.luigi.Parser; import org.pablotron.luigi.Filter; -import org.pablotron.luigi.LuigiError; +import org.pablotron.luigi.errors.LuigiError; import org.pablotron.luigi.actions.Action; public final class Template { diff --git a/java/src/main/java/org/pablotron/luigi/Test.java b/java/src/main/java/org/pablotron/luigi/Test.java index 2a560e2..3d25c13 100644 --- a/java/src/main/java/org/pablotron/luigi/Test.java +++ b/java/src/main/java/org/pablotron/luigi/Test.java @@ -3,7 +3,7 @@ package org.pablotron.luigi; import java.util.Map; import java.util.HashMap; -import org.pablotron.luigi.LuigiError; +import org.pablotron.luigi.errors.LuigiError; import org.pablotron.luigi.Filter; import org.pablotron.luigi.Template; import org.pablotron.luigi.Cache; diff --git a/java/src/main/java/org/pablotron/luigi/UnknownEntryError.java b/java/src/main/java/org/pablotron/luigi/UnknownEntryError.java deleted file mode 100644 index 8b8a0fd..0000000 --- a/java/src/main/java/org/pablotron/luigi/UnknownEntryError.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.pablotron.luigi; - -public class UnknownEntryError extends LuigiError { - public final String type; - public final String name; - - public UnknownEntryError(final String type, final String name) { - super(String.format("unknown %s: %s", type, name)); - - this.type = type; - this.name = name; - } -}; diff --git a/java/src/main/java/org/pablotron/luigi/UnknownFilterError.java b/java/src/main/java/org/pablotron/luigi/UnknownFilterError.java deleted file mode 100644 index a56a6c1..0000000 --- a/java/src/main/java/org/pablotron/luigi/UnknownFilterError.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.pablotron.luigi; - -public class UnknownFilterError extends UnknownEntryError { - public UnknownFilterError(final String name) { - super("filter", name); - } -}; diff --git a/java/src/main/java/org/pablotron/luigi/UnknownKeyError.java b/java/src/main/java/org/pablotron/luigi/UnknownKeyError.java deleted file mode 100644 index 88da21a..0000000 --- a/java/src/main/java/org/pablotron/luigi/UnknownKeyError.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.pablotron.luigi; - -public class UnknownKeyError extends UnknownEntryError { - public UnknownKeyError(final String name) { - super("key", name); - } -}; diff --git a/java/src/main/java/org/pablotron/luigi/UnknownTemplateError.java b/java/src/main/java/org/pablotron/luigi/UnknownTemplateError.java deleted file mode 100644 index 15dae97..0000000 --- a/java/src/main/java/org/pablotron/luigi/UnknownTemplateError.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.pablotron.luigi; - -public class UnknownTemplateError extends UnknownEntryError { - public UnknownTemplateError(final String name) { - super("template", name); - } -}; diff --git a/java/src/main/java/org/pablotron/luigi/actions/Action.java b/java/src/main/java/org/pablotron/luigi/actions/Action.java index 9708199..a473f62 100644 --- a/java/src/main/java/org/pablotron/luigi/actions/Action.java +++ b/java/src/main/java/org/pablotron/luigi/actions/Action.java @@ -2,7 +2,7 @@ package org.pablotron.luigi.actions; import java.util.Map; import org.pablotron.luigi.Filter; -import org.pablotron.luigi.LuigiError; +import org.pablotron.luigi.errors.LuigiError; public interface Action { public String run( diff --git a/java/src/main/java/org/pablotron/luigi/actions/FilterAction.java b/java/src/main/java/org/pablotron/luigi/actions/FilterAction.java index 19565dc..091a285 100644 --- a/java/src/main/java/org/pablotron/luigi/actions/FilterAction.java +++ b/java/src/main/java/org/pablotron/luigi/actions/FilterAction.java @@ -4,9 +4,9 @@ import java.util.Map; import org.pablotron.luigi.actions.Action; import org.pablotron.luigi.FilterReference; import org.pablotron.luigi.Filter; -import org.pablotron.luigi.LuigiError; -import org.pablotron.luigi.UnknownFilterError; -import org.pablotron.luigi.UnknownKeyError; +import org.pablotron.luigi.errors.LuigiError; +import org.pablotron.luigi.errors.UnknownFilterError; +import org.pablotron.luigi.errors.UnknownKeyError; public final class FilterAction implements Action { private final String key; diff --git a/java/src/main/java/org/pablotron/luigi/actions/TextAction.java b/java/src/main/java/org/pablotron/luigi/actions/TextAction.java index 0ad4382..32487be 100644 --- a/java/src/main/java/org/pablotron/luigi/actions/TextAction.java +++ b/java/src/main/java/org/pablotron/luigi/actions/TextAction.java @@ -3,7 +3,7 @@ package org.pablotron.luigi.actions; import java.util.Map; import org.pablotron.luigi.actions.Action; import org.pablotron.luigi.Filter; -import org.pablotron.luigi.LuigiError; +import org.pablotron.luigi.errors.LuigiError; public final class TextAction implements Action { private final String text; @@ -13,8 +13,8 @@ public final class TextAction implements Action { } public String run( - Map filters, - Map args + final Map filters, + final Map args ) throws LuigiError { return this.text; } diff --git a/java/src/main/java/org/pablotron/luigi/errors/FilterError.java b/java/src/main/java/org/pablotron/luigi/errors/FilterError.java new file mode 100644 index 0000000..f2ff7fb --- /dev/null +++ b/java/src/main/java/org/pablotron/luigi/errors/FilterError.java @@ -0,0 +1,7 @@ +package org.pablotron.luigi.errors; + +public class FilterError extends LuigiError { + public FilterError(final String message) { + super(message); + } +}; diff --git a/java/src/main/java/org/pablotron/luigi/errors/LuigiError.java b/java/src/main/java/org/pablotron/luigi/errors/LuigiError.java new file mode 100644 index 0000000..abf9280 --- /dev/null +++ b/java/src/main/java/org/pablotron/luigi/errors/LuigiError.java @@ -0,0 +1,7 @@ +package org.pablotron.luigi.errors; + +public class LuigiError extends Exception { + public LuigiError(final String message) { + super(message); + } +}; diff --git a/java/src/main/java/org/pablotron/luigi/errors/UnknownEntryError.java b/java/src/main/java/org/pablotron/luigi/errors/UnknownEntryError.java new file mode 100644 index 0000000..7710838 --- /dev/null +++ b/java/src/main/java/org/pablotron/luigi/errors/UnknownEntryError.java @@ -0,0 +1,13 @@ +package org.pablotron.luigi.errors; + +public class UnknownEntryError extends LuigiError { + public final String type; + public final String name; + + public UnknownEntryError(final String type, final String name) { + super(String.format("unknown %s: %s", type, name)); + + this.type = type; + this.name = name; + } +}; diff --git a/java/src/main/java/org/pablotron/luigi/errors/UnknownFilterError.java b/java/src/main/java/org/pablotron/luigi/errors/UnknownFilterError.java new file mode 100644 index 0000000..7396da6 --- /dev/null +++ b/java/src/main/java/org/pablotron/luigi/errors/UnknownFilterError.java @@ -0,0 +1,7 @@ +package org.pablotron.luigi.errors; + +public class UnknownFilterError extends UnknownEntryError { + public UnknownFilterError(final String name) { + super("filter", name); + } +}; diff --git a/java/src/main/java/org/pablotron/luigi/errors/UnknownKeyError.java b/java/src/main/java/org/pablotron/luigi/errors/UnknownKeyError.java new file mode 100644 index 0000000..7b0ae4c --- /dev/null +++ b/java/src/main/java/org/pablotron/luigi/errors/UnknownKeyError.java @@ -0,0 +1,7 @@ +package org.pablotron.luigi.errors; + +public class UnknownKeyError extends UnknownEntryError { + public UnknownKeyError(final String name) { + super("key", name); + } +}; diff --git a/java/src/main/java/org/pablotron/luigi/errors/UnknownTemplateError.java b/java/src/main/java/org/pablotron/luigi/errors/UnknownTemplateError.java new file mode 100644 index 0000000..e6b4682 --- /dev/null +++ b/java/src/main/java/org/pablotron/luigi/errors/UnknownTemplateError.java @@ -0,0 +1,7 @@ +package org.pablotron.luigi.errors; + +public class UnknownTemplateError extends UnknownEntryError { + public UnknownTemplateError(final String name) { + super("template", name); + } +}; diff --git a/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java b/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java index c91b727..9aff8fc 100644 --- a/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java +++ b/java/src/test/java/org/pablotron/luigi/tests/CacheTest.java @@ -4,10 +4,7 @@ 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 org.pablotron.luigi.errors.LuigiError; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/java/src/test/java/org/pablotron/luigi/tests/DefaultFiltersTest.java b/java/src/test/java/org/pablotron/luigi/tests/DefaultFiltersTest.java index c839ded..fe0bc51 100644 --- a/java/src/test/java/org/pablotron/luigi/tests/DefaultFiltersTest.java +++ b/java/src/test/java/org/pablotron/luigi/tests/DefaultFiltersTest.java @@ -3,15 +3,12 @@ import java.util.HashMap; import java.util.List; import java.util.ArrayList; -import org.pablotron.luigi.LuigiError; import org.pablotron.luigi.Template; import org.pablotron.luigi.Filter; -import org.pablotron.luigi.FilterError; -import org.pablotron.luigi.ResultHandler; +import org.pablotron.luigi.errors.LuigiError; +import org.pablotron.luigi.errors.FilterError; 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 DefaultFiltersTest { diff --git a/java/src/test/java/org/pablotron/luigi/tests/ErrorsTest.java b/java/src/test/java/org/pablotron/luigi/tests/ErrorsTest.java new file mode 100644 index 0000000..a88699d --- /dev/null +++ b/java/src/test/java/org/pablotron/luigi/tests/ErrorsTest.java @@ -0,0 +1,44 @@ +import java.util.Map; +import java.util.HashMap; + +import org.pablotron.luigi.Template; +import org.pablotron.luigi.Cache; +import org.pablotron.luigi.errors.LuigiError; +import org.pablotron.luigi.errors.UnknownKeyError; +import org.pablotron.luigi.errors.UnknownFilterError; +import org.pablotron.luigi.errors.UnknownTemplateError; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; + +public final class ErrorsTest { + private static Map TEST_ARGS = new HashMap() {{ + put("bar", "foo"); + }}; + + private static Map TEST_TEMPLATES = new HashMap() {{ + put("foo", "foo%{bar}foo"); + }}; + + @Test + public void testUnknownKeyError() { + assertThrows(UnknownKeyError.class, () -> { + Template.run("foo%{unknown-key}", TEST_ARGS); + }); + } + + @Test + public void testUnknownFilterError() { + assertThrows(UnknownFilterError.class, () -> { + Template.run("foo%{bar | unknown-filter}", TEST_ARGS); + }); + } + + @Test + public void testUnknownTemplateError() { + final Cache cache = new Cache(TEST_TEMPLATES); + assertThrows(UnknownTemplateError.class, () -> { + cache.run("unknown-template", TEST_ARGS); + }); + } +}; diff --git a/java/src/test/java/org/pablotron/luigi/tests/FiltersTest.java b/java/src/test/java/org/pablotron/luigi/tests/FiltersTest.java index 9168529..4800318 100644 --- a/java/src/test/java/org/pablotron/luigi/tests/FiltersTest.java +++ b/java/src/test/java/org/pablotron/luigi/tests/FiltersTest.java @@ -1,15 +1,13 @@ import java.util.Map; import java.util.HashMap; -import org.pablotron.luigi.LuigiError; import org.pablotron.luigi.Template; import org.pablotron.luigi.Filter; -import org.pablotron.luigi.FilterError; +import org.pablotron.luigi.errors.LuigiError; +import org.pablotron.luigi.errors.FilterError; import org.pablotron.luigi.ResultHandler; 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; diff --git a/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java b/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java index eadaab1..f4960cc 100644 --- a/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java +++ b/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java @@ -1,16 +1,14 @@ import java.util.Map; import java.util.HashMap; -import org.pablotron.luigi.LuigiError; import org.pablotron.luigi.Template; +import org.pablotron.luigi.errors.LuigiError; import org.pablotron.luigi.ResultHandler; 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"); -- cgit v1.2.3