Back to Repositories

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

The test suite provides comprehensive coverage for Java method descriptor parsing:

Key areas tested:
  • Primitive type parsing in method signatures
  • Object reference parsing with fully qualified class names
  • Return type extraction validation
  • Multiple argument type handling
Edge cases include empty parameter lists and mixed primitive/object signatures.

Implementation Analysis

The testing approach utilizes JUnit Jupiter framework with a systematic verification pattern. Each test case employs a helper method ‘check’ that validates both return types and argument types extracted from method descriptors.

Technical implementation features:
  • AssertJ assertions for precise validation
  • Parameterized test helper method
  • Exception handling verification
  • Array-based argument validation

Technical Details

Testing infrastructure includes:
  • JUnit Jupiter test framework
  • AssertJ assertion library
  • Custom JavaMethodRef class for method signature representation
  • DescriptorParser utility class
  • Arrays utility for argument comparison

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Focused test methods with clear naming conventions
  • Robust error handling with meaningful failure messages
  • Reusable test helper methods
  • Clean separation of test cases for primitives and objects
  • Proper assertion usage for detailed verification

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));
	}
}