Skip to content

Commit

Permalink
Added test method wide CDI scope
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDan committed Feb 29, 2020
1 parent 18c0472 commit 89f394f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.adito.ojcms.cdi;

import de.adito.ojcms.cdi.context.*;

import java.lang.annotation.Annotation;

/**
* Custom CDI context for test method scope.
*
* @author Simon Danner, 29.02.2020
*/
@CustomCdiContext
public class TestMethodContext extends AbstractCustomContext
{
@Override
public Class<? extends Annotation> getScope()
{
return TestMethodScoped.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.adito.ojcms.cdi;

import javax.enterprise.context.NormalScope;
import java.lang.annotation.*;

/**
* CDI scope for unit test methods. The CDI scope lives as long as the execution of a test method.
*
* @author Simon Danner, 29.02.2020
*/
@Documented
@NormalScope
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
public @interface TestMethodScoped
{
}
5 changes: 5 additions & 0 deletions ojcms-cdi-testutils/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
bean-discovery-mode="all">
</beans>

0 comments on commit 89f394f

Please sign in to comment.