package net.bytebuddy.implementation.bytecode.assign; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.implementation.Implementation; import net.bytebuddy.implementation.bytecode.StackManipulation; import net.bytebuddy.test.utility.MockitoRule; import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.mockito.Mock; import org.objectweb.asm.MethodVisitor; import java.util.Arrays; import java.util.Collection; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.verifyZeroInteractions; @RunWith(Parameterized.class) public class AssignerRefusingTest { private final boolean dynamicallyTyped; @Rule public TestRule mockitoRule = new MockitoRule(this); @Mock private TypeDescription.Generic first, second; @Mock private MethodVisitor methodVisitor; @Mock private Implementation.Context implementationContext; public AssignerRefusingTest(boolean dynamicallyTyped) { this.dynamicallyTyped = dynamicallyTyped; } @Parameterized.Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[]{false}, new Object[]{true}); } @After public void tearDown() throws Exception { verifyZeroInteractions(methodVisitor); verifyZeroInteractions(implementationContext); } @Test public void testAssignmentEqual() throws Exception { StackManipulation stackManipulation = Assigner.Refusing.INSTANCE.assign(first, first, Assigner.Typing.of(dynamicallyTyped)); assertThat(stackManipulation.isValid(), is(false)); } @Test public void testAssignmentNotEqual() throws Exception { StackManipulation stackManipulation = Assigner.Refusing.INSTANCE.assign(first, second, Assigner.Typing.of(dynamicallyTyped)); assertThat(stackManipulation.isValid(), is(false)); } }