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.api.config;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.allOf;
20  import static org.hamcrest.Matchers.containsString;
21  import static org.hamcrest.Matchers.equalTo;
22  import static org.hamcrest.Matchers.hasItem;
23  import static org.hamcrest.Matchers.is;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.junit.Before;
27  import org.junit.Test;
28  import org.junit.experimental.categories.Category;
29  
30  import de.smartics.properties.api.config.domain.Property;
31  import de.smartics.properties.api.config.domain.PropertyLocation;
32  import de.smartics.properties.api.config.domain.UnknownProperties;
33  import de.smartics.testdoc.annotations.Uut;
34  import de.smartics.testdoc.categories.type.Coverage;
35  
36  /**
37   * Tests {@link UnknownProperties}.
38   */
39  public class UnknownPropertiesTest
40  {
41    // ********************************* Fields *********************************
42  
43    // --- constants ------------------------------------------------------------
44  
45    private static final PropertyLocation SOURCE_ID =
46        new PropertyLocation("test");
47  
48    // --- members --------------------------------------------------------------
49  
50    @Uut
51    private UnknownProperties uut;
52  
53    private Property property;
54  
55    // ****************************** Inner Classes *****************************
56  
57    // ********************************* Methods ********************************
58  
59    // --- prepare --------------------------------------------------------------
60  
61    @Before
62    public void setUp()
63    {
64      uut = new UnknownProperties();
65  
66      property = new Property(SOURCE_ID, "name", "value");
67    }
68  
69    // --- helper ---------------------------------------------------------------
70  
71    // --- tests ----------------------------------------------------------------
72  
73    @Test
74    public void allowsAddingProperties()
75    {
76      uut.add(property);
77      assertThat(uut.isEmpty(), is(false));
78      assertThat(uut.getProperties(), hasItem(property));
79    }
80  
81    @Test
82    public void providesAStringRepresentation()
83    {
84      uut.add(property);
85      final String string = uut.toString();
86      assertThat(string, allOf(containsString("name"), containsString("value")));
87    }
88  
89    @Test
90    @Category(Coverage.class)
91    public void providesAStringRepresentationForEmptyProperties()
92    {
93      final String string = uut.toString();
94      assertThat(string, is(equalTo(StringUtils.EMPTY)));
95    }
96  }