// tools/generate-tests/generators/concurrency-test-generator/java-templates.ts — SPEC-034
// Java/Kotlin concurrency and Pact test scaffolds
import { sanitizeJavaName } from './utils.js';
export function generateJavaConcurrencyTest(title) {
    const className = sanitizeJavaName(title);
    return [
        `// Concurrency tests for: ${title}`,
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        'import org.junit.jupiter.api.Test;',
        'import java.util.concurrent.*;',
        'import java.util.concurrent.atomic.AtomicInteger;',
        'import static org.junit.jupiter.api.Assertions.*;',
        '',
        `class ${className}ConcurrencyTest {`,
        '',
        '    @Test',
        '    void nConcurrentWritersProduceCorrectFinalState() throws Exception {',
        '        // Arrange',
        '        int N = 100;',
        '        AtomicInteger counter = new AtomicInteger(0);',
        '        ExecutorService executor = Executors.newFixedThreadPool(N);',
        '        CountDownLatch latch = new CountDownLatch(N);',
        '',
        '        // Act: N threads increment concurrently',
        '        for (int i = 0; i < N; i++) {',
        '            executor.submit(() -> {',
        '                counter.incrementAndGet(); // TODO: replace with your actual operation',
        '                latch.countDown();',
        '            });',
        '        }',
        '        latch.await(10, TimeUnit.SECONDS);',
        '        executor.shutdown();',
        '',
        '        // Assert: all increments applied',
        '        assertEquals(N, counter.get(), "Lost updates detected");',
        '    }',
        '',
        '    @Test',
        '    void deadlockDoesNotHangThread() throws Exception {',
        '        // Use ReentrantLock with tryLock(timeout) to detect deadlock',
        '        ReentrantLock lock = new ReentrantLock();',
        '        boolean acquired = lock.tryLock(5, TimeUnit.SECONDS);',
        '        try {',
        '            assertTrue(acquired, "Lock was not acquired within 5 seconds — potential deadlock");',
        '            // TODO: perform your operation here',
        '        } finally {',
        '            if (acquired) lock.unlock();',
        '        }',
        '    }',
        '}',
        '',
    ].join('\n');
}
export function generateJavaPactTest(title) {
    const className = sanitizeJavaName(title);
    return [
        `// Pact consumer contract tests for: ${title}`,
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        'import au.com.dius.pact.consumer.dsl.PactDslWithProvider;',
        'import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;',
        'import au.com.dius.pact.consumer.junit5.PactTestFor;',
        'import au.com.dius.pact.core.model.RequestResponsePact;',
        'import au.com.dius.pact.core.model.annotations.Pact;',
        'import org.junit.jupiter.api.Test;',
        'import org.junit.jupiter.api.extension.ExtendWith;',
        '',
        '@ExtendWith(PactConsumerTestExt.class)',
        `@PactTestFor(providerName = "MyProvider")`,
        `class ${className}PactConsumerTest {`,
        '',
        '    @Pact(consumer = "MyConsumer")',
        '    public RequestResponsePact createPact(PactDslWithProvider builder) {',
        `        return builder.given("resource exists")`,
        `            .uponReceiving("a valid request for ${title}")`,
        `            .path("/api/resource") // TODO: replace with actual path`,
        '            .method("GET")',
        '            .willRespondWith()',
        '            .status(200)',
        '            .body("{\\"id\\": \\"1\\", \\"name\\": \\"Resource\\"}") // TODO: define actual schema',
        '            .toPact();',
        '    }',
        '',
        '    @Test',
        '    @PactTestFor',
        '    void testProviderReturnsValidResponse() {',
        '        // TODO: call your service client and assert response shape',
        '    }',
        '}',
        '',
    ].join('\n');
}
//# sourceMappingURL=java-templates.js.map