View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package test.de.smartics.properties.spi.core.value;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.equalTo;
20  import static org.hamcrest.Matchers.hasItems;
21  import static org.hamcrest.Matchers.is;
22  
23  import java.util.List;
24  
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import de.smartics.properties.spi.core.value.EnumeratedPropertyValueRange;
29  import de.smartics.testdoc.annotations.Uut;
30  
31  /**
32   * Tests {@link EnumeratedPropertyValueRange} using {@link #DummyEnumeration}.
33   */
34  @Uut(type=EnumeratedPropertyValueRange.class)
35  public class EnumeratedPropertyValueRangeTest
36  {
37    // ********************************* Fields *********************************
38  
39    // --- constants ------------------------------------------------------------
40  
41    // --- members --------------------------------------------------------------
42  
43    private EnumeratedPropertyValueRange<DummyEnumeration> uut;
44  
45    // ****************************** Inner Classes *****************************
46  
47    private static enum DummyEnumeration
48    {
49      ELEMENT_1, ELEMENT_2;
50    }
51  
52    // ********************************* Methods ********************************
53  
54    // --- prepare --------------------------------------------------------------
55  
56    @Before
57    public void setUp()
58    {
59      uut =
60          new EnumeratedPropertyValueRange<DummyEnumeration>(
61              DummyEnumeration.class);
62    }
63  
64    // --- helper ---------------------------------------------------------------
65  
66    // --- tests ----------------------------------------------------------------
67  
68    @Test
69    public void providesAStringRepresentation()
70    {
71      final String result = uut.toString();
72  
73      assertThat(result, is(equalTo("ELEMENT_1, ELEMENT_2")));
74    }
75  
76    @Test
77    public void providesAnEnumerationElementInstanceFromAString()
78    {
79      final String enumElementName = DummyEnumeration.ELEMENT_2.name();
80  
81      final DummyEnumeration enumElement = uut.fromString(enumElementName);
82  
83      assertThat(enumElement, is(equalTo(DummyEnumeration.ELEMENT_2)));
84    }
85  
86    @Test
87    public void allowsToRetrieveAllValues()
88    {
89      final List<DummyEnumeration> values = uut.getValues();
90  
91      assertThat(values.size(), is(equalTo(2)));
92      assertThat(values,
93          hasItems(DummyEnumeration.ELEMENT_1, DummyEnumeration.ELEMENT_2));
94    }
95  
96    @Test
97    public void providesAccessToTheEnumerationClass()
98    {
99      final Class<DummyEnumeration> type = uut.getEnumeration();
100 
101     assertThat(type, is(equalTo(DummyEnumeration.class)));
102     assertThat(uut.isCommented(), is(true));
103   }
104 }