44import static org .junit .Assert .assertTrue ;
55import static org .mockito .Matchers .any ;
66import static org .mockito .Matchers .anyString ;
7+ import static org .mockito .Mockito .doReturn ;
78import static org .mockito .Mockito .mock ;
89import static org .mockito .Mockito .when ;
910
1516
1617import java .io .IOException ;
1718import java .io .StringWriter ;
19+ import java .lang .annotation .Annotation ;
1820import java .util .Arrays ;
1921import java .util .HashMap ;
2022import java .util .HashSet ;
@@ -122,19 +124,19 @@ public void run(CommandLine args, Io io) {
122124 public void warnsAboutInvalidElementWithCommandAnnotation () {
123125 final Element classElement = mock (Element .class );
124126 when (classElement .getKind ()).thenReturn (ElementKind .FIELD );
125- when ( roundEnv . getElementsAnnotatedWith ( any ( Class . class )) )
126- .thenReturn ( new HashSet < Element >( Arrays . asList ( classElement )) );
127+ doReturn ( new HashSet <>( Arrays . asList ( classElement ))). when ( roundEnv )
128+ .getElementsAnnotatedWith ( Command . class );
127129
128- Set annotations = new HashSet <Element >();
130+ Set < TypeElement > annotations = new HashSet <>();
129131 assertFalse (processor .process (annotations , roundEnv ));
130132 }
131133
132134 @ Test
133135 public void worksWithoutCommands () {
134- when ( roundEnv . getElementsAnnotatedWith ( any ( Class . class )) )
135- .thenReturn ( new HashSet <>( Arrays . asList () ));
136+ doReturn ( new HashSet <>( Arrays . asList ())). when ( roundEnv )
137+ .getElementsAnnotatedWith (( Class < Annotation >) any ( Class . class ));
136138
137- Set annotations = new HashSet <>();
139+ Set < TypeElement > annotations = new HashSet <>();
138140 assertTrue (processor .process (annotations , roundEnv ));
139141 assertFalse (stringWriter .toString ().contains (".class" ));
140142 }
@@ -144,7 +146,7 @@ public void worksWithOneCommands() {
144146 final Element classElement = mock (TypeElement .class );
145147 when (classElement .getKind ()).thenReturn (ElementKind .CLASS );
146148 Command annotation = CommandAnnotationExample1 .class .getAnnotation (Command .class );
147- when (classElement .getAnnotation (Command .class )). thenReturn ( annotation );
149+ doReturn ( annotation ). when (classElement ) .getAnnotation (Command .class );
148150 when (roundEnv .getElementsAnnotatedWith (any (Class .class )))
149151 .thenReturn (new HashSet <>(Arrays .asList (classElement )));
150152
@@ -154,7 +156,7 @@ public void worksWithOneCommands() {
154156 when (mockedElementUtils .getBinaryName ((TypeElement ) classElement ))
155157 .thenReturn (mockedName );
156158
157- Set annotations = new HashSet <>();
159+ Set < TypeElement > annotations = new HashSet <>();
158160 assertTrue (processor .process (annotations , roundEnv ));
159161 assertTrue (stringWriter .toString ().contains ("TestTest.class" ));
160162 }
@@ -166,9 +168,9 @@ public void generateCorrectCodeWithTwoCommands() {
166168 when (classElement1 .getKind ()).thenReturn (ElementKind .CLASS );
167169 when (classElement2 .getKind ()).thenReturn (ElementKind .CLASS );
168170 Command annotation = CommandAnnotationExample1 .class .getAnnotation (Command .class );
169- when (classElement1 .getAnnotation (Command .class )). thenReturn ( annotation );
171+ doReturn ( annotation ). when (classElement1 ) .getAnnotation (Command .class );
170172 annotation = CommandAnnotationExample2 .class .getAnnotation (Command .class );
171- when (classElement2 .getAnnotation (Command .class )). thenReturn ( annotation );
173+ doReturn ( annotation ). when (classElement2 ) .getAnnotation (Command .class );
172174
173175 when (roundEnv .getElementsAnnotatedWith (any (Class .class )))
174176 .thenReturn (new HashSet <>(Arrays .asList (classElement1 , classElement2 )));
@@ -185,7 +187,7 @@ public void generateCorrectCodeWithTwoCommands() {
185187 when (mockedElementUtils .getBinaryName ((TypeElement ) classElement2 ))
186188 .thenReturn (mockedName2 );
187189
188- Set annotations = new HashSet <>();
190+ Set < TypeElement > annotations = new HashSet <>();
189191 assertTrue (processor .process (annotations , roundEnv ));
190192 assertTrue (stringWriter .toString ().contains ("(\" commmand1\" , TestTest1.class)" ));
191193 assertTrue (stringWriter .toString ().contains ("(\" commmand2\" , TestTest2.class)" ));
0 commit comments