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.classpath;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.hasItems;
20  import static org.hamcrest.Matchers.is;
21  
22  import help.de.smartics.properties.core.SimpleProperties;
23  
24  import java.net.URL;
25  import java.util.Arrays;
26  import java.util.HashSet;
27  import java.util.Set;
28  
29  import org.hamcrest.Matcher;
30  import org.junit.Before;
31  import org.junit.Test;
32  import org.junit.experimental.categories.Category;
33  
34  import de.smartics.properties.spi.core.classpath.PropertySetClassesLoader;
35  import de.smartics.testdoc.annotations.Uut;
36  import de.smartics.testdoc.categories.Technical;
37  
38  /**
39   * Tests {@link PropertySetClassesLoader}.
40   */
41  public class PropertySetClassesLoaderTest
42  {
43    // ********************************* Fields *********************************
44  
45    // --- constants ------------------------------------------------------------
46  
47    // --- members --------------------------------------------------------------
48  
49    @Uut
50    private PropertySetClassesLoader uut;
51  
52    // ****************************** Inner Classes *****************************
53  
54    // ********************************* Methods ********************************
55  
56    // --- prepare --------------------------------------------------------------
57  
58    @Before
59    public void setUp()
60    {
61      uut = new PropertySetClassesLoader();
62    }
63  
64    // --- helper ---------------------------------------------------------------
65  
66    // --- tests ----------------------------------------------------------------
67  
68    @Test
69    @Category(Technical.class)
70    public void allowsNullAsCollectionOfClassPathRoots()
71    {
72      final Set<Class<?>> types = uut.getPropertySetTypes(null);
73      assertThat(types.isEmpty(), is(true));
74    }
75  
76    @Test
77    @Category(Technical.class)
78    public void allowsAnEmptyCollectionOfClassPathRoots()
79    {
80      final Set<Class<?>> types = uut.getPropertySetTypes(new HashSet<URL>());
81      assertThat(types.isEmpty(), is(true));
82    }
83  
84    @SuppressWarnings({ "unchecked", "rawtypes" })
85    @Test
86    @Category(Technical.class)
87    public void returnsOnlyTypesAnnotatedAsPropertySet()
88    {
89      final URL url = SimpleProperties.class.getClassLoader().getResource(""); // NOPMD
90      final Set<Class<?>> types = uut.getPropertySetTypes(Arrays.asList(url));
91      assertThat(types.isEmpty(), is(false));
92      assertThat(types, (Matcher) hasItems(SimpleProperties.class));
93    }
94  
95  }