The type inference for assertEquals always used the first argument, but
JUnit 4's 3-arg overload is assertEquals(message, expected, actual).
When the first arg was a string message, the type was incorrectly inferred
as String instead of the actual expected value's type. Now detects the
message-first pattern and uses the second argument for type inference.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update 41 test expectations in test_java_assertion_removal.py to match
the return type inference behavior introduced in commit 9e5880f0. Tests
now expect inferred types (int, boolean, String, double) instead of
Object for _cf_result variables.
Fix 2 ruff PLR1714 lint issues in remove_asserts.py by using set
membership tests instead of chained or comparisons.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolved conflicts by merging the best of both branches:
- Kept exception_class field from PR for better exception type detection
- Adopted more general variable assignment detection from omni-java
- Combined exception replacement logic to use exception_class with fallback
- Added double catch (specific exception + generic Exception) for robustness
- Merged test cases from both branches with updated expectations
Changes:
- Updated AssertionMatch to include all fields: assigned_var_type, assigned_var_name, exception_class
- Lambda extraction now works for all exception assertions
- Exception class extraction specifically for assertThrows
- Variable assignment detection handles final modifier and fully qualified types
- Exception replacement uses exception_class or falls back to assigned_var_type
- All 80 tests passing
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When assertThrows was assigned to a variable to validate exception
properties, the transformation generated invalid Java syntax by
replacing the assertThrows call with try-catch while leaving the
variable assignment intact.
Example of invalid output:
IllegalArgumentException e = try { code(); } catch (Exception) {}
This fix detects variable assignments, extracts the exception type
from assertThrows arguments, and generates proper exception capture:
IllegalArgumentException e = null;
try { code(); } catch (IllegalArgumentException _cf_caught1) { e = _cf_caught1; } catch (Exception _cf_ignored1) {}
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add a robust Java assert removal transformer to convert generated unit
tests into regression tests. This removes assertion statements while
preserving function calls, enabling behavioral verification by comparing
outputs between original and optimized code.
Key features:
- Support for JUnit 5 assertions (assertEquals, assertTrue, assertThrows, etc.)
- Support for JUnit 4 assertions (org.junit.Assert.*)
- Support for AssertJ fluent assertions (assertThat().isEqualTo())
- Support for TestNG and Hamcrest assertions
- Framework auto-detection from imports
- Handles assertAll grouped assertions
- Preserves non-assertion code (setup, Mockito mocks, etc.)
- 57 comprehensive tests with exact string equality assertions
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>