Repository: weld/weld-junit (java)

Issue:
Portable extensions ignored -- how can I add some of them?
I'm using `org.jboss.weld:weld-junit4:1.2.1.Final` and my implementations of `javax.enterprise.inject.spi.Extension` are completely ignored.

I added the following code to my test-class to see, if the services file is actually found -- and it is:

```
    static {
        try {
            Enumeration<URL> resources = TransactionCustomerServiceTest.class.getClassLoader().getResources("META-INF/services/javax.enterprise.inject.spi.Extension");
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                System.out.println("********************");
                System.out.println(url);
                System.out.println(">>>>>>>>>");
                try (InputStreamReader r = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8);) {
                    char[] cbuf = new char[10000];
                    while (true) {
                        int count = r.read(cbuf);
                        if (count < 0) {
                            break;
                        }
                        System.out.print(new String(cbuf, 0, count));
                    };
                }
                System.out.println("<<<<<<<<<");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
```

I debugged through some weld-code and saw that the extensions seem to be dictated by the `WeldInitiator` -- and not discovered in the ordinary way.

I totally understand that one might not want the discovery for a junit-test. But I did not find any API to manually add the extensions which are needed for the current test. There is from(Class...), but adding the extension classes there has no effect. So how can I get my extension(s) into the junit-test?


Pull request:
WeldInitiator's from() and of() methods should support extensions as …
…well.

Resolves #31 

Both methods - `of()` and `from()` - support extensions now.
I am not sure whether some other methods should support this as well? (such as `fromTestPackage()`)

Patch:
diff --git a/junit4/src/main/java/org/jboss/weld/junit4/WeldInitiator.java b/junit4/src/main/java/org/jboss/weld/junit4/WeldInitiator.java
index a473a7c..bdcc8ac 100644
--- a/junit4/src/main/java/org/jboss/weld/junit4/WeldInitiator.java
+++ b/junit4/src/main/java/org/jboss/weld/junit4/WeldInitiator.java
@@ -24,6 +24,7 @@ import java.util.function.Function;
 
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.jboss.weld.environment.se.Weld;
@@ -51,7 +52,8 @@ import org.junit.runners.model.Statement;
  * </pre>
  *
  * <p>
- * {@link WeldInitiator} implements {@link Instance} and therefore might be used to perform programmatic lookup of bean instances.
+ * {@link WeldInitiator} implements {@link Instance} and therefore might be used to perform programmatic lookup of bean
+ * instances.
  * </p>
  *
  * @author Martin Kouba
@@ -60,14 +62,15 @@ import org.junit.runners.model.Statement;
 public class WeldInitiator extends AbstractWeldInitiator implements TestRule {
 
     /**
-     * The container is configured with the result of {@link #createWeld()} method and the given bean classes are added.
+     * The container is configured with the result of {@link #createWeld()} method and the given bean classes are added. If any
+     * of added classes is an extension, it is automatically recognized and enabled.
      *
      * @param beanClasses
      * @return a new test rule
      * @see Weld#beanClasses(Class...)
      */
     public static WeldInitiator of(Class<?>... beanClasses) {
-        return of(createWeld().beanClasses(beanClasses));
+        return from(beanClasses).build();
     }
 
     /**
@@ -81,7 +84,8 @@ public class WeldInitiator extends AbstractWeldInitiator implements TestRule {
     }
 
     /**
-     * The container is configured with the result of {@link #createWeld()} method and all the classes from the test class package are added.
+     * The container is configured with the result of {@link #createWeld()} method and all the classes from the test class
+     * package are added.
      *
      * @return a new test rule
      */
@@ -90,9 +94,8 @@ public class WeldInitiator extends AbstractWeldInitiator implements TestRule {
     }
 
     /**
-     * The container is instructed to do automatic bean discovery, the resulting bean archive is NOT synthetic.
-     * Note that this requires beans.xml to be present.
-     * It is equals to {@code WeldInitiator.of(new Weld())} invocation.
+     * The container is instructed to do automatic bean discovery, the resulting bean archive is NOT synthetic. Note that this
+     * requires beans.xml to be present. It is equals to {@code WeldInitiator.of(new Weld())} invocation.
      *
      * @return a new test rule
      */
@@ -108,7 +111,15 @@ public class WeldInitiator extends AbstractWeldInitiator implements TestRule {
      * @see #of(Class...)
      */
     public static Builder from(Class<?>... beanClasses) {
-        return from(createWeld().beanClasses(beanClasses));
+        Weld weld = createWeld();
+        for (Class<?> clazz : beanClasses) {
+            if (Extension.class.isAssignableFrom(clazz)) {
+                weld.addExtensions((Class<? extends Extension>) clazz);
+            } else {
+                weld.addBeanClass(clazz);
+            }
+        }
+        return from(weld);
     }
 
     /**
@@ -147,7 +158,8 @@ public class WeldInitiator extends AbstractWeldInitiator implements TestRule {
     }
 
     /**
-     * This builder can be used to customize the final {@link WeldInitiator} instance, e.g. to activate a context for a given normal scope.
+     * This builder can be used to customize the final {@link WeldInitiator} instance, e.g. to activate a context for a given
+     * normal scope.
      */
     public static final class Builder extends AbstractBuilder<WeldInitiator, Builder> {
 
@@ -163,14 +175,14 @@ public class WeldInitiator extends AbstractWeldInitiator implements TestRule {
         @Override
         protected WeldInitiator build(Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<Bean<?>> beans) {
             return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory,
-                    persistenceContextFactory);
+                persistenceContextFactory);
         }
 
     }
 
     private WeldInitiator(Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<Bean<?>> beans,
-            Map<String, Object> resources, Function<InjectionPoint, Object> ejbFactory, Function<InjectionPoint, Object> persistenceUnitFactory,
-            Function<InjectionPoint, Object> persistenceContextFactory) {
+        Map<String, Object> resources, Function<InjectionPoint, Object> ejbFactory, Function<InjectionPoint, Object> persistenceUnitFactory,
+        Function<InjectionPoint, Object> persistenceContextFactory) {
         super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory, persistenceContextFactory);
     }
 
diff --git a/junit5/src/main/java/org/jboss/weld/junit5/WeldInitiator.java b/junit5/src/main/java/org/jboss/weld/junit5/WeldInitiator.java
index db24c86..fb79b7a 100644
--- a/junit5/src/main/java/org/jboss/weld/junit5/WeldInitiator.java
+++ b/junit5/src/main/java/org/jboss/weld/junit5/WeldInitiator.java
@@ -23,6 +23,7 @@ import java.util.Set;
 import java.util.function.Function;
 
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.jboss.weld.environment.se.Weld;
@@ -53,14 +54,15 @@ import org.jboss.weld.junit.AbstractWeldInitiator;
 public class WeldInitiator extends AbstractWeldInitiator {
 
     /**
-     * The container is configured with the result of {@link #createWeld()} method and the given bean classes are added.
+     * The container is configured with the result of {@link #createWeld()} method and the given bean classes are added. If any
+     * of added classes is an extension, it is automatically recognized and enabled.
      *
      * @param beanClasses
      * @return a new WeldInitiator instance
      * @see Weld#beanClasses(Class...)
      */
     public static WeldInitiator of(Class<?>... beanClasses) {
-        return of(createWeld().beanClasses(beanClasses));
+        return from(beanClasses).build();
     }
 
     /**
@@ -74,7 +76,8 @@ public class WeldInitiator extends AbstractWeldInitiator {
     }
 
     /**
-     * The container is configured with the result of {@link #createWeld()} method and all the classes from the test class package are added.
+     * The container is configured with the result of {@link #createWeld()} method and all the classes from the test class
+     * package are added.
      *
      * @return a new WeldInitiator instance
      */
@@ -83,9 +86,8 @@ public class WeldInitiator extends AbstractWeldInitiator {
     }
 
     /**
-     * The container is instructed to do automatic bean discovery, the resulting bean archive is NOT synthetic.
-     * Note that this requires beans.xml to be present.
-     * It is equals to {@code WeldInitiator.of(new Weld())} invocation.
+     * The container is instructed to do automatic bean discovery, the resulting bean archive is NOT synthetic. Note that this
+     * requires beans.xml to be present. It is equals to {@code WeldInitiator.of(new Weld())} invocation.
      *
      * @return a new WeldInitiator instance
      */
@@ -101,7 +103,15 @@ public class WeldInitiator extends AbstractWeldInitiator {
      * @see #of(Class...)
      */
     public static Builder from(Class<?>... beanClasses) {
-        return from(createWeld().beanClasses(beanClasses));
+        Weld weld = createWeld();
+        for (Class<?> clazz : beanClasses) {
+            if (Extension.class.isAssignableFrom(clazz)) {
+                weld.addExtensions((Class<? extends Extension>) clazz);
+            } else {
+                weld.addBeanClass(clazz);
+            }
+        }
+        return from(weld);
     }
 
     /**
@@ -140,7 +150,8 @@ public class WeldInitiator extends AbstractWeldInitiator {
     }
 
     /**
-     * This builder can be used to customize the final {@link WeldInitiator} instance, e.g. to activate a context for a given normal scope.
+     * This builder can be used to customize the final {@link WeldInitiator} instance, e.g. to activate a context for a given
+     * normal scope.
      */
     public static final class Builder extends AbstractBuilder<WeldInitiator, Builder> {
 
@@ -156,14 +167,14 @@ public class WeldInitiator extends AbstractWeldInitiator {
         @Override
         protected WeldInitiator build(Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<Bean<?>> beans) {
             return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory,
-                    persistenceContextFactory);
+                persistenceContextFactory);
         }
 
     }
 
     private WeldInitiator(Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<Bean<?>> beans,
-            Map<String, Object> resources, Function<InjectionPoint, Object> ejbFactory, Function<InjectionPoint, Object> persistenceUnitFactory,
-            Function<InjectionPoint, Object> persistenceContextFactory) {
+        Map<String, Object> resources, Function<InjectionPoint, Object> ejbFactory, Function<InjectionPoint, Object> persistenceUnitFactory,
+        Function<InjectionPoint, Object> persistenceContextFactory) {
         super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory, persistenceContextFactory);
     }
 


Test patch:
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/AddExtensionAsBeanClassWithFromMethodTest.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/AddExtensionAsBeanClassWithFromMethodTest.java
new file mode 100644
index 0000000..45700b8
--- /dev/null
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/AddExtensionAsBeanClassWithFromMethodTest.java
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit4.bean.extension;
+
+import org.jboss.weld.inject.WeldInstance;
+import org.jboss.weld.junit4.WeldInitiator;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+public class AddExtensionAsBeanClassWithFromMethodTest {
+
+    @Rule
+    public WeldInitiator weld = WeldInitiator.from(GoodOldBean.class, MyExtension.class).build();
+
+    @Test
+    public void testThatClassIsRecognizedAsExtension() {
+        // GoodOldBean should be resolvable
+        Assert.assertTrue(weld.select(GoodOldBean.class).isResolvable());
+        WeldInstance<MyExtension> extInstance = weld.select(MyExtension.class);
+        // extension should be resolvable and should have observed the other bean
+        Assert.assertTrue(extInstance.isResolvable());
+        Assert.assertTrue(extInstance.get().beanObserved());
+    }
+}
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/AddExtensionAsBeanClassWithOfMethod.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/AddExtensionAsBeanClassWithOfMethod.java
new file mode 100644
index 0000000..1c1a779
--- /dev/null
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/AddExtensionAsBeanClassWithOfMethod.java
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit4.bean.extension;
+
+import org.jboss.weld.inject.WeldInstance;
+import org.jboss.weld.junit4.WeldInitiator;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+public class AddExtensionAsBeanClassWithOfMethod {
+
+    @Rule
+    public WeldInitiator weld = WeldInitiator.of(GoodOldBean.class, MyExtension.class);
+
+    @Test
+    public void testThatClassIsRecognizedAsExtension() {
+        // GoodOldBean should be resolvable
+        Assert.assertTrue(weld.select(GoodOldBean.class).isResolvable());
+        WeldInstance<MyExtension> extInstance = weld.select(MyExtension.class);
+        // extension should be resolvable and should have observed the other bean
+        Assert.assertTrue(extInstance.isResolvable());
+        Assert.assertTrue(extInstance.get().beanObserved());
+    }
+}
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/GoodOldBean.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/GoodOldBean.java
new file mode 100644
index 0000000..93f7eed
--- /dev/null
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/GoodOldBean.java
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit4.bean.extension;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+@ApplicationScoped
+public class GoodOldBean {
+
+}
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/MyExtension.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/MyExtension.java
new file mode 100644
index 0000000..5646d2c
--- /dev/null
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/extension/MyExtension.java
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit4.bean.extension;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+public class MyExtension implements Extension {
+
+    private boolean beanObserved = false;
+
+    public void observePAT(@Observes ProcessAnnotatedType<GoodOldBean> event) {
+        beanObserved = true;
+    }
+    
+    public boolean beanObserved() {
+        return beanObserved;
+    }
+}
diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/AddExtensionAsBeanClassWithFromMethodTest.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/AddExtensionAsBeanClassWithFromMethodTest.java
new file mode 100644
index 0000000..1c73b3c
--- /dev/null
+++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/AddExtensionAsBeanClassWithFromMethodTest.java
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit5.bean.extension;
+
+import org.jboss.weld.inject.WeldInstance;
+import org.jboss.weld.junit5.EnableWeld;
+import org.jboss.weld.junit5.WeldInitiator;
+import org.jboss.weld.junit5.WeldSetup;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+@EnableWeld
+public class AddExtensionAsBeanClassWithFromMethodTest {
+
+    @WeldSetup
+    WeldInitiator weld = WeldInitiator.from(GoodOldBean.class, MyExtension.class).build();
+
+    @Test
+    public void testThatClassIsRecognizedAsExtension() {
+        // GoodOldBean should be resolvable
+        Assertions.assertTrue(weld.select(GoodOldBean.class).isResolvable());
+        WeldInstance<MyExtension> extInstance = weld.select(MyExtension.class);
+        // extension should be resolvable and should have observed the other bean
+        Assertions.assertTrue(extInstance.isResolvable());
+        Assertions.assertTrue(extInstance.get().beanObserved());
+    }
+}
diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/AddExtensionAsBeanClassWithOfMethodTest.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/AddExtensionAsBeanClassWithOfMethodTest.java
new file mode 100644
index 0000000..64cb24c
--- /dev/null
+++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/AddExtensionAsBeanClassWithOfMethodTest.java
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit5.bean.extension;
+
+import org.jboss.weld.inject.WeldInstance;
+import org.jboss.weld.junit5.EnableWeld;
+import org.jboss.weld.junit5.WeldInitiator;
+import org.jboss.weld.junit5.WeldSetup;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+@EnableWeld
+public class AddExtensionAsBeanClassWithOfMethodTest {
+
+    @WeldSetup
+    WeldInitiator weld = WeldInitiator.of(GoodOldBean.class, MyExtension.class);
+
+    @Test
+    public void testThatClassIsRecognizedAsExtension() {
+        // GoodOldBean should be resolvable
+        Assertions.assertTrue(weld.select(GoodOldBean.class).isResolvable());
+        WeldInstance<MyExtension> extInstance = weld.select(MyExtension.class);
+        // extension should be resolvable and should have observed the other bean
+        Assertions.assertTrue(extInstance.isResolvable());
+        Assertions.assertTrue(extInstance.get().beanObserved());
+    }
+}
diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/GoodOldBean.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/GoodOldBean.java
new file mode 100644
index 0000000..47765f4
--- /dev/null
+++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/GoodOldBean.java
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit5.bean.extension;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+@ApplicationScoped
+public class GoodOldBean {
+
+}
diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/MyExtension.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/MyExtension.java
new file mode 100644
index 0000000..1425f57
--- /dev/null
+++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/extension/MyExtension.java
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2018, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.junit5.bean.extension;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+/**
+ *
+ * @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
+ */
+public class MyExtension implements Extension {
+
+    private boolean beanObserved = false;
+
+    public void observePAT(@Observes ProcessAnnotatedType<GoodOldBean> event) {
+        beanObserved = true;
+    }
+    
+    public boolean beanObserved() {
+        return beanObserved;
+    }
+}