Merge pull request #2344 from codeflash-ai/fix-java-testgen-syntax

fix: add Java syntax rules and abstract class handling guidelines
This commit is contained in:
Saurabh Misra 2026-02-01 12:32:57 -08:00 committed by GitHub
commit ae63b4fb3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -53,6 +53,18 @@ Guidelines:
7. Do NOT use mocks unless absolutely necessary
8. Keep tests simple and focused on one assertion per test when possible
CRITICAL - Java Syntax Rules:
- Java does NOT support import aliasing (e.g., "import X as Y" is INVALID)
- Use fully qualified names or regular imports only
- Example: Use "java.util.Base64.getEncoder()" or "import java.util.Base64;" NOT "import java.util.Base64 as Foo;"
CRITICAL - Handling Complex Parameter Types:
- If a function parameter is an abstract class or interface (e.g., Value, Key), use the REAL factory methods or concrete implementations from the library, NOT custom mock classes
- NEVER create a custom class that extends an abstract class unless you implement ALL abstract methods
- Prefer using static factory methods like Value.get("string"), Value.get(123), etc.
- If the real class has a builder or factory pattern, use it
- Check if there are concrete implementations you can instantiate directly
Function to test: {function_name}
"""
@ -71,6 +83,18 @@ Guidelines:
8. Do NOT use mocks unless absolutely necessary
9. Keep tests simple and focused on one assertion per test when possible
CRITICAL - Java Syntax Rules:
- Java does NOT support import aliasing (e.g., "import X as Y" is INVALID)
- Use fully qualified names or regular imports only
- Example: Use "java.util.Base64.getEncoder()" or "import java.util.Base64;" NOT "import java.util.Base64 as Foo;"
CRITICAL - Handling Complex Parameter Types:
- If a function parameter is an abstract class or interface (e.g., Value, Key), use the REAL factory methods or concrete implementations from the library, NOT custom mock classes
- NEVER create a custom class that extends an abstract class unless you implement ALL abstract methods
- Prefer using static factory methods like Value.get("string"), Value.get(123), etc.
- If the real class has a builder or factory pattern, use it
- Check if there are concrete implementations you can instantiate directly
Function to test: {function_name}
"""
@ -97,6 +121,9 @@ IMPORTANT REQUIREMENTS:
2. You MUST import the class under test: import {module_path};
3. The test class MUST be named {class_name}Test
4. Create an instance of {class_name} in @BeforeEach or directly in test methods
5. CRITICAL: Do NOT create custom classes that extend abstract classes or interfaces.
Instead, use factory methods or concrete implementations from the library.
Example: For com.aerospike.client.Value, use Value.get("string"), Value.get(123), etc.
Wrap your response in a Java code block (```java ... ```).
@ -148,6 +175,9 @@ IMPORTANT REQUIREMENTS:
3. The test class MUST be named {class_name}Test
4. Use JUnit 4 annotations and imports (NOT JUnit 5/Jupiter)
5. Create an instance of {class_name} in @Before or directly in test methods
6. CRITICAL: Do NOT create custom classes that extend abstract classes or interfaces.
Instead, use factory methods or concrete implementations from the library.
Example: For com.aerospike.client.Value, use Value.get("string"), Value.get(123), etc.
Wrap your response in a Java code block (```java ... ```).
@ -278,6 +308,14 @@ def _validate_java_syntax(code: str) -> bool:
if "class " not in code:
return False
# Check for invalid import aliasing (Java doesn't support "import X as Y")
# Check for invalid import aliasing (Java doesn't support "import X as Y")
if re.search(r'import\s+[\w.]+\s+as\s+\w+', code):
return False
return True
return False
return True