summaryrefslogtreecommitdiffstats
path: root/config-lib/src/test/java/com/yahoo/config/EnumNodeTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-lib/src/test/java/com/yahoo/config/EnumNodeTest.java')
-rw-r--r--config-lib/src/test/java/com/yahoo/config/EnumNodeTest.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/config-lib/src/test/java/com/yahoo/config/EnumNodeTest.java b/config-lib/src/test/java/com/yahoo/config/EnumNodeTest.java
new file mode 100644
index 00000000000..c7801d3eecb
--- /dev/null
+++ b/config-lib/src/test/java/com/yahoo/config/EnumNodeTest.java
@@ -0,0 +1,42 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
+/**
+ * @author lulf
+ * @since 5.1
+ */
+public class EnumNodeTest {
+ private static class MyNode extends EnumNode<MyNode.Enum> {
+ public enum Enum { ONE, TWO }
+ public final static Enum ONE = Enum.ONE;
+ public final static Enum TWO = Enum.TWO;
+
+ @Override
+ protected boolean doSetValue(@NonNull String name) {
+ try {
+ value = Enum.valueOf(name);
+ return true;
+ } catch (IllegalArgumentException e) {
+ }
+ return false;
+ }
+
+ }
+
+ @Test
+ public void testEnumNode() {
+ MyNode n = new MyNode();
+ assertNull(n.getValue());
+ assertThat(n.toString(), is("(null)"));
+ assertTrue(n.doSetValue("ONE"));
+ assertThat(n.getValue(), is("ONE"));
+ assertThat(n.toString(), is("ONE"));
+ assertFalse(n.doSetValue("THREE"));
+ }
+}