1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.report.qdox;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import com.thoughtworks.qdox.model.JavaAnnotation;
30 import com.thoughtworks.qdox.model.JavaClass;
31
32 import de.smartics.properties.api.core.annotations.PropertyKeyName;
33 import de.smartics.properties.api.core.annotations.PropertySet;
34 import de.smartics.properties.report.qdox.PropertyDescriptorSearcher;
35 import de.smartics.testdoc.annotations.Uut;
36
37
38
39
40 public class PropertyDescriptorSearcherTest
41 {
42
43
44
45
46
47
48 @Uut
49 private PropertyDescriptorSearcher uut;
50
51
52
53
54
55
56
57 @Before
58 public void setUp()
59 {
60 uut = new PropertyDescriptorSearcher();
61 }
62
63
64
65
66
67 @Test
68 public void recognizesInterfacesAnnotatedWithTheProjectSetAnnotation()
69 {
70 final JavaClass annotationClass = mock(JavaClass.class);
71 when(annotationClass.getFullyQualifiedName()).thenReturn(
72 PropertySet.class.getName());
73
74 final JavaAnnotation annotation = mock(JavaAnnotation.class);
75 when(annotation.getType()).thenReturn(annotationClass);
76
77 final JavaClass cls = mock(JavaClass.class);
78 when(cls.isInterface()).thenReturn(true);
79 final List<JavaAnnotation> annotations = new ArrayList<JavaAnnotation>(1);
80 annotations.add(annotation);
81 when(cls.getAnnotations()).thenReturn(annotations);
82
83 final boolean match = uut.eval(cls);
84
85 assertThat(match, is(true));
86 }
87
88 @Test
89 public void rejectsIfTheAnnotationIsProvidedAtAClass()
90 {
91 final JavaClass annotationClass = mock(JavaClass.class);
92 when(annotationClass.getFullyQualifiedName()).thenReturn(
93 PropertySet.class.getName());
94
95 final JavaAnnotation annotation = mock(JavaAnnotation.class);
96 when(annotation.getType()).thenReturn(annotationClass);
97
98 final JavaClass cls = mock(JavaClass.class);
99 when(cls.isInterface()).thenReturn(false);
100 final List<JavaAnnotation> annotations = new ArrayList<JavaAnnotation>(1);
101 annotations.add(annotation);
102 when(cls.getAnnotations()).thenReturn(annotations);
103
104 final boolean match = uut.eval(cls);
105
106 assertThat(match, is(false));
107 }
108
109 @Test
110 public void rejectsIfTheInterfaceIsNotAnnotatedWithThePropertySetAnnotation()
111 {
112 final JavaClass cls = mock(JavaClass.class);
113 when(cls.isInterface()).thenReturn(true);
114 final List<JavaAnnotation> annotations = new ArrayList<JavaAnnotation>(0);
115 when(cls.getAnnotations()).thenReturn(annotations);
116
117 final boolean match = uut.eval(cls);
118
119 assertThat(match, is(false));
120 }
121
122 @Test
123 public void rejectsIfInterfaceIsAnnotatedWithOtherAnnotation()
124 {
125 final JavaClass annotationClass = mock(JavaClass.class);
126 when(annotationClass.getFullyQualifiedName()).thenReturn(
127 PropertyKeyName.class.getName());
128
129 final JavaAnnotation annotation = mock(JavaAnnotation.class);
130 when(annotation.getType()).thenReturn(annotationClass);
131
132 final JavaClass cls = mock(JavaClass.class);
133 when(cls.isInterface()).thenReturn(false);
134 final List<JavaAnnotation> annotations = new ArrayList<JavaAnnotation>(1);
135 annotations.add(annotation);
136 when(cls.getAnnotations()).thenReturn(annotations);
137
138 final boolean match = uut.eval(cls);
139
140 assertThat(match, is(false));
141 }
142 }