From 1e18bc3179423506862155c14405879dbf4bf1af Mon Sep 17 00:00:00 2001 From: Sola Date: Mon, 18 Apr 2016 16:18:50 +0800 Subject: [PATCH] cortana test --- .../love/sola/netsupport/config/Cortana.java | 19 ++++++++++++++----- .../sola/netsupport/config/CortanaTest.java | 18 ++++++++++++++++++ src/test/resources/cortana.yml | 16 ++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/test/java/love/sola/netsupport/config/CortanaTest.java create mode 100644 src/test/resources/cortana.yml diff --git a/src/main/java/love/sola/netsupport/config/Cortana.java b/src/main/java/love/sola/netsupport/config/Cortana.java index 2947715..9565116 100644 --- a/src/main/java/love/sola/netsupport/config/Cortana.java +++ b/src/main/java/love/sola/netsupport/config/Cortana.java @@ -1,5 +1,6 @@ package love.sola.netsupport.config; +import lombok.Data; import org.yaml.snakeyaml.Yaml; import java.io.InputStream; @@ -15,19 +16,27 @@ import java.util.regex.Pattern; */ public class Cortana { - public static List entries; public static void load() { InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml"); - Map root = (Map) new Yaml().load(in); - + RawConfig root = new Yaml().loadAs(in, RawConfig.class); } - - public static class Compiled { + static class Compiled { Pattern[] patterns; String[] replies; } + @Data + public static class Rule { + String[] regexp; + String[] replies; + } + + @Data + public static class RawConfig { + Map rules; + } + } diff --git a/src/test/java/love/sola/netsupport/config/CortanaTest.java b/src/test/java/love/sola/netsupport/config/CortanaTest.java new file mode 100644 index 0000000..0809f48 --- /dev/null +++ b/src/test/java/love/sola/netsupport/config/CortanaTest.java @@ -0,0 +1,18 @@ +package love.sola.netsupport.config; + +import org.junit.Test; + +/** + * *********************************************** + * Created by Sola on 2016/4/18. + * Don't modify this source without my agreement + * *********************************************** + */ +public class CortanaTest { + + @Test + public void load() throws Exception { + Cortana.load(); + } + +} \ No newline at end of file diff --git a/src/test/resources/cortana.yml b/src/test/resources/cortana.yml new file mode 100644 index 0000000..8535f8e --- /dev/null +++ b/src/test/resources/cortana.yml @@ -0,0 +1,16 @@ +rules: + rule1: + regexp: + - 'single test' + replies: + - 'single test' + rule2: + regexp: ['inline test', 'inline test'] + replies: ['inline test', 'inline test'] + rule3: + regexp: + - 'multi line test' + - 'multi line test' + replies: + - 'multi line test' + - 'multi line test'