Created
June 19, 2018 11:57
-
-
Save ChristianSchwarz/94959c4e1605103d2b00e8a324a49d56 to your computer and use it in GitHub Desktop.
Return type overload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import net.bytebuddy.ByteBuddy; | |
| import net.bytebuddy.agent.ByteBuddyAgent; | |
| import net.bytebuddy.implementation.MethodDelegation; | |
| import org.junit.Test; | |
| import org.mockito.ArgumentMatchers; | |
| import org.mockito.internal.matchers.InstanceOf; | |
| import static java.lang.reflect.Modifier.PUBLIC; | |
| import static java.lang.reflect.Modifier.STATIC; | |
| import static net.bytebuddy.dynamic.loading.ClassReloadingStrategy.fromInstalledAgent; | |
| import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress; | |
| public class FooBar { | |
| static{ | |
| ByteBuddyAgent.install(); | |
| new ByteBuddy() | |
| .redefine(ArgumentMatchers.class) | |
| .defineMethod("any", int.class, PUBLIC | STATIC).intercept(MethodDelegation.to(AnyIntMatcher.class)) | |
| .make() | |
| .load(ArgumentMatchers.class.getClassLoader(), fromInstalledAgent()); | |
| } | |
| public static class AnyIntMatcher{ | |
| public static int any(){ | |
| mockingProgress().getArgumentMatcherStorage().reportMatcher(new InstanceOf(Integer.class, "<any integer>")); | |
| return 0; | |
| } | |
| } | |
| @Test | |
| public void name() { | |
| foo(ArgumentMatchers.any()); | |
| } | |
| public void foo(int v){ | |
| System.out.println(v); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment