1616
1717package org .glassfish .jersey .server .internal .scanning ;
1818
19+ import mockit .Expectations ;
20+ import mockit .Injectable ;
21+ import mockit .Tested ;
22+ import mockit .Verifications ;
23+ import mockit .integration .junit4 .JMockit ;
24+ import org .junit .Before ;
25+ import org .junit .Test ;
26+ import org .junit .runner .RunWith ;
27+
28+ import java .io .ByteArrayInputStream ;
1929import java .io .IOException ;
30+ import java .io .InputStream ;
2031import java .net .URL ;
2132import java .net .URLConnection ;
2233import java .net .URLStreamHandler ;
2637import java .util .Vector ;
2738import java .util .jar .JarInputStream ;
2839
29- import org .junit .Before ;
30- import org .junit .Test ;
3140import static org .junit .Assert .assertTrue ;
3241import static org .junit .Assert .fail ;
3342
34- import mockit .Expectations ;
35- import mockit .Mocked ;
36- import mockit .Verifications ;
37-
3843/**
3944 * Unit tests for {@link PackageNamesScanner}.
4045 *
4146 * @author Eric Navarro
4247 * @author Michal Gajdos
4348 */
49+ @ RunWith (JMockit .class )
4450public class PackageNamesScannerTest {
4551
4652 private static final String [] packages = {"javax.ws.rs" };
@@ -89,14 +95,23 @@ public void testInvalidScheme() {
8995 new PackageNamesScanner (createTestClassLoader ("bad" , createTestURLStreamHandler ("bad" ), jaxRsApiPath ), packages , false );
9096 }
9197
98+
99+ @ Tested
100+ PackageNamesScanner scanner1 = new PackageNamesScanner (new String []{"javax.ws.rs" }, false );
101+ @ Tested
102+ PackageNamesScanner scanner2 = new PackageNamesScanner (new String []{"javax.ws.rs.core" }, false );
103+ @ Tested
104+ PackageNamesScanner scanner3 = new PackageNamesScanner (new String []{"javax.ws.rs.client" }, false );
105+
92106 /**
93107 * Reproducer for OWLS-19790: When scanner is reset the underlying JAR input streams should be closed.
94108 */
95109 @ Test
96- public void testInputStreamClosedAfterReset (@ Mocked final JarInputStream stream ) throws Exception {
97- final PackageNamesScanner scanner1 = new PackageNamesScanner (new String [] {"javax.ws.rs" }, false );
98- final PackageNamesScanner scanner2 = new PackageNamesScanner (new String [] {"javax.ws.rs.core" }, false );
99- final PackageNamesScanner scanner3 = new PackageNamesScanner (new String [] {"javax.ws.rs.client" }, false );
110+ public void testInputStreamClosedAfterReset () throws Exception {
111+ JarInputStream stream = new JarInputStream (
112+ new ByteArrayInputStream ("test" .getBytes (), 0 , 4 ));
113+
114+ new Expectations (InputStream .class ){};
100115
101116 scanner1 .reset ();
102117
@@ -115,10 +130,12 @@ public void testInputStreamClosedAfterReset(@Mocked final JarInputStream stream)
115130 * Reproducer for OWLS-19790: When scanner is closed the underlying JAR input streams should be closed as well.
116131 */
117132 @ Test
118- public void testInputStreamClosedAfterClose (@ Mocked final JarInputStream stream ) throws Exception {
119- final PackageNamesScanner scanner1 = new PackageNamesScanner (new String [] {"javax.ws.rs" }, false );
120- final PackageNamesScanner scanner2 = new PackageNamesScanner (new String [] {"javax.ws.rs.core" }, false );
121- final PackageNamesScanner scanner3 = new PackageNamesScanner (new String [] {"javax.ws.rs.client" }, false );
133+ public void testInputStreamClosedAfterClose () throws Exception {
134+
135+ JarInputStream stream = new JarInputStream (
136+ new ByteArrayInputStream ("test" .getBytes (), 0 , 4 ));
137+
138+ new Expectations (JarInputStream .class ){};
122139
123140 scanner1 .close ();
124141
@@ -136,16 +153,19 @@ public void testInputStreamClosedAfterClose(@Mocked final JarInputStream stream)
136153 /**
137154 * Reproducer for OWLS-19790: When we iterate through the all entries provided by a scanner JAR input stream should be closed.
138155 */
156+ @ Tested
157+ PackageNamesScanner scanner = new PackageNamesScanner (new String []{"javax.ws.rs" }, false );
139158 @ Test
140- public void testInputStreamClosedAfterIteration (@ Mocked final JarInputStream stream ) throws Exception {
141- new Expectations () {{
159+ public void testInputStreamClosedAfterIteration (@ Injectable ("false" ) boolean recursive ) throws Exception {
160+ JarInputStream stream = new JarInputStream (
161+ new ByteArrayInputStream ("test" .getBytes (), 0 , 4 ));
162+
163+ new Expectations (JarInputStream .class ) {{
142164 stream .getNextJarEntry ();
143165 result = null ;
144166 stream .close ();
145167 }};
146168
147- final PackageNamesScanner scanner = new PackageNamesScanner (new String [] {"javax.ws.rs" }, false );
148-
149169 while (scanner .hasNext ()) {
150170 scanner .next ();
151171 }
0 commit comments