Validating Java Method Descriptor Parsing in JADX
This test suite validates the functionality of the DescriptorParser class in the JADX Java input plugin, focusing on parsing Java method descriptors. It ensures accurate parsing of both primitive types and object references in method signatures, verifying the correct extraction of return types and argument types.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
skylot/jadx
jadx-plugins/jadx-java-input/src/test/java/jadx/plugins/input/java/utils/DescriptorParserTest.java
package jadx.plugins.input.java.utils;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import jadx.plugins.input.java.data.JavaMethodRef;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
class DescriptorParserTest {
@Test
public void testPrimitives() {
check("()V", "V");
check("(I)D", "D", "I");
}
@Test
public void testObjects() {
check("(Ljava/lang/String;Ljava/lang/Object;)V", "V", "Ljava/lang/String;", "Ljava/lang/Object;");
}
@SuppressWarnings("CatchMayIgnoreException")
private void check(String desc, String retType, String... argTypes) {
JavaMethodRef mthRef = new JavaMethodRef();
try {
DescriptorParser.fillMethodProto(desc, mthRef);
} catch (Exception e) {
fail("Parse failed for: " + desc, e);
}
assertThat(mthRef.getReturnType()).isEqualTo(retType);
assertThat(mthRef.getArgTypes()).isEqualTo(Arrays.asList(argTypes));
}
}