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.config.definition;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  import de.smartics.properties.impl.config.domain.key.envapp.EnvAppPropertiesDefinitionContext;
29  import de.smartics.testdoc.annotations.Uut;
30  import de.smartics.testdoc.categories.type.Coverage;
31  
32  /**
33   * Tests {@link EnvAppPropertiesDefinitionContext}.
34   */
35  public class PropertiesDefinitionContextTest
36  {
37    // ********************************* Fields *********************************
38  
39    // --- constants ------------------------------------------------------------
40  
41    private static final String REGISTERED_GROUP = "registered";
42  
43    // --- members --------------------------------------------------------------
44  
45    @Uut(method = "isRegisteredGroupTld(String)")
46    private EnvAppPropertiesDefinitionContext uut;
47  
48    // ****************************** Inner Classes *****************************
49  
50    // ********************************* Methods ********************************
51  
52    // --- prepare --------------------------------------------------------------
53  
54    @Before
55    public void setUp()
56    {
57      final Set<String> tlds = new HashSet<String>();
58      tlds.add(REGISTERED_GROUP);
59      uut = new EnvAppPropertiesDefinitionContext(null, null, tlds);
60    }
61  
62    // --- helper ---------------------------------------------------------------
63  
64    // --- tests ----------------------------------------------------------------
65  
66    @Test
67    public void anyTwoLetterTldIdentifiesAGroup()
68    {
69      final String tld = "de";
70      final boolean result = uut.isRegisteredGroupTld(tld);
71  
72      assertThat(result, is(true));
73    }
74  
75    @Test
76    public void anyTwoCharsDoNotIdentifyAGroup()
77    {
78      final String tld = "a1";
79      final boolean result = uut.isRegisteredGroupTld(tld);
80  
81      assertThat(result, is(false));
82    }
83  
84    @Test
85    @Category(Coverage.class)
86    public void anyTwoCharsDoNotIdentifyAGroupDigitFirst()
87    {
88      final String tld = "1a";
89      final boolean result = uut.isRegisteredGroupTld(tld);
90  
91      assertThat(result, is(false));
92    }
93  
94    @Test
95    @Category(Coverage.class)
96    public void anyThreeLettersDoNotIdentifyAGroup()
97    {
98      final String tld = "any";
99      final boolean result = uut.isRegisteredGroupTld(tld);
100 
101     assertThat(result, is(false));
102   }
103 
104   @Test
105   public void aDefaultTldIdentifiesAGroup()
106   {
107     final String tld = "com";
108     final boolean result = uut.isRegisteredGroupTld(tld);
109 
110     assertThat(result, is(true));
111   }
112 
113   @Test
114   public void nullIsNotAGroup()
115   {
116     final String tld = null;
117     final boolean result = uut.isRegisteredGroupTld(tld);
118 
119     assertThat(result, is(false));
120   }
121 }