aboutsummaryrefslogtreecommitdiffstats
path: root/config-lib/src/test/java/com/yahoo/config/EnumNodeTest.java
blob: fac765f40aacbbb1e3240283838d39756cdc91c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
 * @author Ulf Lilleengen
 */
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(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());
        assertEquals("(null)", n.toString());
        assertTrue(n.doSetValue("ONE"));
        assertEquals("ONE", n.getValue());
        assertEquals("ONE", n.toString());
        assertFalse(n.doSetValue("THREE"));
    }
}