From ebc396ca0b7257ff9fc3844cce118a6ea38a9004 Mon Sep 17 00:00:00 2001
From: Mat Booth <mat.booth@redhat.com>
Date: Mon, 11 Mar 2019 10:30:32 +0000
Subject: [PATCH 1/3] Patch out dependency on JMockit

---
 .../jersey/server/ResourceConfigTest.java     | 50 -----------
 .../scanning/PackageNamesScannerTest.java     | 81 -----------------
 .../ext/cdi1x/internal/CdiUtilTest.java       | 45 ----------
 .../FormDataMultiPartReaderWriterTest.java    | 86 -------------------
 4 files changed, 262 deletions(-)

diff --git a/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java b/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java
index 4f4ee99..b0f3bb3 100644
--- a/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java
+++ b/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java
@@ -45,9 +45,6 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
-import mockit.Mocked;
-import mockit.Verifications;
-
 /**
  * @author Pavel Bucek (pavel.bucek at oracle.com)
  */
@@ -350,53 +347,6 @@ public class ResourceConfigTest {
         assertThat(classes, hasItem(InnerStaticClass.PublicClass.class));
     }
 
-    /**
-     * Reproducer for OWLS-19790: Invalidate resource finders in resource config only when needed.
-     */
-    @Test
-    public void testInvalidateResourceFinders(@Mocked final PackageNamesScanner scanner) throws Exception {
-        final ResourceConfig resourceConfig = new ResourceConfig()
-                .packages(false, PublicRootResourceClass.class.getPackage().getName());
-
-        // Scan packages.
-        resourceConfig.getClasses();
-
-        // No reset.
-        new Verifications() {{
-            scanner.reset();
-            times = 0;
-        }};
-
-        resourceConfig.register(InnerStaticClass.PublicClass.class);
-
-        // Reset - we called getClasses() on ResourceConfig.
-        new Verifications() {{
-            scanner.reset();
-            times = 1;
-        }};
-
-        // No reset.
-        resourceConfig.register(PublicRootResourceClass.class);
-        resourceConfig.register(PublicRootResourceInnerStaticClass.PublicClass.class);
-
-        // No reset - simple registering does not invoke cache invalidation and reset of resource finders.
-        new Verifications() {{
-            scanner.reset();
-            times = 1;
-        }};
-
-        // Scan packages.
-        resourceConfig.getClasses();
-
-        resourceConfig.registerFinder(new PackageNamesScanner(new String[] {"javax.ws.rs"}, false));
-
-        // Reset - we called getClasses() on ResourceConfig.
-        new Verifications() {{
-            scanner.reset();
-            times = 2;
-        }};
-    }
-
     @Test
     public void testResourceFinderStreamsClosed() throws IOException {
         System.out.println(new ResourceConfig().packages("javax.ws.rs").getClasses());
diff --git a/core-server/src/test/java/org/glassfish/jersey/server/internal/scanning/PackageNamesScannerTest.java b/core-server/src/test/java/org/glassfish/jersey/server/internal/scanning/PackageNamesScannerTest.java
index 29b18c0..563b998 100644
--- a/core-server/src/test/java/org/glassfish/jersey/server/internal/scanning/PackageNamesScannerTest.java
+++ b/core-server/src/test/java/org/glassfish/jersey/server/internal/scanning/PackageNamesScannerTest.java
@@ -16,11 +16,6 @@
 
 package org.glassfish.jersey.server.internal.scanning;
 
-import mockit.Expectations;
-import mockit.Injectable;
-import mockit.Tested;
-import mockit.Verifications;
-import mockit.integration.junit4.JMockit;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -46,7 +41,6 @@ import static org.junit.Assert.fail;
  * @author Eric Navarro
  * @author Michal Gajdos
  */
-@RunWith(JMockit.class)
 public class PackageNamesScannerTest {
 
     private static final String[] packages = {"javax.ws.rs"};
@@ -96,81 +90,6 @@ public class PackageNamesScannerTest {
     }
 
 
-    @Tested
-    PackageNamesScanner scanner1 = new PackageNamesScanner(new String[]{"javax.ws.rs"}, false);
-    @Tested
-    PackageNamesScanner scanner2 = new PackageNamesScanner(new String[]{"javax.ws.rs.core"}, false);
-    @Tested
-    PackageNamesScanner scanner3 = new PackageNamesScanner(new String[]{"javax.ws.rs.client"}, false);
-
-    /**
-     * Reproducer for OWLS-19790: When scanner is reset the underlying JAR input streams should be closed.
-     */
-    @Test
-    public void testInputStreamClosedAfterReset() throws Exception {
-        JarInputStream stream = new JarInputStream(
-                new ByteArrayInputStream("test".getBytes(), 0, 4));
-
-        new Expectations(InputStream.class){};
-
-        scanner1.reset();
-
-        scanner2.reset();
-        scanner2.reset();
-
-        scanner3.reset();
-
-        new Verifications() {{
-            stream.close();
-            times = 4;
-        }};
-    }
-
-    /**
-     * Reproducer for OWLS-19790: When scanner is closed the underlying JAR input streams should be closed as well.
-     */
-    @Test
-    public void testInputStreamClosedAfterClose()  throws Exception {
-
-        JarInputStream stream = new JarInputStream(
-                new ByteArrayInputStream("test".getBytes(), 0, 4));
-
-        new Expectations(JarInputStream.class){};
-
-        scanner1.close();
-
-        scanner2.close();
-        scanner2.close();
-
-        scanner3.close();
-
-        new Verifications() {{
-            stream.close();
-            times = 3;
-        }};
-    }
-
-    /**
-     * Reproducer for OWLS-19790: When we iterate through the all entries provided by a scanner JAR input stream should be closed.
-     */
-    @Tested
-    PackageNamesScanner scanner = new PackageNamesScanner(new String[]{"javax.ws.rs"}, false);
-    @Test
-    public void testInputStreamClosedAfterIteration(@Injectable("false") boolean recursive) throws Exception {
-        JarInputStream stream = new JarInputStream(
-                new ByteArrayInputStream("test".getBytes(), 0, 4));
-
-        new Expectations(JarInputStream.class) {{
-            stream.getNextJarEntry();
-            result = null;
-            stream.close();
-        }};
-
-        while (scanner.hasNext()) {
-            scanner.next();
-        }
-    }
-
     private ClassLoader createTestClassLoader(final String scheme,
                                               final URLStreamHandler urlStreamHandler,
                                               final String resourceFilePath) {
diff --git a/ext/cdi/jersey-cdi1x/src/test/java/org/glassfish/jersey/ext/cdi1x/internal/CdiUtilTest.java b/ext/cdi/jersey-cdi1x/src/test/java/org/glassfish/jersey/ext/cdi1x/internal/CdiUtilTest.java
index 0cdafe1..bcc2a66 100644
--- a/ext/cdi/jersey-cdi1x/src/test/java/org/glassfish/jersey/ext/cdi1x/internal/CdiUtilTest.java
+++ b/ext/cdi/jersey-cdi1x/src/test/java/org/glassfish/jersey/ext/cdi1x/internal/CdiUtilTest.java
@@ -28,11 +28,6 @@ import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
-import mockit.Mock;
-import mockit.MockUp;
-import mockit.Mocked;
-import mockit.Verifications;
-
 /**
  * Unit tests for {@link org.glassfish.jersey.ext.cdi1x.internal.CdiUtil}.
  *
@@ -48,34 +43,6 @@ public class CdiUtilTest {
         }
     }
 
-    @Test
-    public void getBeanManagerCustom(@Mocked final TestBeanManagerProvider custom,
-                                     @Mocked final DefaultBeanManagerProvider fallback) throws Exception {
-        CdiUtil.getBeanManager();
-
-        new Verifications() {{
-            custom.getBeanManager(); times = 1;
-            fallback.getBeanManager(); times = 0;
-        }};
-    }
-
-    @Test
-    public void getDefaultBeanManagerDefault(@Mocked final DefaultBeanManagerProvider fallback) throws Exception {
-        new MockUp<CdiUtil>() {
-            @Mock
-            @SuppressWarnings("UnusedDeclaration")
-            <T> T lookupService(final Class<T> clazz) {
-                return null;
-            }
-        };
-
-        CdiUtil.getBeanManager();
-
-        new Verifications() {{
-            fallback.getBeanManager(); times = 1;
-        }};
-    }
-
     @Priority(500)
     public static class MyServiceOne implements MyService {
     }
@@ -115,16 +82,4 @@ public class CdiUtilTest {
         assertThat(CdiUtil.createHk2InjectionManagerStore(), instanceOf(TestInjectionManagerStore.class));
     }
 
-    @Test
-    public void createHk2LocatorManagerDefault() throws Exception {
-        new MockUp<CdiUtil>() {
-            @Mock
-            @SuppressWarnings("UnusedDeclaration")
-            <T> T lookupService(final Class<T> clazz) {
-                return null;
-            }
-        };
-
-        assertThat(CdiUtil.createHk2InjectionManagerStore(), instanceOf(SingleInjectionManagerStore.class));
-    }
 }
diff --git a/media/multipart/src/test/java/org/glassfish/jersey/media/multipart/internal/FormDataMultiPartReaderWriterTest.java b/media/multipart/src/test/java/org/glassfish/jersey/media/multipart/internal/FormDataMultiPartReaderWriterTest.java
index b0a851c..f57d4e7 100644
--- a/media/multipart/src/test/java/org/glassfish/jersey/media/multipart/internal/FormDataMultiPartReaderWriterTest.java
+++ b/media/multipart/src/test/java/org/glassfish/jersey/media/multipart/internal/FormDataMultiPartReaderWriterTest.java
@@ -69,10 +69,6 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import mockit.Expectations;
-import mockit.Mocked;
-import mockit.Verifications;
-
 /**
  * Tests for multipart {@code MessageBodyReader} and {@code MessageBodyWriter} as well as {@code FormDataMultiPart} and {@code
  * FormDataParam} injections.
@@ -666,35 +662,6 @@ public class FormDataMultiPartReaderWriterTest extends MultiPartJerseyTest {
         }
     }
 
-    /**
-     * JERSEY-2663 reproducer. Make sure that temporary file created by MIMEPull is not copied into new temporary file created
-     * by Jersey.
-     */
-    @Test
-    public void testInjectedFileNotCopied(@Mocked final BodyPartEntity entity) throws Exception {
-        final FormDataMultiPart multipart = new FormDataMultiPart();
-        final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(),
-                "CONTENT");
-        multipart.bodyPart(bodypart);
-
-        final Response response = target().path("FileResource").path("InjectedFileNotCopied")
-                .request()
-                .post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
-
-        // Make sure that the Mimepull temp file has been moved to specific file.
-        new Verifications() {{
-            entity.moveTo(withInstanceOf(File.class));
-            times = 1;
-        }};
-
-        // Make sure that the temp file has been removed.
-        final String pathname = response.readEntity(String.class);
-        // Wait a second to make sure the file doesn't exist.
-        Thread.sleep(1000);
-
-        assertThat("Temporary file, " + pathname + ", on the server has not been removed",
-                new File(pathname).exists(), is(false));
-    }
 
     /**
      * JERSEY-2846 reproducer. Make sure that temporary file created by MIMEPull deleted after a successful request.
@@ -772,59 +739,6 @@ public class FormDataMultiPartReaderWriterTest extends MultiPartJerseyTest {
         }
     }
 
-    /**
-     * Mocked JERSEY-2794 reproducer. Real test is under integration tests.
-     */
-    @Test
-    public void mimeTempFileRemovedAfterAbortedUpload(@Mocked final MIMEMessage message) throws Exception {
-        new Expectations() {{
-            message.getAttachments();
-            result = new MIMEParsingException();
-        }};
-
-        final URL url = new URL(getBaseUri().toString() + "MediaTypeWithBoundaryResource");
-        final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-
-        connection.setRequestMethod("PUT");
-        connection.setRequestProperty("Accept", "text/plain");
-        connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=XXXX_YYYY");
-
-        connection.setDoOutput(true);
-        connection.connect();
-
-        final OutputStream outputStream = connection.getOutputStream();
-        outputStream.write("--XXXX_YYYY".getBytes());
-        outputStream.write('\n');
-        outputStream.write("Content-Type: text/plain".getBytes());
-        outputStream.write('\n');
-        outputStream.write("Content-Disposition: form-data; name=\"big-part\"".getBytes());
-        outputStream.write('\n');
-        outputStream.write('\n');
-
-        // Send big chunk of data.
-        for (int i = 0; i < 16 * 4096; i++) {
-            outputStream.write('E');
-            if (i % 1024 == 0) {
-                outputStream.flush();
-            }
-        }
-
-        // Do NOT send end of the MultiPart message to simulate the issue.
-
-        // Get Response ...
-        final int response = connection.getResponseCode();
-        // ... Disconnect.
-        connection.disconnect();
-
-        assertThat("Bad Request expected", response, is(400));
-
-        // Make sure that the Mimepull message and it's parts have been closed and temporary files deleted.
-        new Verifications() {{
-            message.close();
-            times = 1;
-        }};
-    }
-
     private void checkEntity(final String expected, final BodyPartEntity entity) throws IOException {
         // Convert the raw bytes into a String
         final InputStreamReader sr = new InputStreamReader(entity.getInputStream());
-- 
2.20.1

