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.metadata;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  
21  import java.lang.reflect.Method;
22  
23  import org.junit.Test;
24  import org.junit.experimental.categories.Category;
25  
26  import de.smartics.properties.api.core.annotations.PropertyMetaDataMethod;
27  import de.smartics.properties.api.core.annotations.PropertySet;
28  import de.smartics.properties.api.core.domain.PropertyDescriptor;
29  import de.smartics.properties.api.core.domain.PropertyKey;
30  import de.smartics.properties.spi.core.util.PropertyUtils;
31  import de.smartics.testdoc.annotations.Uut;
32  import de.smartics.testdoc.categories.Technical;
33  import de.smartics.testdoc.categories.type.Coverage;
34  import de.smartics.util.test.lang.LangTestUtils;
35  
36  /**
37   * Tests {@link PropertyUtils}.
38   */
39  @Uut(type = PropertyUtils.class, method = "isPropertyMethod(Method)")
40  public class PropertyUtilsIsPropertyMethodTest
41  {
42    // ********************************* Fields *********************************
43  
44    // --- constants ------------------------------------------------------------
45  
46    // --- members --------------------------------------------------------------
47  
48    // ****************************** Inner Classes *****************************
49  
50    @PropertySet
51    public interface IsProperties
52    {
53      String name();
54  
55      @PropertyMetaDataMethod("name")
56      PropertyDescriptor something();
57  
58      String namePropertyDescriptor();
59  
60      PropertyKey namePropertyKey();
61    }
62  
63    // ********************************* Methods ********************************
64  
65    // --- prepare --------------------------------------------------------------
66  
67    // --- helper ---------------------------------------------------------------
68  
69    // --- tests ----------------------------------------------------------------
70  
71    @Test(expected = NullPointerException.class)
72    @Category(Technical.class)
73    public void requiresNonNullTypeForMethodTest()
74    {
75      PropertyUtils.isPropertyMethod(null);
76    }
77  
78    @Test
79    public void recognizesAnnotatedPropertyDescriptorMethod() throws Exception
80    {
81      final Method method =
82          IsProperties.class.getMethod("something", new Class<?>[0]);
83      final boolean value = PropertyUtils.isPropertyMethod(method);
84      assertThat(value, is(false));
85    }
86  
87    @Test
88    public void recognizesMethodWithPropertyDescriptorSuffix() throws Exception
89    {
90      final Method method =
91          IsProperties.class.getMethod("namePropertyDescriptor", new Class<?>[0]);
92      final boolean value = PropertyUtils.isPropertyMethod(method);
93      assertThat(value, is(false));
94    }
95  
96    @Test
97    public void recognizesMethodWithPropertyKeySuffix() throws Exception
98    {
99      final Method method =
100         IsProperties.class.getMethod("namePropertyKey", new Class<?>[0]);
101     final boolean value = PropertyUtils.isPropertyMethod(method);
102     assertThat(value, is(false));
103   }
104 
105   @Test
106   public void recognizesPropertyMethod() throws Exception
107   {
108     final Method method = IsProperties.class.getMethod("name", new Class<?>[0]);
109     final boolean value = PropertyUtils.isPropertyMethod(method);
110     assertThat(value, is(true));
111   }
112 
113   @Test
114   @Category(Coverage.class)
115   public void testPrivateConstructor()
116   {
117     LangTestUtils.runPrivateConstructorTest(PropertyUtils.class);
118   }
119 }