codeflash-internal/django/aiservice/tests/validators/test_java_validator.py
Saurabh Misra 198c0c1a4e
codeflash-omni-java (#2335)
# Pull Request Checklist

## Description
- [ ] **Breaking Changes**: Document any breaking changes (if
applicable)
- [ ] **Description of PR**: Clear and concise description of what this
PR accomplishes
- [ ] **Related Issues**: Link to any related issues or tickets

## Testing
- [ ] **Test cases Attached**: All relevant test cases have been
added/updated
- [ ] **Manual Testing**: Manual testing completed for the changes

## Monitoring & Debugging
- [ ] **Logging in place**: Appropriate logging has been added for
debugging user issues
- [ ] **Sentry will be able to catch errors**: Error handling ensures
Sentry can capture and report errors
- [ ] **Avoid Dev based/Prisma logging**: No development-only or
Prisma-specific logging in production code

## Configuration
- [ ] **Env variables newly added**: Any new environment variables are
documented in .env.example file or mentioned in description
---

## Additional Notes
<!-- Add any additional context, screenshots, or notes for reviewers
here -->

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: HeshamHM28 <HeshamMohamedFathy@outlook.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-39-200.ec2.internal>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Kevin Turcios <turcioskevinr@gmail.com>
Co-authored-by: Kevin Turcios <106575910+KRRT7@users.noreply.github.com>
2026-02-13 23:26:55 +05:30

40 lines
1.2 KiB
Python

"""Tests for Java validator module."""
from aiservice.validators.java_validator import validate_java_syntax
class TestJavaValidator:
"""Tests for tree-sitter based Java validation."""
def test_valid_simple_class(self) -> None:
"""Test a simple valid class."""
code = """
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
"""
is_valid, error = validate_java_syntax(code)
assert is_valid
assert error is None
def test_invalid_syntax(self) -> None:
"""Test invalid Java syntax is detected."""
code = "public class { }" # Missing class name
is_valid, error = validate_java_syntax(code)
assert not is_valid
assert error is not None
def test_empty_code(self) -> None:
"""Test empty code fails validation."""
is_valid, error = validate_java_syntax("")
assert not is_valid
assert error == "Empty code"
def test_caching_works(self) -> None:
"""Test that caching works (same code returns same result)."""
code = "public class Test {}"
result1 = validate_java_syntax(code)
result2 = validate_java_syntax(code)
assert result1 == result2