Skip to content

Commit

Permalink
Testing: add reproducers for testing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed Dec 3, 2024
1 parent bd8d514 commit 5d11efe
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.it.testing.repro34099

import io.quarkus.test.junit.QuarkusTest
import java.time.Duration
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertTimeout

@QuarkusTest
class Repro34099Test {
@Test
fun javaAssertion() {
Assertions.assertTimeout(Duration.ofSeconds(1)) {}
}

@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/34099")
// fails with `Linkage loader constraint violation`
fun kotlinAssertion() {
assertTimeout(Duration.ofSeconds(1)) {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.quarkus.it.testing.repro42000

import io.quarkus.test.junit.QuarkusTest
import java.util.stream.Stream
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource

@QuarkusTest
class Repro42000Test {
companion object {
val lambda: (String) -> String = { s -> s }

fun function(s: String) = s

@JvmStatic
fun lambdaProvider(): Stream<Arguments> {
return Stream.of(Arguments.of(lambda))
}

@JvmStatic
fun functionProvider(): Stream<Arguments> {
return Stream.of(Arguments.of(::function))
}
}

@ParameterizedTest
@MethodSource("lambdaProvider")
@Disabled("https://github.com/quarkusio/quarkus/issues/42000")
// fails with `IllegalArgumentException: argument type mismatch`
fun testLambdaProvider(function: (String) -> String) {
assertNotNull(function)
}

@ParameterizedTest
@MethodSource("functionProvider")
fun testFunctionProvider(function: (String) -> String) {
assertNotNull(function)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.quarkus.it.testing.repro44320;

import java.util.Set;

import jakarta.enterprise.context.ApplicationScoped;

import io.quarkus.arc.Unremovable;
import io.quarkus.runtime.Startup;

@ApplicationScoped
@Startup
@Unremovable
public class MyService {
public Set<String> get() {
return Set.of("a", "b", "c");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.it.main.testing.repro13261;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.nio.file.Path;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import io.quarkus.test.junit.QuarkusTest;

@Disabled("https://github.com/quarkusio/quarkus/issues/13261")
// fails with `expected: not <null>`
@QuarkusTest
public class Repro13261Test {
@TempDir
Path tempDir;

@Test
public void test() {
assertNotNull(tempDir);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.it.main.testing.repro42006;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.Serializable;
import java.util.function.Supplier;
import java.util.stream.Stream;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;

import io.quarkus.test.junit.QuarkusTest;

@Disabled("https://github.com/quarkusio/quarkus/issues/42006")
// fails with `java.lang.ClassNotFoundException: io.quarkus.it.main.testing.repro42006.Repro42006Test$LambdaProvider$$Lambda$4007/0x000075d5017e8450`
@QuarkusTest
public class Repro42006Test {
@ParameterizedTest
@ArgumentsSource(LambdaProvider.class)
void test(String type, Object lambda) {
assertTrue(lambda.toString().contains("$$Lambda"), "Failed on " + type);
}

private static class LambdaProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of("SerializableSupplier", (SerializableSupplier) () -> "foo"),
Arguments.of("SerializableCustom", (SerializableCustom) () -> "bar"));
}
}

public interface SerializableSupplier extends Supplier<String>, Serializable {
}

public interface SerializableCustom extends Serializable {
String get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.it.main.testing.repro44320;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.HashSet;
import java.util.Set;

import jakarta.inject.Inject;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import io.quarkus.it.testing.repro44320.MyService;
import io.quarkus.test.junit.QuarkusTest;

@Disabled("https://github.com/quarkusio/quarkus/issues/44320")
// fails with `You must configure at least one set of arguments for this @ParameterizedTest`, because the `set` is empty
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusTest
public class Repro44320Test {
private static Set<String> set = new HashSet<>();

@Inject
MyService service;

@BeforeAll
public void beforeAllTests() {
set = service.get();
}

@ParameterizedTest
@MethodSource("getData")
public void test(String key) {
assertNotNull(key);
}

public Set<String> getData() {
return set;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.quarkus.it.main.testing.repro8446;

public interface Greeter {
String hello();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.quarkus.it.main.testing.repro8446;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;

public class GreeterExtension implements TestTemplateInvocationContextProvider {
@Override
public boolean supportsTestTemplate(ExtensionContext context) {
return context.getTestMethod().map(method -> {
return Arrays.asList(method.getParameterTypes()).contains(Greeter.class);
}).orElse(false);
}

@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
return Stream.of(new HelloTestTemplateInvocationContext(() -> "hello"));
}

private static class HelloTestTemplateInvocationContext implements TestTemplateInvocationContext, ParameterResolver {
private final Greeter greeter;

public HelloTestTemplateInvocationContext(Greeter greeter) {
this.greeter = greeter;
}

@Override
public List<Extension> getAdditionalExtensions() {
return Collections.singletonList(this);
}

@Override
public boolean supportsParameter(ParameterContext pc, ExtensionContext extensionContext)
throws ParameterResolutionException {
return pc.getParameter().getType() == Greeter.class;
}

@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
return greeter;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.it.main.testing.repro8446;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;

import io.quarkus.test.junit.QuarkusTest;

@Disabled("https://github.com/quarkusio/quarkus/issues/8446")
// fails with `IllegalArgumentException: argument type mismatch`
@QuarkusTest
public class Repro8446Test {
@TestTemplate
@ExtendWith(GreeterExtension.class)
public void test(Greeter greeter) {
assertEquals("hello", greeter.hello());
}
}

0 comments on commit 5d11efe

Please sign in to comment.