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 java.lang.reflect.Method;
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.junit.Test;
23  
24  import de.smartics.properties.api.core.annotations.PropertySet;
25  import de.smartics.properties.api.core.domain.PropertyConstraint;
26  import de.smartics.properties.api.core.domain.PropertyDescriptor;
27  import de.smartics.properties.api.core.domain.PropertyExpression;
28  import de.smartics.properties.api.core.domain.PropertyKey;
29  import de.smartics.properties.api.core.domain.PropertyType;
30  import de.smartics.properties.spi.core.metadata.PropertyMetaDataParser;
31  import de.smartics.testdoc.annotations.Uut;
32  
33  /**
34   * Tests {@link de.smartics.properties.spi.core.metadata.PropertyMetaDataParser} with and
35   * without property set annotations.
36   */
37  @Uut(type = PropertyMetaDataParser.class)
38  public class PropertyMetaDataParserPropertySetAnnotationsTest extends
39      AbstractPropertyMetaDataParserTestBase
40  { // NOPMD
41    // ********************************* Fields *********************************
42  
43    // --- constants ------------------------------------------------------------
44  
45    // --- members --------------------------------------------------------------
46  
47    // ****************************** Inner Classes *****************************
48  
49    @PropertySet("type")
50    public interface TestProperties
51    {
52      String property1();
53  
54      @PropertySet("method")
55      String property2();
56  
57      @PropertySet("")
58      String property3();
59  
60      @PropertySet(" ")
61      String property4();
62    }
63  
64    // ********************************* Methods ********************************
65  
66    // --- prepare --------------------------------------------------------------
67  
68    // --- helper ---------------------------------------------------------------
69  
70    private void runTest(final String propertySet,
71        final String methodNameAndPropertyName)
72    {
73      final Method method =
74          fetchMethod(TestProperties.class, methodNameAndPropertyName);
75      final PropertyDescriptor descriptor = uut.readDescriptor(method);
76  
77      final PropertyKey expectedKey =
78          new PropertyKey(propertySet, methodNameAndPropertyName);
79      final PropertyType expectedType = new PropertyType(String.class);
80      final List<PropertyConstraint<?>> expectedConstraints =
81          Collections.emptyList();
82  
83      checkThat(descriptor, expectedKey, expectedType,
84          PropertyExpression.NO_EXPRESSION, null, expectedConstraints);
85    }
86  
87    // --- tests ----------------------------------------------------------------
88  
89    @Test
90    public void parsesPropertySetOnType()
91    {
92      runTest("type", "property1");
93    }
94  
95    @Test
96    public void favoursPropertySetOnMethodName()
97    {
98      runTest("method", "property2");
99    }
100 
101   @Test
102   public void allowsToEraseThePropertySetName()
103   {
104     runTest(null, "property3");
105   }
106 
107   @Test
108   public void defaultIsASingleSpace()
109   {
110     runTest(TestProperties.class.getName(), "property4");
111   }
112 }