forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#38929 from mkouba/component-test-paramet…
…erized-methods QuarkusComponentTest: support parameterized test methods
- Loading branch information
Showing
6 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../test/java/io/quarkus/test/component/paraminject/ParameterInjectionParameterizedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.quarkus.test.component.paraminject; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.annotation.PreDestroy; | ||
import jakarta.enterprise.context.Dependent; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import io.quarkus.test.component.QuarkusComponentTest; | ||
import io.quarkus.test.component.SkipInject; | ||
|
||
@QuarkusComponentTest | ||
public class ParameterInjectionParameterizedTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "alpha", "bravo", "delta" }) | ||
public void testParamsInjection(@SkipInject String param, Converter converter) { | ||
Assertions.assertThat(converter.convert(param)).isIn("ALPHA", "BRAVO", "DELTA"); | ||
} | ||
|
||
@AfterAll | ||
public static void afterAll() { | ||
assertEquals(3, Converter.DESTROYED.get()); | ||
} | ||
|
||
@Dependent | ||
public static class Converter { | ||
|
||
static final AtomicInteger DESTROYED = new AtomicInteger(); | ||
|
||
String convert(String param) { | ||
return param.toUpperCase(); | ||
} | ||
|
||
@PreDestroy | ||
void destroy() { | ||
DESTROYED.incrementAndGet(); | ||
} | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...t/src/test/java/io/quarkus/test/component/paraminject/ParameterInjectionRepeatedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.test.component.paraminject; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.annotation.PreDestroy; | ||
import jakarta.enterprise.context.Dependent; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.RepeatedTest; | ||
import org.junit.jupiter.api.RepetitionInfo; | ||
|
||
import io.quarkus.test.component.QuarkusComponentTest; | ||
|
||
@QuarkusComponentTest | ||
public class ParameterInjectionRepeatedTest { | ||
@RepeatedTest(10) | ||
public void testParamsInjection( | ||
// component under test | ||
Converter converter, | ||
// ignored automatically, no need for `@SkipInject` | ||
RepetitionInfo info) { | ||
assertEquals(10, info.getTotalRepetitions()); | ||
assertEquals("FOOBAR", converter.convert("fooBar")); | ||
} | ||
|
||
@AfterAll | ||
public static void afterAll() { | ||
assertEquals(10, Converter.DESTROYED.get()); | ||
} | ||
|
||
@Dependent | ||
public static class Converter { | ||
static final AtomicInteger DESTROYED = new AtomicInteger(); | ||
|
||
String convert(String param) { | ||
return param.toUpperCase(); | ||
} | ||
|
||
@PreDestroy | ||
void destroy() { | ||
DESTROYED.incrementAndGet(); | ||
} | ||
} | ||
} |