This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git
The following commit(s) were added to refs/heads/master by this push:
new 8a596d2 [MEECROWAVE-276] fix meecrowave-junit for @MeecrowaveConfig
case
8a596d2 is described below
commit 8a596d21f7d6786b9149b10b96ca76576da4d63e
Author: Romain Manni-Bucau
AuthorDate: Tue Jan 12 14:40:27 2021 +0100
[MEECROWAVE-276] fix meecrowave-junit for @MeecrowaveConfig case
---
.../src/main/jbake/content/testing/index.adoc | 6 ++
.../meecrowave/junit5/MeecrowaveExtension.java | 111 +++--
.../junit5/MeecrowaveTestLifecycleTest.java| 3 +
pom.xml| 2 +-
4 files changed, 68 insertions(+), 54 deletions(-)
diff --git a/meecrowave-doc/src/main/jbake/content/testing/index.adoc
b/meecrowave-doc/src/main/jbake/content/testing/index.adoc
index b112ae1..b229045 100644
--- a/meecrowave-doc/src/main/jbake/content/testing/index.adoc
+++ b/meecrowave-doc/src/main/jbake/content/testing/index.adoc
@@ -83,6 +83,7 @@ which is close to `MonoMeecrowave.Runner` in term of usage.
[source,java]
@MeecrowaveConfig /*(some config)*/
+@TestInstance(PER_CLASS)
public class MeecrowaveConfigTest {
@ConfigurationInject
private Meecrowave.Builder config;
@@ -109,6 +110,11 @@ TIP: JUnit 5 integration provides an
`@AfterFirstInjection` method and `@AfterLa
which can be used to setup/reset some environment using injections once for a
set of test methods.
The methods must not have any parameter.
+IMPORTANT: when not using `@TestInstance(PER_CLASS)`, container is started per
test method. Generally speaking you should try to align the scope of your
container to the scope of validity of your beans.
+For a library it is generally the class (so `@MeecrowaveConfig
@TestInstance(PER_CLASS)`) and for an application the whole test set (so
`@MonoMeecrowaveConfig`).
+Note that using an `Extension` you can adjust mocks or spy beans dynamically
without a container restart.
+Having the longest life time for the container will make your test suite
faster to execute.
+
== Arquillian Container
Container dependency:
diff --git
a/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java
b/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java
index 18aaeea..2464188 100644
---
a/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java
+++
b/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java
@@ -18,17 +18,6 @@
*/
package org.apache.meecrowave.junit5;
-import static java.util.Optional.ofNullable;
-import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
-
-import java.io.File;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Optional;
-
-import javax.enterprise.context.spi.CreationalContext;
-
import org.apache.meecrowave.Meecrowave;
import org.apache.meecrowave.configuration.Configuration;
import org.apache.meecrowave.testing.Injector;
@@ -38,32 +27,68 @@ import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
+import javax.enterprise.context.spi.CreationalContext;
+import java.io.File;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Optional;
+
+import static java.util.Optional.ofNullable;
+import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
+
public class MeecrowaveExtension extends BaseLifecycle
implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback,
AfterEachCallback {
-
- private static final ExtensionContext.Namespace NAMESPACE =
ExtensionContext.Namespace.create(MeecrowaveExtension.class.getName());
-
+
+private static final ExtensionContext.Namespace NAMESPACE =
ExtensionContext.Namespace.create(MeecrowaveExtension.class.getName());
+
private final ScopesExtension scopes = new ScopesExtension() {
@Override
protected Optional[]> getScopes(final
ExtensionContext context) {
return context.getElement()
- .map(e -> findAnnotation(context.getElement(),
MeecrowaveConfig.class)
- .orElseGet(() -> context.getParent()
-
.flatMap(ExtensionContext::getElement)
- .flatMap(it ->
findAnnotation(it, MeecrowaveConfig.class))
- .orElse(null)))
- .map(MeecrowaveConfig::scopes)
-