-
-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...src/test/java/net/bytebuddy/implementation/bind/annotation/DynamicConstantBinderTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.bytebuddy.implementation.bind.annotation; | ||
|
||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.description.type.TypeList; | ||
import net.bytebuddy.implementation.bind.MethodDelegationBinder; | ||
import net.bytebuddy.implementation.bytecode.assign.Assigner; | ||
import net.bytebuddy.utility.JavaConstant; | ||
import net.bytebuddy.utility.JavaType; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DynamicConstantBinderTest extends AbstractAnnotationBinderTest<DynamicConstant> { | ||
|
||
private static final String FOO = "foo", BAR = "bar"; | ||
|
||
@Mock | ||
private TypeDescription targetType; | ||
|
||
@Mock | ||
private TypeDescription.Generic typeDescription; | ||
|
||
@Mock | ||
private TypeList.Generic interfaces; | ||
|
||
@Mock | ||
private TypeList rawInterfaces; | ||
|
||
public DynamicConstantBinderTest() { | ||
super(DynamicConstant.class); | ||
} | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
when(target.getType()).thenReturn(typeDescription); | ||
when(typeDescription.asErasure()).thenReturn(targetType); | ||
when(instrumentedType.getInterfaces()).thenReturn(interfaces); | ||
when(interfaces.asErasures()).thenReturn(rawInterfaces); | ||
} | ||
|
||
@Override | ||
protected TargetMethodAnnotationDrivenBinder.ParameterBinder<DynamicConstant> getSimpleBinder() { | ||
return DynamicConstant.Binder.INSTANCE; | ||
} | ||
|
||
@Test | ||
public void testDynamicConstant() throws Exception { | ||
doReturn(void.class).when(annotation).bootstrapReturnType(); | ||
doReturn(void.class).when(annotation).bootstrapOwner(); | ||
doReturn(new Class<?>[] {Object.class}).when(annotation).bootstrapParameterTypes(); | ||
when(annotation.invokedynamic()).thenReturn(false); | ||
when(annotation.name()).thenReturn(FOO); | ||
when(annotation.bootstrapName()).thenReturn(BAR); | ||
when(annotation.bootstrapType()).thenReturn(JavaConstant.MethodHandle.HandleType.INVOKE_STATIC); | ||
when(targetType.isAssignableFrom(JavaType.METHOD_HANDLE.getTypeStub())).thenReturn(true); | ||
MethodDelegationBinder.ParameterBinding<?> parameterBinding = DynamicConstant.Binder.INSTANCE | ||
.bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); | ||
assertThat(parameterBinding.isValid(), is(true)); | ||
} | ||
|
||
@Test | ||
public void testDynamicConstantInvokedynamic() throws Exception { | ||
doReturn(void.class).when(annotation).bootstrapReturnType(); | ||
doReturn(void.class).when(annotation).bootstrapOwner(); | ||
doReturn(new Class<?>[] {Object.class}).when(annotation).bootstrapParameterTypes(); | ||
when(annotation.invokedynamic()).thenReturn(true); | ||
when(annotation.name()).thenReturn(FOO); | ||
when(annotation.bootstrapName()).thenReturn(BAR); | ||
when(annotation.bootstrapType()).thenReturn(JavaConstant.MethodHandle.HandleType.INVOKE_STATIC); | ||
when(targetType.isAssignableFrom(JavaType.METHOD_HANDLE.getTypeStub())).thenReturn(true); | ||
MethodDelegationBinder.ParameterBinding<?> parameterBinding = DynamicConstant.Binder.INSTANCE | ||
.bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); | ||
assertThat(parameterBinding.isValid(), is(true)); | ||
} | ||
} |