View Javadoc
1   package com.atlassian.plugin.util;
2   
3   import org.junit.Rule;
4   import org.junit.Test;
5   import org.junit.contrib.java.lang.system.RestoreSystemProperties;
6   
7   import static org.hamcrest.MatcherAssert.assertThat;
8   import static org.hamcrest.Matchers.is;
9   
10  public class TestEnumUtils {
11      private final String PROPERTY_NAME = TestEnumUtils.class.getName() + ".propertyName";
12  
13      @Rule
14      public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
15  
16      private enum TestEnum {
17          ALPHA,
18          BETA,
19          GAMMA,
20          DELTA
21      }
22  
23      private TestEnum lookupValue() {
24          return EnumUtils.enumValueFromProperty(PROPERTY_NAME, TestEnum.values(), TestEnum.BETA);
25      }
26  
27      @Test
28      public void checkDefault() {
29          assertThat(lookupValue(), is(TestEnum.BETA));
30      }
31  
32      @Test
33      public void valueTracksPropertyValue() {
34          System.setProperty(PROPERTY_NAME, "alpha");
35          assertThat(lookupValue(), is(TestEnum.ALPHA));
36          System.setProperty(PROPERTY_NAME, "GAMMA");
37          assertThat(lookupValue(), is(TestEnum.GAMMA));
38          System.setProperty(PROPERTY_NAME, "DelTa");
39          assertThat(lookupValue(), is(TestEnum.DELTA));
40      }
41  }