"""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
