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.git


The following commit(s) were added to refs/heads/master by this push:
     new 459c8e8  [OWB-1333] fix+ensure @Cdi.onStart is usable
459c8e8 is described below

commit 459c8e83a98081ec17405e5bf63f9a6ae0ac89ef
Author: Romain Manni-Bucau <rmannibu...@gmail.com>
AuthorDate: Thu Jun 25 15:34:44 2020 +0200

    [OWB-1333] fix+ensure @Cdi.onStart is usable
---
 .../java/org/apache/openwebbeans/junit5/Cdi.java   |  3 +-
 .../openwebbeans/junit5/internal/CdiExtension.java | 10 ++---
 .../junit5/reusable/CdiWithOnStartTest.java        | 47 ++++++++++++++++++++++
 3 files changed, 52 insertions(+), 8 deletions(-)

diff --git 
a/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/Cdi.java 
b/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/Cdi.java
index c5c7d7b..03e3646 100644
--- a/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/Cdi.java
+++ b/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/Cdi.java
@@ -21,7 +21,6 @@ package org.apache.openwebbeans.junit5;
 import org.apache.openwebbeans.junit5.internal.CdiExtension;
 import org.junit.jupiter.api.extension.ExtendWith;
 
-import java.io.Closeable;
 import java.lang.annotation.Annotation;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
@@ -101,7 +100,7 @@ public @interface Cdi
     /**
      * Will be execute before the container starts and can return a closeable 
called after the container stops.
      */
-    interface OnStart extends Supplier<Closeable>
+    interface OnStart extends Supplier<AutoCloseable>
     {
     }
 
diff --git 
a/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/CdiExtension.java
 
b/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/CdiExtension.java
index c5852c0..6b71f01 100644
--- 
a/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/CdiExtension.java
+++ 
b/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/CdiExtension.java
@@ -32,8 +32,6 @@ import javax.enterprise.inject.se.SeContainerInitializer;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.InjectionTarget;
-import java.io.Closeable;
-import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -47,7 +45,7 @@ public class CdiExtension extends 
CdiParametersResolverExtension implements Befo
 
     private SeContainer testInstanceContainer;
     private Collection<CreationalContext<?>> creationalContexts = new 
ArrayList<>();
-    private Closeable[] onStop;
+    private AutoCloseable[] onStop;
 
     @Override
     public void beforeAll(final ExtensionContext extensionContext)
@@ -101,8 +99,8 @@ public class CdiExtension extends 
CdiParametersResolverExtension implements Befo
                         throw new 
IllegalStateException(e.getTargetException());
                     }
                 })
-                .peek(Supplier::get)
-                .toArray(Closeable[]::new);
+                .map(Supplier::get)
+                .toArray(AutoCloseable[]::new);
         SeContainer container = initializer.initialize();
         if (reusable)
         {
@@ -168,7 +166,7 @@ public class CdiExtension extends 
CdiParametersResolverExtension implements Befo
             {
                 it.close();
             }
-            catch (final IOException e)
+            catch (final Exception e)
             {
                 throw new IllegalStateException(e);
             }
diff --git 
a/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/reusable/CdiWithOnStartTest.java
 
b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/reusable/CdiWithOnStartTest.java
new file mode 100644
index 0000000..fabeeb3
--- /dev/null
+++ 
b/webbeans-junit5/src/test/java/org/apache/openwebbeans/junit5/reusable/CdiWithOnStartTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openwebbeans.junit5.reusable;
+
+import org.apache.openwebbeans.junit5.Cdi;
+import org.junit.jupiter.api.Test;
+
+import java.io.Closeable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@Cdi(disableDiscovery = true, onStarts = CdiWithOnStartTest.MyOnStart.class)
+class CdiWithOnStartTest {
+    @Test
+    void run() {
+        assertTrue(MyOnStart.started.get());
+    }
+
+    public static class MyOnStart implements Cdi.OnStart {
+        private static final AtomicBoolean started = new AtomicBoolean();
+
+        @Override
+        public Closeable get() {
+            assertFalse(started.get());
+            started.set(true);
+            return () -> started.set(false);
+        }
+    }
+}

Reply via email to