// 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();',
        '                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");',
        '            assertTrue(acquired, "Lock acquisition is bounded");',
        '        } 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.Disabled;',
        'import org.junit.jupiter.api.Test;',
        'import org.junit.jupiter.api.extension.ExtendWith;',
        '',
        '@ExtendWith(PactConsumerTestExt.class)',
        '@Disabled("Provide explicit Pact interactions before enabling this contract.")',
        `@PactTestFor(providerName = "${className}Provider")`,
        `class ${className}PactConsumerTest {`,
        '',
        `    @Pact(consumer = "${className}Consumer")`,
        '    public RequestResponsePact createPact(PactDslWithProvider builder) {',
        '        throw new IllegalStateException("Provide explicit Pact interactions before enabling this contract.");',
        '    }',
        '',
        '    @Test',
        '    @PactTestFor',
        '    void testProviderReturnsValidResponse() {',
        '        throw new IllegalStateException("Bind this Pact contract to a service client before enabling.");',
        '    }',
        '}',
        '',
    ].join('\n');
}
//# sourceMappingURL=java-templates.js.map