Skip to content

Commit

Permalink
add mocking for asm MethodNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jul 27, 2023
1 parent 0c8ec95 commit b079b1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private static boolean isStringAllUppercase(final String input) {
// I think it's best to only work with primitive types here, as other types should already have names
// and this dramatically cuts down on the number of methods analyzed because we aren't filtering by
// method name
if (!(method.computeDescriptor().getReturnType() instanceof PrimitiveType)) {
if (!(method.descriptor().getReturnType() instanceof PrimitiveType)) {
return null;
}
final List<IntPredicate> codes = new ArrayList<>(OPCODES_IN_ORDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.quality.Strictness;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

@ExtendWith(MockitoExtension.class)
class LvtAssignmentSuggesterTest {
Expand Down Expand Up @@ -81,19 +83,24 @@ void testSuggester(

final AsmClassData owner = mock(LENIENT);
final AsmMethodData method = mock(LENIENT);
final MethodNode methodNode = mock(LENIENT);
methodNode.instructions = new InsnList();

when(owner.kind()).thenReturn(ClassKind.CLASS);
when(owner.name()).thenReturn(methodOwner);
when(method.name()).thenReturn(methodName);

final MethodDescriptor desc = MethodDescriptor.parseDescriptor(methodDescriptor);
when(method.descriptor()).thenReturn(desc);
when(method.computeDescriptor()).thenReturn(desc);

// params() and returnType() methods will defer to the descriptor
when(method.params()).thenCallRealMethod();
when(method.param(anyInt())).thenCallRealMethod();
when(method.returnType()).thenCallRealMethod();

when(method.getNode()).thenReturn(methodNode);

if (methodOwner.equals(RANDOM_SOURCE_NAME)) {
when(owner.doesExtendOrImplement(this.randomSourceClass)).thenReturn(true);
} else {
Expand Down

0 comments on commit b079b1f

Please sign in to comment.