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.CollectionPropertyValueRange;
29  import de.smartics.testdoc.annotations.Uut;
30  import de.smartics.util.lang.NullArgumentException;
31  
32  /**
33   * Tests {@link CollectionPropertyValueRange} with arrays. Uses two elements.
34   */
35  @Uut(type = CollectionPropertyValueRange.class)
36  public class CollectionPropertyValueRangeWithArrayTest
37  {
38    // ********************************* Fields *********************************
39  
40    // --- constants ------------------------------------------------------------
41  
42    private static final String ELEMENT_2 = "two";
43  
44    private static final String ELEMENT_1 = "one";
45  
46    private static final String[] TEST_ARRAY =
47    { ELEMENT_1, ELEMENT_2 };
48  
49    // --- members --------------------------------------------------------------
50  
51    private CollectionPropertyValueRange<String> uut;
52  
53    // ****************************** Inner Classes *****************************
54  
55    // ********************************* Methods ********************************
56  
57    // --- prepare --------------------------------------------------------------
58  
59    @Before
60    public void setUp()
61    {
62      uut = new CollectionPropertyValueRange<String>(TEST_ARRAY);
63    }
64  
65    // --- helper ---------------------------------------------------------------
66  
67    // --- tests ----------------------------------------------------------------
68  
69    @Test
70    public void providesAStringRepresentation()
71    {
72      final String result = uut.toString();
73  
74      assertThat(result, is(equalTo("one, two")));
75    }
76  
77    @Test
78    public void providesAnElementInstanceFromAString()
79    {
80      final String elementName = ELEMENT_2;
81      final String element = uut.fromString(elementName);
82  
83      assertThat(element, is(equalTo(ELEMENT_2)));
84    }
85  
86    @Test(expected = IllegalArgumentException.class)
87    public void signalsRequestOfUnknownElementWithAnException()
88    {
89      final String elementName = "unknown-element-name";
90      uut.fromString(elementName);
91    }
92  
93    @Test
94    public void allowsToRetrieveAllValues()
95    {
96      final List<String> values = uut.getValues();
97  
98      assertThat(values.size(), is(equalTo(2)));
99      assertThat(values, hasItems(ELEMENT_1, ELEMENT_2));
100   }
101 
102   @Test(expected = NullArgumentException.class)
103   public void constructionRequiresANonNullArray()
104   {
105     new CollectionPropertyValueRange<String>((String[]) null);
106   }
107 }