File tree Expand file tree Collapse file tree 4 files changed +53
-6
lines changed
main/java/io/swagger/jaxrs/config Expand file tree Collapse file tree 4 files changed +53
-6
lines changed Original file line number Diff line number Diff line change 139139 <artifactId >testng</artifactId >
140140 <scope >test</scope >
141141 </dependency >
142+ <dependency >
143+ <groupId >org.mockito</groupId >
144+ <artifactId >mockito-all</artifactId >
145+ </dependency >
142146 </dependencies >
143147 <properties >
144148 <coverage .complexity.minimum>0.29</coverage .complexity.minimum>
Original file line number Diff line number Diff line change 88public class DefaultJaxrsScanner extends AbstractScanner implements JaxrsScanner {
99 private boolean prettyPrint = false ;
1010
11- public Set <Class <?>> classesFromContext (
12- Application app ,
13- ServletConfig sc ) {
11+ public Set <Class <?>> classesFromContext (Application app , ServletConfig sc ) {
1412 Set <Class <?>> output = new HashSet <Class <?>>();
1513 if (app != null ) {
1614 Set <Class <?>> clz = app .getClasses ();
@@ -20,9 +18,7 @@ public Set<Class<?>> classesFromContext(
2018 Set <Object > singletons = app .getSingletons ();
2119 if (singletons != null ) {
2220 for (Object o : singletons ) {
23- if (o instanceof Class ) {
24- output .add ((Class ) o );
25- }
21+ output .add (o .getClass ());
2622 }
2723 }
2824 }
Original file line number Diff line number Diff line change 1+ package io .swagger ;
2+
3+ import static org .mockito .Mockito .mock ;
4+ import static org .mockito .Mockito .when ;
5+ import static org .testng .Assert .assertEquals ;
6+
7+ import io .swagger .jaxrs .config .DefaultJaxrsScanner ;
8+
9+ import com .google .common .base .Function ;
10+ import com .google .common .collect .Iterables ;
11+ import com .google .common .collect .Sets ;
12+ import org .testng .annotations .Test ;
13+
14+ import java .util .Set ;
15+
16+ import javax .ws .rs .core .Application ;
17+
18+ public class DefaultJaxrsScannerTest {
19+
20+ @ Test (description = "should return singletones" )
21+ public void classesFromContextTest () {
22+ Application app = mock (Application .class );
23+ Set <Object > singletons = Sets .newHashSet (new io .swagger .jaxrs .listing .ApiListingResource (), new DefaultJaxrsScannerTest ());
24+
25+ when (app .getClasses ()).thenReturn (null );
26+ when (app .getSingletons ()).thenReturn (singletons );
27+
28+ DefaultJaxrsScanner scanner = new DefaultJaxrsScanner ();
29+ Set <Class <?>> output = scanner .classesFromContext (app , null );
30+
31+ Set <Class <?>> classes = Sets .newHashSet (Iterables .transform (singletons , new Function <Object , Class <?>>() {
32+ @ Override
33+ public Class <?> apply (Object o ) {
34+ return o .getClass ();
35+ }
36+ }));
37+
38+ assertEquals (output , classes );
39+ }
40+ }
Original file line number Diff line number Diff line change 507507 <version >${testng-version} </version >
508508 <scope >test</scope >
509509 </dependency >
510+ <dependency >
511+ <groupId >org.mockito</groupId >
512+ <artifactId >mockito-all</artifactId >
513+ <version >${mockito-version} </version >
514+ <scope >test</scope >
515+ </dependency >
510516 <dependency >
511517 <groupId >javax.servlet</groupId >
512518 <artifactId >servlet-api</artifactId >
558564
559565 <junit-version >4.8.2</junit-version >
560566 <testng-version >6.9.4</testng-version >
567+ <mockito-version >1.9.5</mockito-version >
561568 <surefire-version >2.18.1</surefire-version >
562569 <maven-plugin-version >1.0.0</maven-plugin-version >
563570 <commons-lang-version >3.2.1</commons-lang-version >
You can’t perform that action at this time.
0 commit comments