Skip to content

Commit bdc8597

Browse files
committed
Testing: add reproducers for testing bugs
1 parent e9859df commit bdc8597

File tree

9 files changed

+269
-0
lines changed

9 files changed

+269
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.quarkus.it.testing.repro34099
2+
3+
import io.quarkus.test.junit.QuarkusTest
4+
import java.time.Duration
5+
import org.junit.jupiter.api.Assertions
6+
import org.junit.jupiter.api.Disabled
7+
import org.junit.jupiter.api.Test
8+
import org.junit.jupiter.api.assertTimeout
9+
10+
@QuarkusTest
11+
class Repro34099Test {
12+
@Test
13+
fun javaAssertion() {
14+
Assertions.assertTimeout(Duration.ofSeconds(1)) {}
15+
}
16+
17+
@Test
18+
@Disabled("https://github.com/quarkusio/quarkus/issues/34099")
19+
// fails with `Linkage loader constraint violation`
20+
fun kotlinAssertion() {
21+
assertTimeout(Duration.ofSeconds(1)) {}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.quarkus.it.testing.repro42000
2+
3+
import io.quarkus.test.junit.QuarkusTest
4+
import java.util.stream.Stream
5+
import org.junit.jupiter.api.Assertions.assertNotNull
6+
import org.junit.jupiter.api.Disabled
7+
import org.junit.jupiter.params.ParameterizedTest
8+
import org.junit.jupiter.params.provider.Arguments
9+
import org.junit.jupiter.params.provider.MethodSource
10+
11+
@QuarkusTest
12+
class Repro42000Test {
13+
companion object {
14+
val lambda: (String) -> String = { s -> s }
15+
16+
fun function(s: String) = s
17+
18+
@JvmStatic
19+
fun lambdaProvider(): Stream<Arguments> {
20+
return Stream.of(Arguments.of(lambda))
21+
}
22+
23+
@JvmStatic
24+
fun functionProvider(): Stream<Arguments> {
25+
return Stream.of(Arguments.of(::function))
26+
}
27+
}
28+
29+
@ParameterizedTest
30+
@MethodSource("lambdaProvider")
31+
@Disabled("https://github.com/quarkusio/quarkus/issues/42000")
32+
// fails with `IllegalArgumentException: argument type mismatch`
33+
fun testLambdaProvider(function: (String) -> String) {
34+
assertNotNull(function)
35+
}
36+
37+
@ParameterizedTest
38+
@MethodSource("functionProvider")
39+
fun testFunctionProvider(function: (String) -> String) {
40+
assertNotNull(function)
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.quarkus.it.testing.repro44320;
2+
3+
import java.util.Set;
4+
5+
import jakarta.enterprise.context.ApplicationScoped;
6+
7+
import io.quarkus.arc.Unremovable;
8+
import io.quarkus.runtime.Startup;
9+
10+
@ApplicationScoped
11+
@Startup
12+
@Unremovable
13+
public class MyService {
14+
public Set<String> get() {
15+
return Set.of("a", "b", "c");
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.quarkus.it.main.testing.repro13261;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import java.nio.file.Path;
6+
7+
import org.junit.jupiter.api.Disabled;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.io.TempDir;
10+
11+
import io.quarkus.test.junit.QuarkusTest;
12+
13+
@Disabled("https://github.com/quarkusio/quarkus/issues/13261")
14+
// fails with `expected: not <null>`
15+
@QuarkusTest
16+
public class Repro13261Test {
17+
@TempDir
18+
Path tempDir;
19+
20+
@Test
21+
public void test() {
22+
assertNotNull(tempDir);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.quarkus.it.main.testing.repro42006;
2+
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import java.io.Serializable;
6+
import java.util.function.Supplier;
7+
import java.util.stream.Stream;
8+
9+
import org.junit.jupiter.api.Disabled;
10+
import org.junit.jupiter.api.extension.ExtensionContext;
11+
import org.junit.jupiter.params.ParameterizedTest;
12+
import org.junit.jupiter.params.provider.Arguments;
13+
import org.junit.jupiter.params.provider.ArgumentsProvider;
14+
import org.junit.jupiter.params.provider.ArgumentsSource;
15+
16+
import io.quarkus.test.junit.QuarkusTest;
17+
18+
@Disabled("https://github.com/quarkusio/quarkus/issues/42006")
19+
// fails with `java.lang.ClassNotFoundException: io.quarkus.it.main.testing.repro42006.Repro42006Test$LambdaProvider$$Lambda$4007/0x000075d5017e8450`
20+
@QuarkusTest
21+
public class Repro42006Test {
22+
@ParameterizedTest
23+
@ArgumentsSource(LambdaProvider.class)
24+
void test(String type, Object lambda) {
25+
assertTrue(lambda.toString().contains("$$Lambda"), "Failed on " + type);
26+
}
27+
28+
private static class LambdaProvider implements ArgumentsProvider {
29+
@Override
30+
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
31+
return Stream.of(
32+
Arguments.of("SerializableSupplier", (SerializableSupplier) () -> "foo"),
33+
Arguments.of("SerializableCustom", (SerializableCustom) () -> "bar"));
34+
}
35+
}
36+
37+
public interface SerializableSupplier extends Supplier<String>, Serializable {
38+
}
39+
40+
public interface SerializableCustom extends Serializable {
41+
String get();
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.quarkus.it.main.testing.repro44320;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import java.util.HashSet;
6+
import java.util.Set;
7+
8+
import jakarta.inject.Inject;
9+
10+
import org.junit.jupiter.api.BeforeAll;
11+
import org.junit.jupiter.api.Disabled;
12+
import org.junit.jupiter.api.TestInstance;
13+
import org.junit.jupiter.params.ParameterizedTest;
14+
import org.junit.jupiter.params.provider.MethodSource;
15+
16+
import io.quarkus.it.testing.repro44320.MyService;
17+
import io.quarkus.test.junit.QuarkusTest;
18+
19+
@Disabled("https://github.com/quarkusio/quarkus/issues/44320")
20+
// fails with `You must configure at least one set of arguments for this @ParameterizedTest`, because the `set` is empty
21+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
22+
@QuarkusTest
23+
public class Repro44320Test {
24+
private static Set<String> set = new HashSet<>();
25+
26+
@Inject
27+
MyService service;
28+
29+
@BeforeAll
30+
public void beforeAllTests() {
31+
set = service.get();
32+
}
33+
34+
@ParameterizedTest
35+
@MethodSource("getData")
36+
public void test(String key) {
37+
assertNotNull(key);
38+
}
39+
40+
public Set<String> getData() {
41+
return set;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.quarkus.it.main.testing.repro8446;
2+
3+
public interface Greeter {
4+
String hello();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.quarkus.it.main.testing.repro8446;
2+
3+
import java.util.Arrays;
4+
import java.util.Collections;
5+
import java.util.List;
6+
import java.util.stream.Stream;
7+
8+
import org.junit.jupiter.api.extension.Extension;
9+
import org.junit.jupiter.api.extension.ExtensionContext;
10+
import org.junit.jupiter.api.extension.ParameterContext;
11+
import org.junit.jupiter.api.extension.ParameterResolutionException;
12+
import org.junit.jupiter.api.extension.ParameterResolver;
13+
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
14+
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
15+
16+
public class GreeterExtension implements TestTemplateInvocationContextProvider {
17+
@Override
18+
public boolean supportsTestTemplate(ExtensionContext context) {
19+
return context.getTestMethod().map(method -> {
20+
return Arrays.asList(method.getParameterTypes()).contains(Greeter.class);
21+
}).orElse(false);
22+
}
23+
24+
@Override
25+
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
26+
return Stream.of(new HelloTestTemplateInvocationContext(() -> "hello"));
27+
}
28+
29+
private static class HelloTestTemplateInvocationContext implements TestTemplateInvocationContext, ParameterResolver {
30+
private final Greeter greeter;
31+
32+
public HelloTestTemplateInvocationContext(Greeter greeter) {
33+
this.greeter = greeter;
34+
}
35+
36+
@Override
37+
public List<Extension> getAdditionalExtensions() {
38+
return Collections.singletonList(this);
39+
}
40+
41+
@Override
42+
public boolean supportsParameter(ParameterContext pc, ExtensionContext extensionContext)
43+
throws ParameterResolutionException {
44+
return pc.getParameter().getType() == Greeter.class;
45+
}
46+
47+
@Override
48+
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
49+
return greeter;
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.quarkus.it.main.testing.repro8446;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Disabled;
6+
import org.junit.jupiter.api.TestTemplate;
7+
import org.junit.jupiter.api.extension.ExtendWith;
8+
9+
import io.quarkus.test.junit.QuarkusTest;
10+
11+
@Disabled("https://github.com/quarkusio/quarkus/issues/8446")
12+
// fails with `IllegalArgumentException: argument type mismatch`
13+
@QuarkusTest
14+
public class Repro8446Test {
15+
@TestTemplate
16+
@ExtendWith(GreeterExtension.class)
17+
public void test(Greeter greeter) {
18+
assertEquals("hello", greeter.hello());
19+
}
20+
}

0 commit comments

Comments
 (0)