Commit graph

8 commits

Author SHA1 Message Date
HeshamHM28
83f335ed04 fix asserts 2026-02-17 03:29:58 +02:00
HeshamHM28
4c976415ef Replace Regex with tree-sitter 2026-02-16 08:32:55 +02:00
Mohamed Ashraf
abf2c98994 chore: merge omni-java into fix/java-exception-assignment-instrumentation
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>
2026-02-11 12:52:15 +00:00
HeshamHM28
4740725af7 fix asserts 2026-02-11 01:59:04 +02:00
Mohamed Ashraf
e207b83a87 fix: handle assertThrows variable assignment in Java instrumentation
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>
2026-02-10 21:22:21 +00:00
Mohamed Ashraf
8d42ed93dd test(05-02): add concurrency-aware assertion removal tests
- 14 new tests in TestConcurrencyPatterns class
- synchronized blocks/methods preserved after transformation
- volatile field reads, AtomicInteger ops preserved
- ConcurrentHashMap, Thread.sleep, wait/notify patterns preserved
- ReentrantLock, CountDownLatch patterns preserved
- Real-world TokenBucket and CircularBuffer patterns validated
- AssertJ assertion on synchronized method call validated
- Total: 71 tests (57 existing + 14 new), all passing
2026-02-06 13:27:41 +00:00
misrasaurabh1
0ff54b5043 better unit test discovery java 2026-02-05 23:57:13 -08:00
Saurabh Misra
31c90f0391 feat: implement Java assertion removal transformer
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>
2026-02-03 09:02:25 +00:00