Skip to content

Commit

Permalink
Ported TestInstance.Lifecycle.PER_CLASS fix to 4.x (#5052)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalexandrov committed Oct 5, 2022
1 parent 7b77255 commit b0a3c11
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
Expand Down Expand Up @@ -363,6 +364,14 @@ public <T> T interceptTestClassConstructor(Invocation<T> invocation,
// we need to start container before the test class is instantiated, to honor @BeforeAll that
// creates a custom MP config
if (container == null) {
// at this early stage the class should be checked whether it is annotated with
// @TestInstance(TestInstance.Lifecycle.PER_CLASS) to start correctly the container
TestInstance testClassAnnotation = testClass.getAnnotation(TestInstance.class);
if (testClassAnnotation != null && testClassAnnotation.value().equals(TestInstance.Lifecycle.PER_CLASS)){
throw new RuntimeException("When a class is annotated with @HelidonTest, "
+ "it is not compatible with @TestInstance(TestInstance.Lifecycle.PER_CLASS)"
+ "annotation, as it is a Singleton CDI Bean.");
}
startContainer(classLevelBeans, classLevelExtensions, classLevelDisableDiscovery);
}

Expand Down

0 comments on commit b0a3c11

Please sign in to comment.