package org.jmock.test.unit.lib.legacy;

import java.io.File;

import org.jmock.api.Imposteriser;
import org.jmock.imposters.ByteBuddyClassImposteriser;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.jmock.test.acceptance.AbstractImposteriserParameterResolver;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

/**
 * This used to fail in Java 8 as cglib-nodep used asm:5.0.3 which required
 * jdk<=7 Now we use cglib (not cglib-nodep) and override asm to 5.0.4
 * 
 * @see https://github.com/jmock-developers/jmock-library/issues/79
 * @see https://github.com/cglib/cglib/issues/20
 * 
 */
public class Java8Issue79UnitTest {
    public final JUnit4Mockery context = new JUnit4Mockery();

    /**
     * However it fails in java 11 as asm and cglib do not appear to support java
     * 11 yet. Migrate all code to ByteBuddyClassImposteriser to solve this issue.
     * 
     * java.lang.UnsupportedOperationException at
     * org.objectweb.asm.ClassVisitor.visitNestMemberExperimental(ClassVisitor.java:248)
     * 
     * @param imposteriserImpl
     */
    @DisabledOnJre({ JRE.JAVA_11 })
    @ParameterizedTest
    @ArgumentsSource(ClassImposteriserParameterResolver.class)
    public void testMock(Imposteriser imposteriserImpl) {
        context.setImposteriser(imposteriserImpl);
        context.mock(File.class);
    }

    @ParameterizedTest
    @ArgumentsSource(ByteBuddyImposteriserParameterResolver.class)
    public void testByteBuddyImposteriser(Imposteriser imposteriserImpl) {
        context.setImposteriser(imposteriserImpl);
        context.mock(File.class);
    }

    public static class ByteBuddyImposteriserParameterResolver extends AbstractImposteriserParameterResolver {
        public ByteBuddyImposteriserParameterResolver() {
            super(ByteBuddyClassImposteriser.INSTANCE);
        }
    }

    public static class ClassImposteriserParameterResolver extends AbstractImposteriserParameterResolver {
        public ClassImposteriserParameterResolver() {
            super(ClassImposteriser.INSTANCE);
        }
    }
}

@@ -56,16 +56,46 @@
 .File;%0A%0A
+import javax.sql.DataSource;%0A%0A
 import o
@@ -113,32 +113,32 @@
 i.Imposteriser;%0A
-
 import org.jmock
@@ -197,33 +197,21 @@
 ock.
-integration.
 junit
-4
+5
 .JUnit
-4
+5
 Mock
@@ -432,16 +432,74 @@
 on.JRE;%0A
+import org.junit.jupiter.api.extension.RegisterExtension;%0A
 import o
@@ -897,20 +897,21 @@
 ass 
-Java8
 Issue79
+And127
 Unit
@@ -917,16 +917,44 @@
 tTest %7B%0A
+    %0A    @RegisterExtension%0A
     publ
@@ -963,25 +963,25 @@
  final JUnit
-4
+5
 Mockery cont
@@ -995,17 +995,17 @@
 ew JUnit
-4
+5
 Mockery(
@@ -1855,32 +1855,32 @@
 osteriserImpl);%0A
-
         context.
@@ -1889,32 +1889,72 @@
 ck(File.class);%0A
+        context.mock(DataSource.class);%0A
     %7D%0A%0A    publi

Add issue #127 test