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  {
12      private final String PROPERTY_NAME = TestEnumUtils.class.getName() + ".propertyName";
13  
14      @Rule
15      public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(PROPERTY_NAME);
16  
17      private enum TestEnum
18      {
19          ALPHA,
20          BETA,
21          GAMMA,
22          DELTA
23      }
24  
25      private TestEnum lookupValue()
26      {
27          return EnumUtils.enumValueFromProperty(PROPERTY_NAME, TestEnum.values(), TestEnum.BETA);
28      }
29  
30      @Test
31      public void checkDefault()
32      {
33          assertThat(lookupValue(), is(TestEnum.BETA));
34      }
35  
36      @Test
37      public void valueTracksPropertyValue()
38      {
39          System.setProperty(PROPERTY_NAME, "alpha");
40          assertThat(lookupValue(), is(TestEnum.ALPHA));
41          System.setProperty(PROPERTY_NAME, "GAMMA");
42          assertThat(lookupValue(), is(TestEnum.GAMMA));
43          System.setProperty(PROPERTY_NAME, "DelTa");
44          assertThat(lookupValue(), is(TestEnum.DELTA));
45      }
46  }