From 98fe66f2b672375e7ba018d2229fd668d57514d9 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Wed, 1 Nov 2023 10:29:30 +0100 Subject: [PATCH 1/4] Update Weld parent, apply formatter/impsort changes --- .gitignore | 1 + .../weld/junit/AbstractWeldInitiator.java | 37 ++++++--- .../java/org/jboss/weld/junit/MockBean.java | 50 +++++++----- .../weld/junit/MockBeanWithPriority.java | 12 +-- .../org/jboss/weld/junit/MockInterceptor.java | 32 +++++--- .../weld/junit/MockJpaInjectionServices.java | 9 ++- .../junit/MockResourceInjectionServices.java | 6 +- .../org/jboss/weld/junit4/WeldInitiator.java | 21 +++-- .../org/jboss/weld/junit4/CustomWeldTest.java | 4 +- .../org/jboss/weld/junit4/SimpleTest.java | 1 - .../jboss/weld/junit4/bean/AddBeanTest.java | 3 +- .../AddGloballyEnabledAlternativeTest.java | 13 ++-- .../junit4/bean/AddPassivatingBeanTest.java | 6 +- .../junit4/bean/AlternativeMockBeanTest.java | 4 +- .../java/org/jboss/weld/junit4/bean/Bar.java | 3 +- .../bean/MockBeanWithQualifiersTest.java | 4 +- .../junit4/bean/extension/MyExtension.java | 2 +- .../events/ContextLifecycleEventsTest.java | 3 +- .../inject/InjectWithClassRuleTest.java | 12 +-- .../MockInterceptorOrderingTest.java | 21 ++--- .../interceptor/MockInterceptorTest.java | 11 ++- .../junit4/resources/InjectResourcesTest.java | 10 +-- .../org/jboss/weld/junit5/EnableWeld.java | 3 +- .../weld/junit5/ExplicitParamInjection.java | 2 +- .../weld/junit5/ExtensionContextUtils.java | 3 +- .../org/jboss/weld/junit5/WeldInitiator.java | 21 +++-- .../weld/junit5/WeldJunit5Extension.java | 56 ++++++++------ .../jboss/weld/junit5/WeldJunitEnricher.java | 8 +- .../weld/junit5/auto/ActivateScopes.java | 6 +- .../weld/junit5/auto/AddBeanClasses.java | 2 - .../junit5/auto/AddEnabledDecorators.java | 1 - .../junit5/auto/AddEnabledInterceptors.java | 1 - .../jboss/weld/junit5/auto/AddExtensions.java | 3 +- .../jboss/weld/junit5/auto/AddPackages.java | 5 +- .../jboss/weld/junit5/auto/ClassScanning.java | 76 +++++++++---------- .../auto/EnableAlternativeStereotypes.java | 2 - .../weld/junit5/auto/EnableAlternatives.java | 2 - .../weld/junit5/auto/EnableAutoWeld.java | 7 +- .../jboss/weld/junit5/auto/ExcludeBean.java | 32 ++++---- .../weld/junit5/auto/ExcludeBeanClasses.java | 30 ++++---- .../junit5/auto/ExcludedBeansExtension.java | 8 +- .../junit5/auto/SetBeanDiscoveryMode.java | 4 +- .../auto/TestInstanceInjectionExtension.java | 10 ++- .../junit5/auto/WeldJunit5AutoExtension.java | 27 ++++--- ...ativeAsSoleBeanInSyntheticArchiveTest.java | 10 +-- .../auto/ActivateScopesInheritanceTest.java | 16 ++-- .../weld/junit5/auto/ActivateScopesTest.java | 75 +++++++++--------- .../weld/junit5/auto/AddBeanClassesTest.java | 23 +++--- .../weld/junit5/auto/AddDecoratorTest.java | 4 +- .../weld/junit5/auto/AddExtensionsTest.java | 15 ++-- .../weld/junit5/auto/AddInterceptorTest.java | 4 +- .../weld/junit5/auto/AddPackagesTest.java | 23 +++--- .../auto/AutoConfigWithWeldSetupTest.java | 74 +++++++++--------- .../weld/junit5/auto/BasicAutoConfigTest.java | 33 ++++---- .../auto/ExcludeBeanClassesDepsTest.java | 9 +-- .../junit5/auto/ExcludeBeanClassesTest.java | 13 ++-- .../weld/junit5/auto/ExcludeBeanDepsTest.java | 9 +-- .../junit5/auto/ExcludeBeanHierarchyTest.java | 11 ++- .../weld/junit5/auto/ExcludeBeanTest.java | 11 ++- .../ExplicitParametersAutoConfigTest.java | 28 ++++--- .../junit5/auto/InheritedInjectedTest.java | 3 +- .../junit5/auto/ParametersAutoConfigTest.java | 26 +++---- .../ProducerMethodParametersScanningTest.java | 8 +- .../weld/junit5/auto/ProducesBeforeTest.java | 48 ++++++------ .../ScannedClassesAreNotForcedBeansTest.java | 8 +- ...ParameterClassesAreNotForcedBeansTest.java | 8 +- .../junit5/auto/SetDiscoveryModeAllTest.java | 1 + .../alternativeStereotype/SomeStereotype.java | 2 +- .../jboss/weld/junit5/auto/beans/Engine.java | 6 +- .../org/jboss/weld/junit5/auto/beans/V6.java | 19 ++--- .../org/jboss/weld/junit5/auto/beans/V8.java | 19 +++-- .../beans/unsatisfied/V8NoAnnotation.java | 4 +- .../junit5/auto/extension/AddedExtension.java | 1 - .../DecoratedBean.java | 4 +- .../DecoratedBeanInterface.java | 2 +- .../InterceptedBean.java | 2 +- .../TestDecorator.java | 4 +- .../TestInterceptor.java | 2 +- .../TestInterceptorBinding.java | 2 +- ...OuterTestClassAndBeanSameInstanceTest.java | 32 +++++--- .../weld/junit5/basic/BeanManagerTest.java | 1 - .../weld/junit5/basic/CustomWeldTest.java | 3 +- .../junit5/basic/DisabledMethodsTest.java | 6 +- .../weld/junit5/basic/EnableWeldTest.java | 18 ++--- .../java/org/jboss/weld/junit5/basic/Foo.java | 5 +- .../jboss/weld/junit5/basic/SimpleTest.java | 4 +- .../junit5/basic/unsatisfied/FooDeps.java | 4 +- .../jboss/weld/junit5/bean/AddBeanTest.java | 32 ++++---- .../AddGloballyEnabledAlternativeTest.java | 17 +++-- .../junit5/bean/AddPassivatingBeanTest.java | 14 ++-- .../junit5/bean/AlternativeMockBeanTest.java | 3 +- .../java/org/jboss/weld/junit5/bean/Bar.java | 3 +- .../bean/MockBeanWithQualifiersTest.java | 4 +- .../junit5/bean/extension/MyExtension.java | 2 +- .../contexts/ContextsActivatedTest.java | 1 - .../weld/junit5/contexts/SomeAnnotation.java | 2 +- .../events/ContextLifecycleEventsTest.java | 3 +- .../junit5/enricher/FooWeldJunitEnricher.java | 7 +- .../explicitInjection/CustomExtension.java | 9 ++- .../JUnit5ExtensionTest.java | 7 +- .../extensionInjection/MapProducer.java | 8 +- .../extensionInjection/MyQualifier.java | 4 +- .../jboss/weld/junit5/initiator/bean/Bar.java | 3 +- .../jboss/weld/junit5/initiator/bean/Foo.java | 3 +- .../NestedClassesWeldInitiatorTest.java | 1 + .../discovery/ObjectWeldInitiatorTest.java | 8 +- .../discovery/PrivateWeldInitiatorTest.java | 4 +- .../SubclassWithWeldInitiatorTest.java | 14 ++-- .../SuperclassWithPrivateWeldInitiator.java | 4 +- .../SuperclassWithProtectedWeldInitiator.java | 4 +- .../SuperclassWithWeldInitiator.java | 11 ++- .../interceptor/MockInterceptorTest.java | 11 ++- .../junit5/nested/NestedTestClassTest.java | 4 +- .../junit5/resources/InjectResourcesTest.java | 10 +-- .../testLifecycle/PerClassLifecycleTest.java | 2 +- .../weld/junit5/testLifecycle/PlainBean.java | 2 +- pom.xml | 2 +- .../org/jboss/weld/spock/DisableWeld.java | 17 +++-- .../java/org/jboss/weld/spock/EnableWeld.java | 62 +++++++++------ .../jboss/weld/spock/WeldConfiguration.java | 9 ++- .../org/jboss/weld/spock/WeldInitiator.java | 22 ++++-- .../java/org/jboss/weld/spock/WeldSetup.java | 6 +- .../jboss/weld/spock/WeldSpockEnricher.java | 19 +++-- .../jboss/weld/spock/auto/ActivateScopes.java | 6 +- .../jboss/weld/spock/auto/AddBeanClasses.java | 6 +- .../weld/spock/auto/AddEnabledDecorators.java | 6 +- .../spock/auto/AddEnabledInterceptors.java | 6 +- .../jboss/weld/spock/auto/AddExtensions.java | 6 +- .../jboss/weld/spock/auto/AddPackages.java | 9 ++- .../auto/EnableAlternativeStereotypes.java | 6 +- .../weld/spock/auto/EnableAlternatives.java | 6 +- .../jboss/weld/spock/auto/ExcludeBean.java | 18 +++-- .../weld/spock/auto/ExcludeBeanClasses.java | 16 ++-- .../jboss/weld/spock/impl/ClassScanning.java | 60 +++++++-------- .../spock/impl/EagerExceptionRenderer.java | 20 ++--- .../spock/impl/EnableWeldAutoInterceptor.java | 27 ++++--- .../weld/spock/impl/EnableWeldExtension.java | 59 ++++++++------ .../spock/impl/EnableWeldInterceptor.java | 10 +-- .../impl/EnableWeldManualInterceptor.java | 34 +++++---- .../impl/TestInstanceInjectionExtension.java | 1 + 140 files changed, 975 insertions(+), 829 deletions(-) diff --git a/.gitignore b/.gitignore index 1c979b35..d63cdce7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /.settings/ /.idea *.iml +.cache diff --git a/junit-common/src/main/java/org/jboss/weld/junit/AbstractWeldInitiator.java b/junit-common/src/main/java/org/jboss/weld/junit/AbstractWeldInitiator.java index c71e922a..3aea5e1d 100644 --- a/junit-common/src/main/java/org/jboss/weld/junit/AbstractWeldInitiator.java +++ b/junit-common/src/main/java/org/jboss/weld/junit/AbstractWeldInitiator.java @@ -29,7 +29,6 @@ import java.util.Set; import java.util.function.Function; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import jakarta.annotation.Resource; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.Dependent; @@ -50,6 +49,8 @@ import org.jboss.weld.environment.se.WeldContainer; import org.jboss.weld.inject.WeldInstance; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * * @author Matej Novotny @@ -89,8 +90,10 @@ public static Weld createWeld() { protected volatile WeldContainer container; - protected AbstractWeldInitiator(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans, - Map resources, Function ejbFactory, Function persistenceUnitFactory, + protected AbstractWeldInitiator(Weld weld, List instancesToInject, + Set> scopesToActivate, Set> beans, + Map resources, Function ejbFactory, + Function persistenceUnitFactory, Function persistenceContextFactory) { this.instancesToInject = new ArrayList<>(); for (Object instance : instancesToInject) { @@ -141,7 +144,9 @@ protected ToInject createToInject(Object instanceToInject) { * Injects the given non-contextual instance immediately. The returned {@link AutoCloseable} should be used * to release the creational context once the injected beans are no longer needed. * - *

Example: + *

+ * Example: + * *

{@code
      * try (AutoCloseable contextReleaser = injectNonContextual(this)) {
      *     // do some things with the injected instances
@@ -229,7 +234,8 @@ public Event event() {
             // We need to use reflection due to some compatibility issues
             Method eventMethod = container.getClass().getMethod("event");
             return (Event) eventMethod.invoke(container);
-        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+                | InvocationTargetException e) {
             throw new IllegalStateException("Cannot invoke WeldContainer.event() method using reflection", e);
         }
     }
@@ -255,7 +261,8 @@ public void shutdown() {
 
     /**
      *
-     * @return true if the container was initialized completely and is not shut down yet, false otherwise
+     * @return true if the container was initialized completely and is not shut down yet, false
+     *         otherwise
      */
     public boolean isRunning() {
         return (container != null) && container.isRunning();
@@ -316,7 +323,8 @@ void inject() {
             CreationalContext ctx = beanManager.createCreationalContext(null);
             @SuppressWarnings("unchecked")
             InjectionTarget injectionTarget = (InjectionTarget) beanManager
-                    .getInjectionTargetFactory(beanManager.createAnnotatedType(instance.getClass())).createInjectionTarget(null);
+                    .getInjectionTargetFactory(beanManager.createAnnotatedType(instance.getClass()))
+                    .createInjectionTarget(null);
             injectionTarget.inject(instance, ctx);
             creationalContext = ctx;
         }
@@ -357,7 +365,8 @@ public AbstractBuilder(Weld weld) {
         }
 
         /**
-         * Activate and deactivate contexts for the given normal scopes for the lifetime of the initialized Weld container, by default for each test method
+         * Activate and deactivate contexts for the given normal scopes for the lifetime of the initialized Weld container, by
+         * default for each test method
          * execution.
          * 

* {@link ApplicationScoped} is ignored as it is always active. @@ -393,7 +402,8 @@ protected Function getPersistenceUnitFactory() { } /** - * Instructs the initiator to inject the given non-contextual instance once the container is started, i.e. during test execution. + * Instructs the initiator to inject the given non-contextual instance once the container is started, i.e. during test + * execution. * *

* This method could be used e.g. to inject a test class instance: @@ -416,7 +426,8 @@ protected Function getPersistenceUnitFactory() { * * *

- * Injected {@link Dependent} bean instances are destroyed after the test execution. However, the lifecycle of the non-contextual instance is not + * Injected {@link Dependent} bean instances are destroyed after the test execution. However, the lifecycle of the + * non-contextual instance is not * managed by the container and all injected references will be invalid after the test execution. *

* @@ -507,7 +518,8 @@ public T setPersistenceContextFactory(Function persisten protected abstract T self(); - protected abstract I build(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans); + protected abstract I build(Weld weld, List instancesToInject, Set> scopesToActivate, + Set> beans); /** * @@ -515,7 +527,8 @@ public T setPersistenceContextFactory(Function persisten */ public I build() { return build(weld, instancesToInject.isEmpty() ? Collections.emptyList() : new ArrayList<>(instancesToInject), - scopesToActivate.isEmpty() ? Collections.> emptySet() : new HashSet<>(scopesToActivate), + scopesToActivate.isEmpty() ? Collections.> emptySet() + : new HashSet<>(scopesToActivate), beans.isEmpty() ? Collections.> emptySet() : new HashSet<>(beans)); } diff --git a/junit-common/src/main/java/org/jboss/weld/junit/MockBean.java b/junit-common/src/main/java/org/jboss/weld/junit/MockBean.java index 426b72c2..b94a1dda 100644 --- a/junit-common/src/main/java/org/jboss/weld/junit/MockBean.java +++ b/junit-common/src/main/java/org/jboss/weld/junit/MockBean.java @@ -59,7 +59,7 @@ * @author Martin Kouba * * @param - * See also {@code WeldInitiator.Builder#addBean(Bean)} method. + * See also {@code WeldInitiator.Builder#addBean(Bean)} method. * @since 1.1 */ public class MockBean implements Bean, PassivationCapable { @@ -76,7 +76,8 @@ public class MockBean implements Bean, PassivationCapable { * * *

- * Note that {@link Builder#creating(Object)} or {@link Builder#create(CreateFunction)} must be always set. Otherwise, an {@link IllegalStateException} is + * Note that {@link Builder#creating(Object)} or {@link Builder#create(CreateFunction)} must be always set. Otherwise, an + * {@link IllegalStateException} is * thrown during {@link Builder#build()} invocation. *

* @@ -87,7 +88,8 @@ public static Builder builder() { } /** - * A convenient method to create a {@link Bean} with default values (see also {@link #builder()}). Additionaly, the specified bean types are added to the + * A convenient method to create a {@link Bean} with default values (see also {@link #builder()}). Additionaly, the + * specified bean types are added to the * set of bean types and {@link Bean#create(CreationalContext)} will always return the specified bean instance. * * @param beanInstance @@ -101,10 +103,12 @@ public static Bean of(T beanInstance, Type... beanTypes) { /** * A convenient method to create a {@link Builder} initialized from the specified bean class. *

- * Note that the container may not be started yet and so it is not possible to use CDI SPI. Instead, we try to simulate the default bean discovery. + * Note that the container may not be started yet and so it is not possible to use CDI SPI. Instead, we try to simulate the + * default bean discovery. *

*

- * By default, {@link Unmanaged} is used to create/destroy the bean instance. However, it is possible to override this behavior. + * By default, {@link Unmanaged} is used to create/destroy the bean instance. However, it is possible to override this + * behavior. *

* * @param beanClass @@ -138,7 +142,8 @@ public static Builder read(Class beanClass) { private final Class beanClass; - protected MockBean(Class beanClass, Set> stereotypes, boolean alternative, boolean selectForSyntheticBeanArchive, String name, + protected MockBean(Class beanClass, Set> stereotypes, boolean alternative, + boolean selectForSyntheticBeanArchive, String name, Set qualifiers, Set types, Class scope, CreateFunction createCallback, DestroyFunction destroyCallback) { this.beanClass = beanClass; @@ -151,7 +156,8 @@ protected MockBean(Class beanClass, Set> stereoty this.scope = scope; this.createCallback = createCallback; this.destroyCallback = destroyCallback; - this.id = new StringBuilder().append(MockBean.class.getName()).append("_").append(SEQUENCE.incrementAndGet()).toString(); + this.id = new StringBuilder().append(MockBean.class.getName()).append("_").append(SEQUENCE.incrementAndGet()) + .toString(); } @Override @@ -207,7 +213,8 @@ public boolean isAlternative() { } /** - * Initiator should use {@link #getBeanClass()} to select the alternative. Also the alternative should only be selected if {@link #isAlternative()} also + * Initiator should use {@link #getBeanClass()} to select the alternative. Also the alternative should only be selected if + * {@link #isAlternative()} also * returns true. * * @return true if the initiator should select the bean for the synthetic bean archive @@ -252,7 +259,8 @@ private static Builder readInternal(Class beanClass) { } if (!scopes.isEmpty()) { if (scopes.size() > 1) { - throw new IllegalStateException("At most one scope may be specifie [beanClass: " + beanClass + ", scopes: " + scopes + "]"); + throw new IllegalStateException( + "At most one scope may be specifie [beanClass: " + beanClass + ", scopes: " + scopes + "]"); } builder.scope(scopes.iterator().next().annotationType()); } @@ -292,7 +300,8 @@ private static Set getStereotypes(AnnotatedElement element) { private static Set getScopes(AnnotatedElement element) { Set scopes = new HashSet<>(); for (Annotation annotation : element.getAnnotations()) { - if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class)) { + if (annotation.annotationType().isAnnotationPresent(Scope.class) + || annotation.annotationType().isAnnotationPresent(NormalScope.class)) { scopes.add(annotation); } } @@ -477,8 +486,10 @@ public Builder globallySelectedAlternative(int priority) { * The bean is an alternative and should be automatically selected for the synthetic bean archive. * *

- * Users are encouraged to specify {@link #beanClass(Class)} when using this method. The bean class is used to determine which alternative beans are - * selected for a bean archive. By default, all mock beans share the same bean class - {@code org.jboss.weld.junit.WeldCDIExtension}. + * Users are encouraged to specify {@link #beanClass(Class)} when using this method. The bean class is used to determine + * which alternative beans are + * selected for a bean archive. By default, all mock beans share the same bean class - + * {@code org.jboss.weld.junit.WeldCDIExtension}. *

* * @return self @@ -493,7 +504,8 @@ public Builder selectedAlternative() { } /** - * The bean has the given bean class, is an alternative and should be automatically selected for the synthetic bean archive. + * The bean has the given bean class, is an alternative and should be automatically selected for the synthetic bean + * archive. * * @param beanClass * @return self @@ -544,7 +556,8 @@ public Builder creating(final T instance) { * Use {@link Unmanaged} to create/destroy the bean instance. * *

- * NOTE: {@link CreationalContext#toString()} is used as a key in a map and therefore must be unique for the lifetime of a bean instance. Weld + * NOTE: {@link CreationalContext#toString()} is used as a key in a map and therefore must be unique for the lifetime of + * a bean instance. Weld * implementation fulfills this requirement. *

* @@ -565,7 +578,8 @@ public Builder useUnmanaged(Class beanClass) { if (unmanagedInstance != null) { if (!unmanagedInstance.get().equals(o)) { throw new IllegalStateException( - "Unmanaged instance [" + unmanagedInstance.get() + "] is not equal to the bean instance to be destroyed: " + o); + "Unmanaged instance [" + unmanagedInstance.get() + + "] is not equal to the bean instance to be destroyed: " + o); } unmanagedInstance.preDestroy().dispose(); } @@ -622,10 +636,12 @@ public MockBean build() { } // if given any priority, we will instead initialize MockBeanWithPriority if (priority != null) { - return new MockBeanWithPriority<>(beanClass, stereotypes, alternative, selectForSyntheticBeanArchive, priority, name, normalizedQualfiers, types, scope, createCallback, + return new MockBeanWithPriority<>(beanClass, stereotypes, alternative, selectForSyntheticBeanArchive, priority, + name, normalizedQualfiers, types, scope, createCallback, destroyCallback); } else { - return new MockBean<>(beanClass, stereotypes, alternative, selectForSyntheticBeanArchive, name, normalizedQualfiers, types, scope, createCallback, + return new MockBean<>(beanClass, stereotypes, alternative, selectForSyntheticBeanArchive, name, + normalizedQualfiers, types, scope, createCallback, destroyCallback); } } diff --git a/junit-common/src/main/java/org/jboss/weld/junit/MockBeanWithPriority.java b/junit-common/src/main/java/org/jboss/weld/junit/MockBeanWithPriority.java index aff002f3..e20afc1c 100644 --- a/junit-common/src/main/java/org/jboss/weld/junit/MockBeanWithPriority.java +++ b/junit-common/src/main/java/org/jboss/weld/junit/MockBeanWithPriority.java @@ -1,10 +1,11 @@ package org.jboss.weld.junit; -import jakarta.enterprise.inject.spi.Prioritized; import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.Set; +import jakarta.enterprise.inject.spi.Prioritized; + /** * A subclass of {@link MockBean} implementing {@link Prioritized} hence allowing for globally enabled alternatives. * Used instead of {@link MockBean} if user specified {@link MockBean.Builder#priority(int)}. @@ -16,10 +17,11 @@ class MockBeanWithPriority extends MockBean implements Prioritized { private final int priority; MockBeanWithPriority(Class beanClass, Set> stereotypes, boolean alternative, - boolean selectForSyntheticBeanArchive, int priority, String name, - Set qualifiers, Set types, Class scope, - CreateFunction createCallback, DestroyFunction destroyCallback) { - super(beanClass, stereotypes, alternative, selectForSyntheticBeanArchive, name, qualifiers, types, scope, createCallback, destroyCallback); + boolean selectForSyntheticBeanArchive, int priority, String name, + Set qualifiers, Set types, Class scope, + CreateFunction createCallback, DestroyFunction destroyCallback) { + super(beanClass, stereotypes, alternative, selectForSyntheticBeanArchive, name, qualifiers, types, scope, + createCallback, destroyCallback); if (priority <= 0) { throw new IllegalArgumentException("MockBean cannot have priority equal or lower than 0!"); } diff --git a/junit-common/src/main/java/org/jboss/weld/junit/MockInterceptor.java b/junit-common/src/main/java/org/jboss/weld/junit/MockInterceptor.java index 722f46c8..da129cfd 100644 --- a/junit-common/src/main/java/org/jboss/weld/junit/MockInterceptor.java +++ b/junit-common/src/main/java/org/jboss/weld/junit/MockInterceptor.java @@ -42,17 +42,20 @@ /** * This custom {@link Interceptor} implementation is useful for mocking. *

- * A new instance is usually created through a {@link Builder} (see also {@link #withBindings(Annotation...)} method) and then passed to the + * A new instance is usually created through a {@link Builder} (see also {@link #withBindings(Annotation...)} method) and then + * passed to the * {@code WeldInitiator.Builder#addBeans(Bean...)} method. *

*

- * Note that by default all mock interceptors are automatically enabled for the synthetic bean archive. If needed a custom bean class can be set through the - * {@link Builder#beanClass(Class)} method - the bean class can be used to enable the interceptor for a bean archive. It's not possible to enable a mock + * Note that by default all mock interceptors are automatically enabled for the synthetic bean archive. If needed a custom bean + * class can be set through the + * {@link Builder#beanClass(Class)} method - the bean class can be used to enable the interceptor for a bean archive. It's not + * possible to enable a mock * interceptor globally (per application). *

* * @author Martin Kouba - * See also {code WeldInitiator.Builder#addBean(Bean)} method. + * See also {code WeldInitiator.Builder#addBean(Bean)} method. * @since 1.2.1 */ public class MockInterceptor implements Interceptor { @@ -81,7 +84,8 @@ public static Builder withBindings(Annotation... interceptorBindings) { * @param callback * @param interceptorBindings */ - private MockInterceptor(Class beanClass, InterceptionType type, InterceptionCallback callback, Set interceptorBindings) { + private MockInterceptor(Class beanClass, InterceptionType type, InterceptionCallback callback, + Set interceptorBindings) { this.beanClass = beanClass; this.type = type; this.callback = callback; @@ -105,7 +109,8 @@ public Object intercept(InterceptionType type, MockInterceptorInstance instance, @Override public MockInterceptorInstance create(CreationalContext creationalContext) { - return new MockInterceptorInstance(getInterceptedBean(creationalContext), BeanManagerProxy.unwrap(CDI.current().getBeanManager()).getContextId()); + return new MockInterceptorInstance(getInterceptedBean(creationalContext), + BeanManagerProxy.unwrap(CDI.current().getBeanManager()).getContextId()); } @Override @@ -167,19 +172,22 @@ private Bean getInterceptedBean(CreationalContext ct Class ctxImplClazz; if (ctx.getClass().getName().startsWith("org.jboss.weld.contexts")) { // 3.x - ctxImplClazz = MockInterceptor.class.getClassLoader().loadClass("org.jboss.weld.contexts.CreationalContextImpl"); + ctxImplClazz = MockInterceptor.class.getClassLoader() + .loadClass("org.jboss.weld.contexts.CreationalContextImpl"); } else { // 2.x ctxImplClazz = MockInterceptor.class.getClassLoader().loadClass("org.jboss.weld.context.CreationalContextImpl"); } Object parentContext = ctxImplClazz.getMethod("getParentCreationalContext").invoke(ctx); if (parentContext != null) { - Contextual interceptedContextual = (Contextual) ctxImplClazz.getMethod("getContextual").invoke(parentContext); + Contextual interceptedContextual = (Contextual) ctxImplClazz.getMethod("getContextual") + .invoke(parentContext); if (interceptedContextual instanceof Bean) { interceptedBean = (Bean) interceptedContextual; } } - } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) { + } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException + | SecurityException | InvocationTargetException e) { throw new IllegalStateException(e); } return interceptedBean; @@ -233,8 +241,10 @@ public Builder type(InterceptionType type) { } /** - * Allows to specify a bean class of an interceptor. This is only required if you later on need to enforce interceptor ordering via - * Weld.enableInterceptors(). Note that such ordering corresponds to enabling interceptors via beans.xml (e.g. per bean archive). + * Allows to specify a bean class of an interceptor. This is only required if you later on need to enforce interceptor + * ordering via + * Weld.enableInterceptors(). Note that such ordering corresponds to enabling interceptors via beans.xml + * (e.g. per bean archive). * * @param beanClass * @return self diff --git a/junit-common/src/main/java/org/jboss/weld/junit/MockJpaInjectionServices.java b/junit-common/src/main/java/org/jboss/weld/junit/MockJpaInjectionServices.java index f3b36eb7..f660f5d9 100644 --- a/junit-common/src/main/java/org/jboss/weld/junit/MockJpaInjectionServices.java +++ b/junit-common/src/main/java/org/jboss/weld/junit/MockJpaInjectionServices.java @@ -39,7 +39,8 @@ public class MockJpaInjectionServices implements JpaInjectionServices { private final Function persistenceContextFactory; - public MockJpaInjectionServices(Function persistenceUnitFactory, Function persistenceContextFactory) { + public MockJpaInjectionServices(Function persistenceUnitFactory, + Function persistenceContextFactory) { this.persistenceUnitFactory = persistenceUnitFactory; this.persistenceContextFactory = persistenceContextFactory; } @@ -50,7 +51,8 @@ public ResourceReferenceFactory registerPersistenceContextInjecti @Override public ResourceReference createResource() { if (persistenceContextFactory == null) { - throw new IllegalStateException("Persistent context factory not set, cannot resolve injection point: " + injectionPoint); + throw new IllegalStateException( + "Persistent context factory not set, cannot resolve injection point: " + injectionPoint); } Object context = persistenceContextFactory.apply(injectionPoint); if (context == null || context instanceof EntityManager) { @@ -67,7 +69,8 @@ public ResourceReferenceFactory registerPersistenceUnitInj @Override public ResourceReference createResource() { if (persistenceUnitFactory == null) { - throw new IllegalStateException("Persistent unit factory not set, cannot resolve injection point: " + injectionPoint); + throw new IllegalStateException( + "Persistent unit factory not set, cannot resolve injection point: " + injectionPoint); } Object unit = persistenceUnitFactory.apply(injectionPoint); if (unit == null || unit instanceof EntityManagerFactory) { diff --git a/junit-common/src/main/java/org/jboss/weld/junit/MockResourceInjectionServices.java b/junit-common/src/main/java/org/jboss/weld/junit/MockResourceInjectionServices.java index eb09cb22..2cd223a9 100644 --- a/junit-common/src/main/java/org/jboss/weld/junit/MockResourceInjectionServices.java +++ b/junit-common/src/main/java/org/jboss/weld/junit/MockResourceInjectionServices.java @@ -54,9 +54,11 @@ private Object resolveResource(InjectionPoint injectionPoint) { if (resource == null) { throw new IllegalArgumentException("No @Resource annotation found on " + injectionPoint); } - if (injectionPoint.getMember() instanceof Method && ((Method) injectionPoint.getMember()).getParameterTypes().length != 1) { + if (injectionPoint.getMember() instanceof Method + && ((Method) injectionPoint.getMember()).getParameterTypes().length != 1) { throw new IllegalArgumentException( - "Injection point represents a method which doesn't follow JavaBean conventions (must have exactly one parameter) " + injectionPoint); + "Injection point represents a method which doesn't follow JavaBean conventions (must have exactly one parameter) " + + injectionPoint); } String name; if (!resource.lookup().equals("")) { 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 dad367cf..cb29af0c 100644 --- a/junit4/src/main/java/org/jboss/weld/junit4/WeldInitiator.java +++ b/junit4/src/main/java/org/jboss/weld/junit4/WeldInitiator.java @@ -204,16 +204,21 @@ protected Builder self() { } @Override - protected WeldInitiator build(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans) { - return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, getEjbFactory(), getPersistenceUnitFactory(), getPersistenceContextFactory()); + protected WeldInitiator build(Weld weld, List instancesToInject, + Set> scopesToActivate, Set> beans) { + return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, getEjbFactory(), + getPersistenceUnitFactory(), getPersistenceContextFactory()); } } - private WeldInitiator(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans, - Map resources, Function ejbFactory, Function persistenceUnitFactory, - Function persistenceContextFactory) { - super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory, persistenceContextFactory); + private WeldInitiator(Weld weld, List instancesToInject, Set> scopesToActivate, + Set> beans, + Map resources, Function ejbFactory, + Function persistenceUnitFactory, + Function persistenceContextFactory) { + super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory, + persistenceContextFactory); } /** @@ -223,7 +228,9 @@ private WeldInitiator(Weld weld, List instancesToInject, SetExample: + *

+ * Example: + * *

{@code
      * }@{@code ClassRule
      * public static WeldInitiator weld = WeldInitiator.from(Foo.class).build();
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/CustomWeldTest.java b/junit4/src/test/java/org/jboss/weld/junit4/CustomWeldTest.java
index bcc7d32d..faaa4c33 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/CustomWeldTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/CustomWeldTest.java
@@ -19,7 +19,6 @@
 import static org.jboss.weld.junit4.WeldInitiator.createWeld;
 import static org.junit.Assert.assertEquals;
 
-import org.jboss.weld.junit4.WeldInitiator;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -30,7 +29,8 @@
 public class CustomWeldTest {
 
     @Rule
-    public WeldInitiator weld = WeldInitiator.of(createWeld().alternatives(FooAlternative.class).beanClasses(Foo.class, FooAlternative.class));
+    public WeldInitiator weld = WeldInitiator
+            .of(createWeld().alternatives(FooAlternative.class).beanClasses(Foo.class, FooAlternative.class));
 
     @Test
     public void testFooAlternative() {
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/SimpleTest.java b/junit4/src/test/java/org/jboss/weld/junit4/SimpleTest.java
index c4bc3fe9..db46d883 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/SimpleTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/SimpleTest.java
@@ -18,7 +18,6 @@
 
 import static org.junit.Assert.assertEquals;
 
-import org.jboss.weld.junit4.WeldInitiator;
 import org.junit.Rule;
 import org.junit.Test;
 
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/AddBeanTest.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/AddBeanTest.java
index 75cf9910..5a5c8db8 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/bean/AddBeanTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/AddBeanTest.java
@@ -58,7 +58,8 @@ public class AddBeanTest {
     @SuppressWarnings("serial")
     static Bean createListBean() {
         return MockBean.builder()
-                .types(new TypeLiteral>() {}.getType())
+                .types(new TypeLiteral>() {
+                }.getType())
                 .qualifiers(Meaty.Literal.INSTANCE)
                 .creating(
                         // Mock object provided by Mockito
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/AddGloballyEnabledAlternativeTest.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/AddGloballyEnabledAlternativeTest.java
index feec3e4d..9e395ad0 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/bean/AddGloballyEnabledAlternativeTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/AddGloballyEnabledAlternativeTest.java
@@ -1,5 +1,11 @@
 package org.jboss.weld.junit4.bean;
 
+import java.util.List;
+import java.util.Set;
+
+import jakarta.enterprise.inject.spi.Bean;
+import jakarta.enterprise.util.TypeLiteral;
+
 import org.jboss.weld.junit.MockBean;
 import org.jboss.weld.junit4.WeldInitiator;
 import org.junit.Assert;
@@ -7,18 +13,13 @@
 import org.junit.Test;
 import org.mockito.Mockito;
 
-import jakarta.enterprise.inject.spi.Bean;
-import jakarta.enterprise.util.TypeLiteral;
-import java.util.List;
-import java.util.Set;
-
 /**
  * Tests {@link org.jboss.weld.junit.MockBean} adding a bean that is a globally enabled alternative.
  *
  * @author Matej Novotny
  */
 public class AddGloballyEnabledAlternativeTest {
-    
+
     @Rule
     public WeldInitiator weld = WeldInitiator.from(Bar.class)
             .addBeans(createFooAlternativeBean(), createListBean())
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/AddPassivatingBeanTest.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/AddPassivatingBeanTest.java
index 296d63d3..051d89d3 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/bean/AddPassivatingBeanTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/AddPassivatingBeanTest.java
@@ -43,7 +43,8 @@ public class AddPassivatingBeanTest {
     @SuppressWarnings("serial")
     static Bean createListBean() {
         return MockBean.builder()
-                .types(new TypeLiteral>() {}.getType())
+                .types(new TypeLiteral>() {
+                }.getType())
                 .scope(SessionScoped.class)
                 .creating(
                         // Mock object provided by Mockito
@@ -54,7 +55,8 @@ static Bean createListBean() {
     @SuppressWarnings("serial")
     @Test
     public void testPassivatingBeanAdded() {
-        assertEquals("42", weld.select(new TypeLiteral>() {}).get().get(0));
+        assertEquals("42", weld.select(new TypeLiteral>() {
+        }).get().get(0));
     }
 
 }
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/AlternativeMockBeanTest.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/AlternativeMockBeanTest.java
index ace5a702..bab3a6d0 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/bean/AlternativeMockBeanTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/AlternativeMockBeanTest.java
@@ -33,7 +33,9 @@ public class AlternativeMockBeanTest {
 
     @Rule
     public WeldInitiator weld = WeldInitiator.from(SimpleService.class)
-            .addBeans(MockBean.builder().types(MyService.class).selectedAlternative(CoolService.class).create(c -> new CoolService()).build()).build();
+            .addBeans(MockBean.builder().types(MyService.class).selectedAlternative(CoolService.class)
+                    .create(c -> new CoolService()).build())
+            .build();
 
     @Test
     public void testAlternativeBeanSelected() {
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/Bar.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/Bar.java
index c240776b..df4d88ca 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/bean/Bar.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/Bar.java
@@ -1,8 +1,9 @@
 package org.jboss.weld.junit4.bean;
 
+import java.util.List;
+
 import jakarta.enterprise.context.ApplicationScoped;
 import jakarta.inject.Inject;
-import java.util.List;
 
 @ApplicationScoped
 public class Bar {
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/bean/MockBeanWithQualifiersTest.java b/junit4/src/test/java/org/jboss/weld/junit4/bean/MockBeanWithQualifiersTest.java
index 3984b4e2..f962f8dc 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/bean/MockBeanWithQualifiersTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/bean/MockBeanWithQualifiersTest.java
@@ -1,13 +1,13 @@
 package org.jboss.weld.junit4.bean;
 
+import jakarta.enterprise.inject.Any;
+
 import org.jboss.weld.junit.MockBean;
 import org.jboss.weld.junit4.WeldInitiator;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 
-import jakarta.enterprise.inject.Any;
-
 /**
  * Tests that {@link MockBean} with custom qualifiers has {@link Any} qualifier automatically added.
  */
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
index e1fd4954..17c3b578 100644
--- 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
@@ -31,7 +31,7 @@ public class MyExtension implements Extension {
     public void observePAT(@Observes ProcessAnnotatedType event) {
         beanObserved = true;
     }
-    
+
     public boolean beanObserved() {
         return beanObserved;
     }
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/contexts/events/ContextLifecycleEventsTest.java b/junit4/src/test/java/org/jboss/weld/junit4/contexts/events/ContextLifecycleEventsTest.java
index d2b76566..8cec40f7 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/contexts/events/ContextLifecycleEventsTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/contexts/events/ContextLifecycleEventsTest.java
@@ -35,7 +35,8 @@
 public class ContextLifecycleEventsTest {
 
     @Rule
-    public WeldInitiator initiator = WeldInitiator.from(ContextLifecycleEventsObserver.class).activate(RequestScoped.class, SessionScoped.class).build();
+    public WeldInitiator initiator = WeldInitiator.from(ContextLifecycleEventsObserver.class)
+            .activate(RequestScoped.class, SessionScoped.class).build();
 
     @Test
     public void testInitFired() {
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/inject/InjectWithClassRuleTest.java b/junit4/src/test/java/org/jboss/weld/junit4/inject/InjectWithClassRuleTest.java
index 761dff7b..d5263f3b 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/inject/InjectWithClassRuleTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/inject/InjectWithClassRuleTest.java
@@ -16,6 +16,12 @@
  */
 package org.jboss.weld.junit4.inject;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import jakarta.enterprise.event.Event;
+import jakarta.inject.Inject;
+
 import org.jboss.weld.junit4.Foo;
 import org.jboss.weld.junit4.WeldInitiator;
 import org.junit.ClassRule;
@@ -25,12 +31,6 @@
 import org.junit.rules.RuleChain;
 import org.junit.runners.model.Statement;
 
-import jakarta.enterprise.event.Event;
-import jakarta.inject.Inject;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 /**
  *
  * @author Björn Kautler
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorOrderingTest.java b/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorOrderingTest.java
index e5a6cbe4..7536eb63 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorOrderingTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorOrderingTest.java
@@ -41,15 +41,18 @@ public class MockInterceptorOrderingTest {
     private static AtomicBoolean guard = new AtomicBoolean();
 
     @Rule
-    public WeldInitiator weld = WeldInitiator.from(WeldInitiator.createWeld().addBeanClass(Foo.class).enableInterceptors(Integer.class, String.class)).addBeans(
-            MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).beanClass(Integer.class).aroundInvoke((ctx, b) -> {
-                return 5;
-                }),
-            MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).beanClass(String.class).aroundInvoke((ctx, b) -> {
-                // Should be never invoked
-                guard.set(true);
-                return -5;
-                })).build();
+    public WeldInitiator weld = WeldInitiator
+            .from(WeldInitiator.createWeld().addBeanClass(Foo.class).enableInterceptors(Integer.class, String.class)).addBeans(
+                    MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).beanClass(Integer.class)
+                            .aroundInvoke((ctx, b) -> {
+                                return 5;
+                            }),
+                    MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).beanClass(String.class).aroundInvoke((ctx, b) -> {
+                        // Should be never invoked
+                        guard.set(true);
+                        return -5;
+                    }))
+            .build();
 
     @Before
     public void setup() {
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorTest.java b/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorTest.java
index 28420b57..4ee8b6d3 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/interceptor/MockInterceptorTest.java
@@ -50,12 +50,14 @@ public class MockInterceptorTest {
             MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).aroundInvoke((ctx, b) -> {
                 aroundInvokes.add(b.getBeanClass().getName());
                 return ctx.proceed();
-                }),
+            }),
             // This interceptor is disabled
             MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).beanClass(String.class).aroundInvoke((ctx, b) -> {
                 return false;
-                }),
-            MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).postConstruct((ctx, b) -> postConstructs.add(b.getBeanClass().getName()))).build();
+            }),
+            MockInterceptor.withBindings(FooBinding.Literal.INSTANCE)
+                    .postConstruct((ctx, b) -> postConstructs.add(b.getBeanClass().getName())))
+            .build();
 
     @Before
     public void setup() {
@@ -76,7 +78,8 @@ public void testInterception() {
 
     @Test
     public void testDisabledInterceptor() {
-        List> interceptors = weld.getBeanManager().resolveInterceptors(InterceptionType.AROUND_INVOKE, FooBinding.Literal.INSTANCE);
+        List> interceptors = weld.getBeanManager().resolveInterceptors(InterceptionType.AROUND_INVOKE,
+                FooBinding.Literal.INSTANCE);
         assertEquals(1, interceptors.size());
         assertEquals(MockInterceptor.class, interceptors.get(0).getBeanClass());
     }
diff --git a/junit4/src/test/java/org/jboss/weld/junit4/resources/InjectResourcesTest.java b/junit4/src/test/java/org/jboss/weld/junit4/resources/InjectResourcesTest.java
index b9e8b6ac..24d70baa 100644
--- a/junit4/src/test/java/org/jboss/weld/junit4/resources/InjectResourcesTest.java
+++ b/junit4/src/test/java/org/jboss/weld/junit4/resources/InjectResourcesTest.java
@@ -56,11 +56,11 @@ public class InjectResourcesTest {
 
     @Rule
     public WeldInitiator weld = WeldInitiator.fromTestPackage()
-                                                .bindResource("bar", "hello1")
-                                                .bindResource("java:comp/env/baz", "hello2")
-                                                .setEjbFactory(ip -> new DummySessionBean("ping"))
-                                                .setPersistenceUnitFactory(getPUFactory())
-                                                .setPersistenceContextFactory(getPCFactory()).build();
+            .bindResource("bar", "hello1")
+            .bindResource("java:comp/env/baz", "hello2")
+            .setEjbFactory(ip -> new DummySessionBean("ping"))
+            .setPersistenceUnitFactory(getPUFactory())
+            .setPersistenceContextFactory(getPCFactory()).build();
 
     @Test
     public void testResourceInjection() {
diff --git a/junit5/src/main/java/org/jboss/weld/junit5/EnableWeld.java b/junit5/src/main/java/org/jboss/weld/junit5/EnableWeld.java
index 1bc5c277..03889e85 100644
--- a/junit5/src/main/java/org/jboss/weld/junit5/EnableWeld.java
+++ b/junit5/src/main/java/org/jboss/weld/junit5/EnableWeld.java
@@ -29,7 +29,8 @@
  * Meta-annotation that allows test classes to be extended with {@code @EnableWeld}
  * instead of {@code @ExtendWith(WeldJunit5Extension.class)}.
  *
- * 

+ *
+ * 
* @EnableWeld * public class SimpleTest { * diff --git a/junit5/src/main/java/org/jboss/weld/junit5/ExplicitParamInjection.java b/junit5/src/main/java/org/jboss/weld/junit5/ExplicitParamInjection.java index ff56f112..18c1905d 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/ExplicitParamInjection.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/ExplicitParamInjection.java @@ -25,7 +25,7 @@ * An annotation used to enforce explicit parameter annotation. When applied, Weld will only attempt to resolve method * parameters which have qualifiers. In case no qualifier is required for your bean, add the {@link Default} qualifier, see CDI * specification for in depth explanation on qualifiers. - * + * * This annotation can be applied either on test class, in which case it affects parameter injection in all methods, or on * a method. * diff --git a/junit5/src/main/java/org/jboss/weld/junit5/ExtensionContextUtils.java b/junit5/src/main/java/org/jboss/weld/junit5/ExtensionContextUtils.java index ee14e41c..6f17ba31 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/ExtensionContextUtils.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/ExtensionContextUtils.java @@ -120,7 +120,8 @@ public static void setContainerToStore(ExtensionContext context, WeldContainer c */ public static List getEnrichersFromStore(ExtensionContext context) { @SuppressWarnings("unchecked") - List enrichers = (List) getRootExtensionStore(context).get(WELD_ENRICHERS, List.class); + List enrichers = (List) getRootExtensionStore(context).get(WELD_ENRICHERS, + List.class); return enrichers; } 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 a1d91dfb..fe8f9a6c 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/WeldInitiator.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/WeldInitiator.java @@ -33,7 +33,9 @@ /** * JUnit 5 initiator - can be used to customize the Weld SE container started by {@link WeldJunit5Extension}. * - *

Example: + *

+ * Example: + * *

  * @ExtendWith(WeldJunit5Extension.class)
  * public class SimpleTest {
@@ -167,16 +169,21 @@ protected Builder self() {
         }
 
         @Override
-        protected WeldInitiator build(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans) {
-            return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, getEjbFactory(), getPersistenceUnitFactory(), getPersistenceContextFactory());
+        protected WeldInitiator build(Weld weld, List instancesToInject,
+                Set> scopesToActivate, Set> beans) {
+            return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, getEjbFactory(),
+                    getPersistenceUnitFactory(), getPersistenceContextFactory());
         }
 
     }
 
-    private WeldInitiator(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans,
-        Map resources, Function ejbFactory, Function persistenceUnitFactory,
-        Function persistenceContextFactory) {
-        super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory, persistenceContextFactory);
+    private WeldInitiator(Weld weld, List instancesToInject, Set> scopesToActivate,
+            Set> beans,
+            Map resources, Function ejbFactory,
+            Function persistenceUnitFactory,
+            Function persistenceContextFactory) {
+        super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory,
+                persistenceContextFactory);
     }
 
     void shutdownWeld() {
diff --git a/junit5/src/main/java/org/jboss/weld/junit5/WeldJunit5Extension.java b/junit5/src/main/java/org/jboss/weld/junit5/WeldJunit5Extension.java
index 9de5f471..430eef2c 100644
--- a/junit5/src/main/java/org/jboss/weld/junit5/WeldJunit5Extension.java
+++ b/junit5/src/main/java/org/jboss/weld/junit5/WeldJunit5Extension.java
@@ -27,7 +27,21 @@
 import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
 import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_METHOD;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.ServiceLoader;
+import java.util.stream.Collectors;
+
 import jakarta.enterprise.inject.spi.BeanManager;
+
 import org.jboss.weld.environment.se.Weld;
 import org.jboss.weld.inject.WeldInstance;
 import org.jboss.weld.util.collections.ImmutableList;
@@ -41,19 +55,6 @@
 import org.junit.jupiter.api.extension.ParameterResolutionException;
 import org.junit.jupiter.api.extension.ParameterResolver;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.ServiceLoader;
-import java.util.stream.Collectors;
-
 /**
  * JUnit 5 extension allowing to bootstrap Weld SE container for each @Test method (or once per test class
  * if running {@link org.junit.jupiter.api.TestInstance.Lifecycle#PER_CLASS}) and tear it down afterwards. Also allows
@@ -144,26 +145,33 @@ protected void weldInit(ExtensionContext context, Weld weld, WeldInitiator.Build
     }
 
     @Override
-    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
+            throws ParameterResolutionException {
         // we did our checks in supportsParameter() method, now we can do simple resolution
         if (getContainerFromStore(extensionContext) != null) {
-            List qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager());
+            List qualifiers = resolveQualifiers(parameterContext,
+                    getContainerFromStore(extensionContext).getBeanManager());
             return getContainerFromStore(extensionContext)
                     .select(parameterContext.getParameter().getParameterizedType(),
-                            qualifiers.toArray(new Annotation[qualifiers.size()])).get();
+                            qualifiers.toArray(new Annotation[qualifiers.size()]))
+                    .get();
         }
         return null;
     }
 
     @Override
-    public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+    public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
+            throws ParameterResolutionException {
         // if weld container isn't up yet or if it's not Method, we don't resolve it
-        if (getContainerFromStore(extensionContext) == null || (!(parameterContext.getDeclaringExecutable() instanceof Method))) {
+        if (getContainerFromStore(extensionContext) == null
+                || (!(parameterContext.getDeclaringExecutable() instanceof Method))) {
             return false;
         }
-        List qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager());
+        List qualifiers = resolveQualifiers(parameterContext,
+                getContainerFromStore(extensionContext).getBeanManager());
         // if we require explicit parameter injection (via global settings or annotation) and there are no qualifiers we don't resolve it
-        if ((getExplicitInjectionInfoFromStore(extensionContext) || (methodRequiresExplicitParamInjection(parameterContext))) && qualifiers.isEmpty()) {
+        if ((getExplicitInjectionInfoFromStore(extensionContext) || (methodRequiresExplicitParamInjection(parameterContext)))
+                && qualifiers.isEmpty()) {
             return false;
         } else {
             // attempt to resolve the bean; at this point we know it should be a CDI bean since it has CDI qualifiers
@@ -172,7 +180,8 @@ public boolean supportsParameter(ParameterContext parameterContext, ExtensionCon
                     parameterContext.getParameter().getParameterizedType(),
                     qualifiers.toArray(new Annotation[qualifiers.size()]));
             if (!select.isResolvable()) {
-                throw new ParameterResolutionException(String.format("Weld has failed to resolve test parameter [%s] in method [%s].%n" +
+                throw new ParameterResolutionException(String.format(
+                        "Weld has failed to resolve test parameter [%s] in method [%s].%n" +
                                 "%s dependency has type %s and qualifiers %s.",
                         parameterContext.getParameter(), parameterContext.getDeclaringExecutable().toGenericString(),
                         select.isAmbiguous() ? "Ambiguous" : "Unsatisfied",
@@ -296,9 +305,10 @@ private WeldInitiator findInitiatorInInstance(Object testInstance) {
         // Multiple occurrences of @WeldSetup in the hierarchy will lead to an exception
         if (foundInitiatorFields.size() > 1) {
             final String msg = foundInitiatorFields.stream()
-                    .map(f -> "Field '" + f.getName() + "' with type " + f.getType() + " which is declared in " + f.getDeclaringClass())
+                    .map(f -> "Field '" + f.getName() + "' with type " + f.getType() + " which is declared in "
+                            + f.getDeclaringClass())
                     .collect(Collectors.joining("\n", "Multiple @WeldSetup annotated fields found, "
-                                                      + "only one is allowed! Fields found:\n", ""));
+                            + "only one is allowed! Fields found:\n", ""));
             throw new IllegalStateException(msg);
         }
 
diff --git a/junit5/src/main/java/org/jboss/weld/junit5/WeldJunitEnricher.java b/junit5/src/main/java/org/jboss/weld/junit5/WeldJunitEnricher.java
index 1a83e51e..c4e69c13 100644
--- a/junit5/src/main/java/org/jboss/weld/junit5/WeldJunitEnricher.java
+++ b/junit5/src/main/java/org/jboss/weld/junit5/WeldJunitEnricher.java
@@ -20,14 +20,14 @@
 import org.jboss.weld.junit5.WeldInitiator.Builder;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
-
-
 /**
- * If no {@link WeldInitiator} field annotated with {@link WeldSetup} is present on a test class, all service providers of this interface are used to enrich the
+ * If no {@link WeldInitiator} field annotated with {@link WeldSetup} is present on a test class, all service providers of this
+ * interface are used to enrich the
  * default test environment. The initial {@link Weld} instance is created using {@link WeldInitiator#createWeld()}.
  *
  * 

- * A system property with key equal to FQCN of a customizer class may be used to disable an enricher completely. E.g. for a class + * A system property with key equal to FQCN of a customizer class may be used to disable an enricher completely. E.g. for a + * class * {@code org.weld.FooEnricher} use {@code -Dorg.weld.FooEnricher=false} to disable the enricher. *

* diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/ActivateScopes.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/ActivateScopes.java index 94340726..f55abcbb 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/ActivateScopes.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/ActivateScopes.java @@ -16,7 +16,6 @@ */ package org.jboss.weld.junit5.auto; - import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; @@ -27,7 +26,6 @@ import org.junit.jupiter.api.TestInstance; - /** * Activates the listed scopes for the duration of the test. * @@ -35,7 +33,7 @@ * {@link TestInstance.Lifecycle}. */ @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Inherited @Repeatable(ActivateScopes.All.class) public @interface ActivateScopes { @@ -46,7 +44,7 @@ * Container annotation for repeatable {@link ActivateScopes}. */ @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.TYPE}) + @Target({ ElementType.TYPE }) @Inherited @interface All { ActivateScopes[] value(); diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddBeanClasses.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddBeanClasses.java index 4011fb4c..d2f7f59f 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddBeanClasses.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddBeanClasses.java @@ -16,7 +16,6 @@ */ package org.jboss.weld.junit5.auto; - import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; @@ -24,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** * Adds the listed classes as beans to the deployed testing container. */ diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledDecorators.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledDecorators.java index 3a42b97d..6e82b769 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledDecorators.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledDecorators.java @@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** * Adds, and enables, the listed classes as CDI decorators to the deployed testing container. */ diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledInterceptors.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledInterceptors.java index a3dc0672..76be3e9c 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledInterceptors.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddEnabledInterceptors.java @@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** * Adds, and enables, the listed classes as CDI interceptors to the deployed testing container. */ diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddExtensions.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddExtensions.java index d32fa8a6..1667a20e 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddExtensions.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddExtensions.java @@ -16,8 +16,6 @@ */ package org.jboss.weld.junit5.auto; - -import jakarta.enterprise.inject.spi.Extension; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; @@ -25,6 +23,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import jakarta.enterprise.inject.spi.Extension; /** * Adds the listed classes as portable CDI extensions to the deployed testing container. diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddPackages.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddPackages.java index 9aaaf98f..db788244 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/AddPackages.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/AddPackages.java @@ -16,7 +16,6 @@ */ package org.jboss.weld.junit5.auto; - import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; @@ -24,11 +23,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** * Adds all bean classes from the listed packages to the deployed testing container. * - *

Packages are selected by providing any bean class in the package. + *

+ * Packages are selected by providing any bean class in the package. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java index bb92ecff..5b063952 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/ClassScanning.java @@ -16,28 +16,10 @@ */ package org.jboss.weld.junit5.auto; -import org.jboss.weld.environment.se.Weld; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.RepeatedTest; -import org.junit.jupiter.api.Test; -import org.junit.platform.commons.support.AnnotationSupport; -import org.junit.platform.commons.support.HierarchyTraversalMode; -import org.junit.platform.commons.util.CollectionUtils; -import org.junit.platform.commons.util.Preconditions; +import static java.util.Arrays.asList; +import static java.util.Arrays.stream; +import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated; -import jakarta.decorator.Decorator; -import jakarta.enterprise.context.Dependent; -import jakarta.enterprise.context.NormalScope; -import jakarta.enterprise.inject.Instance; -import jakarta.enterprise.inject.Produces; -import jakarta.enterprise.inject.Stereotype; -import jakarta.enterprise.inject.spi.Extension; -import jakarta.inject.Inject; -import jakarta.inject.Qualifier; -import jakarta.interceptor.Interceptor; import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.lang.reflect.Executable; @@ -55,10 +37,28 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.Arrays.asList; -import static java.util.Arrays.stream; -import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated; +import jakarta.decorator.Decorator; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.NormalScope; +import jakarta.enterprise.inject.Instance; +import jakarta.enterprise.inject.Produces; +import jakarta.enterprise.inject.Stereotype; +import jakarta.enterprise.inject.spi.Extension; +import jakarta.inject.Inject; +import jakarta.inject.Qualifier; +import jakarta.interceptor.Interceptor; +import org.jboss.weld.environment.se.Weld; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.RepeatedTest; +import org.junit.jupiter.api.Test; +import org.junit.platform.commons.support.AnnotationSupport; +import org.junit.platform.commons.support.HierarchyTraversalMode; +import org.junit.platform.commons.util.CollectionUtils; +import org.junit.platform.commons.util.Preconditions; /** * Provides automagic bean class discovery for a test class instance. @@ -114,12 +114,9 @@ static void scanForRequiredBeanClasses(List> testClasses, Weld weld, bo .forEach(cls -> addClassesToProcess(classesToProcess, cls)); findAnnotatedDeclaredMethods(currClass, Produces.class).stream() - .flatMap(method -> - Stream.concat( - getExecutableParameterTypes(method, explicitInjection).stream(), - Stream.of(method.getReturnType()) - ) - ) + .flatMap(method -> Stream.concat( + getExecutableParameterTypes(method, explicitInjection).stream(), + Stream.of(method.getReturnType()))) .forEach(cls -> addClassesToProcess(classesToProcess, cls)); AnnotationSupport.findAnnotatedMethods(currClass, Test.class, HierarchyTraversalMode.BOTTOM_UP).stream() @@ -147,10 +144,9 @@ static void scanForRequiredBeanClasses(List> testClasses, Weld weld, bo .forEach(cls -> addClassesToProcess(classesToProcess, cls)); AnnotationSupport.findRepeatableAnnotations(currClass, AddPackages.class) - .forEach(ann -> - stream(ann.value()) - .distinct() - .forEach(cls -> weld.addPackage(ann.recursively(), cls))); + .forEach(ann -> stream(ann.value()) + .distinct() + .forEach(cls -> weld.addPackage(ann.recursively(), cls))); AnnotationSupport.findRepeatableAnnotations(currClass, AddBeanClasses.class).stream() .flatMap(ann -> stream(ann.value())) @@ -201,7 +197,8 @@ static void scanForRequiredBeanClasses(List> testClasses, Weld weld, bo // discovery mode can only be set once; we use the first annotation we find if (!syntheticArchiveDiscoverySet) { - Optional annotation = AnnotationSupport.findAnnotation(currClass, SetBeanDiscoveryMode.class); + Optional annotation = AnnotationSupport.findAnnotation(currClass, + SetBeanDiscoveryMode.class); if (annotation.isPresent()) { syntheticArchiveDiscoverySet = true; weld.setBeanDiscoveryMode(annotation.get().value()); @@ -277,8 +274,7 @@ private static boolean hasBeanDefiningAnnotation(Class clazz) { private static List findAllFieldsInHierarchy(Class clazz) { Preconditions.notNull(clazz, "Class must not be null"); - List localFields = getDeclaredFields(clazz).stream(). - filter((field) -> !field.isSynthetic()) + List localFields = getDeclaredFields(clazz).stream().filter((field) -> !field.isSynthetic()) .collect(Collectors.toList()); List superclassFields = getSuperclassFields(clazz).stream() .filter((field) -> !isMethodShadowedByLocalFields(field, localFields)) @@ -292,7 +288,8 @@ private static List findAllFieldsInHierarchy(Class clazz) { private static List getSuperclassFields(Class clazz) { Class superclass = clazz.getSuperclass(); - return superclass != null && superclass != Object.class ? findAllFieldsInHierarchy(superclass) : Collections.emptyList(); + return superclass != null && superclass != Object.class ? findAllFieldsInHierarchy(superclass) + : Collections.emptyList(); } private static List getDeclaredFields(Class clazz) { @@ -328,7 +325,8 @@ private static List> getDeclaredConstructors(Class clazz) { return asList(clazz.getDeclaredConstructors()); } - private static Optional> findFirstAnnotatedConstructor(Class clazz, Class annotationType) { + private static Optional> findFirstAnnotatedConstructor(Class clazz, + Class annotationType) { Optional> found = getDeclaredConstructors(clazz).stream() .filter((cons) -> isAnnotated(cons, annotationType)) diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternativeStereotypes.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternativeStereotypes.java index 66e7420a..75175d1b 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternativeStereotypes.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternativeStereotypes.java @@ -16,7 +16,6 @@ */ package org.jboss.weld.junit5.auto; - import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; @@ -25,7 +24,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** * Adds the listed annotations as alternative stereotypes to the deployed container. */ diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternatives.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternatives.java index e03d499a..bb374c64 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternatives.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAlternatives.java @@ -16,7 +16,6 @@ */ package org.jboss.weld.junit5.auto; - import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; @@ -24,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - /** * Enables the listed classes as bean class alternatives in the deployed testing container. */ diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAutoWeld.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAutoWeld.java index e3d5187e..a3571343 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAutoWeld.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/EnableAutoWeld.java @@ -16,8 +16,6 @@ */ package org.jboss.weld.junit5.auto; -import org.junit.jupiter.api.extension.ExtendWith; - import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; @@ -25,11 +23,14 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.api.extension.ExtendWith; + /** * Meta-annotation that allows test classes to be extended with {@code @EnableAutoWeld} * instead of {@code @ExtendWith(WeldJunit5AutoExtension.class)}. * - *


+ *
+ * 
* @EnableAutoWeld * public class SimpleTest { * diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBean.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBean.java index f0f4b9d5..c93e80d6 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBean.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBean.java @@ -13,37 +13,41 @@ * (e.g. scope) from automatic discovery. This can be helpful to allow replacing a bean class with a different * implementation, typically a mock. * - *

The type of bean to exclude is implied by the annotated fields' type or annotated methods' return type. If the type + *

+ * The type of bean to exclude is implied by the annotated fields' type or annotated methods' return type. If the type * is a base class or interface all beans extending / implementing that type will be excluded. * - *

NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the + *

+ * NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the * implied type that are defined by {@link Produces} producer methods / fields or synthetic * beans. Also, current implementation excludes beans based on type, disregarding any qualifiers that are specified. * - *

Example: + *

+ * Example: + * *

  * @EnableAutoWeld
  * class TestSomeFoo {
  *
- *   @Inject
- *   SomeFoo someFoo;   // SomeFoo depends upon application scoped bean Foo
+ *     @Inject
+ *     SomeFoo someFoo; // SomeFoo depends upon application scoped bean Foo
  *
- *   @Produces
- *   @ExcludeBean   // Excludes beans with type Foo from automatic discovery
- *   Foo mockFoo = mock(Foo.class);  // mockFoo is now produced in place of original Foo impl
+ *     @Produces
+ *     @ExcludeBean // Excludes beans with type Foo from automatic discovery
+ *     Foo mockFoo = mock(Foo.class); // mockFoo is now produced in place of original Foo impl
  *
- *   @Test
- *   void test(Foo myFoo) {
- *     assertNotNull(myFoo);
- *     assertEquals(myFoo.getBar(), "mock-foo");
- *   }
+ *     @Test
+ *     void test(Foo myFoo) {
+ *         assertNotNull(myFoo);
+ *         assertEquals(myFoo.getBar(), "mock-foo");
+ *     }
  * }
  * 
* * @see ExcludeBeanClasses */ @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.METHOD}) +@Target({ ElementType.FIELD, ElementType.METHOD }) @Inherited public @interface ExcludeBean { } diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBeanClasses.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBeanClasses.java index 369c0310..b9f69acf 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBeanClasses.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludeBeanClasses.java @@ -13,29 +13,33 @@ * {@code @ExcludeBeanClasses} excludes a set of classes with bean defining annotations (e.g. scopes) from automatic * discovery. This can be helpful to allow replacing bean classes with a different implementation, typically a mock. * - *

This annotation works as an inverse of {@link AddBeanClasses} hence usually requires actual bean implementation + *

+ * This annotation works as an inverse of {@link AddBeanClasses} hence usually requires actual bean implementation * classes as parameters. * - *

NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the + *

+ * NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the * specified type that are defined by {@link Produces} producer methods / fields or synthetic beans. * - *

Example: + *

+ * Example: + * *

  * @EnableAutoWeld
- * @ExcludeBeanClasses(Foo.class)     // Excludes Foo bean class from automatic discovery
+ * @ExcludeBeanClasses(Foo.class) // Excludes Foo bean class from automatic discovery
  * class TestSomeFoo {
  *
- *   @Inject
- *   SomeFoo someFoo;                 // SomeFoo depends upon application scoped bean Foo
+ *     @Inject
+ *     SomeFoo someFoo; // SomeFoo depends upon application scoped bean Foo
  *
- *   @Produces
- *   Foo mockFoo = mock(Foo.class);   // mockFoo is now produced in place of original Foo impl
+ *     @Produces
+ *     Foo mockFoo = mock(Foo.class); // mockFoo is now produced in place of original Foo impl
  *
- *   @Test
- *   void test(Foo myFoo) {
- *     assertNotNull(myFoo);
- *     assertEquals(myFoo.getBar(), "mock-foo");
- *   }
+ *     @Test
+ *     void test(Foo myFoo) {
+ *         assertNotNull(myFoo);
+ *         assertEquals(myFoo.getBar(), "mock-foo");
+ *     }
  * }
  * 
* diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludedBeansExtension.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludedBeansExtension.java index 77f2d44b..f424c584 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludedBeansExtension.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/ExcludedBeansExtension.java @@ -16,15 +16,15 @@ */ package org.jboss.weld.junit5.auto; +import java.lang.reflect.Type; +import java.util.Set; + import jakarta.enterprise.context.NormalScope; import jakarta.enterprise.event.Observes; import jakarta.enterprise.inject.spi.Extension; import jakarta.enterprise.inject.spi.ProcessAnnotatedType; import jakarta.enterprise.inject.spi.WithAnnotations; import jakarta.inject.Scope; -import java.lang.reflect.Type; -import java.util.Set; - /** * Extension class that ensures selected classes are excluded as @@ -40,7 +40,7 @@ public class ExcludedBeansExtension implements Extension { this.excludedBeanClasses = excludedBeanClasses; } - void excludeBeans(@Observes @WithAnnotations({Scope.class, NormalScope.class}) ProcessAnnotatedType pat) { + void excludeBeans(@Observes @WithAnnotations({ Scope.class, NormalScope.class }) ProcessAnnotatedType pat) { if (excludedBeanClasses.contains(pat.getAnnotatedType().getJavaClass())) { pat.veto(); diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/SetBeanDiscoveryMode.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/SetBeanDiscoveryMode.java index c0e89808..99e94aff 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/SetBeanDiscoveryMode.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/SetBeanDiscoveryMode.java @@ -1,13 +1,13 @@ package org.jboss.weld.junit5.auto; -import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode; - import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode; + /** * Sets discovery mode for Weld SE synthetic bean archive. Valid options are {@link BeanDiscoveryMode#ALL} and * {@link BeanDiscoveryMode#ANNOTATED}. diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/TestInstanceInjectionExtension.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/TestInstanceInjectionExtension.java index fc509d97..a8bad21f 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/TestInstanceInjectionExtension.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/TestInstanceInjectionExtension.java @@ -18,7 +18,6 @@ import jakarta.enterprise.context.spi.CreationalContext; import jakarta.enterprise.event.Observes; -import jakarta.enterprise.inject.spi.BeanManager; import jakarta.enterprise.inject.spi.Extension; import jakarta.enterprise.inject.spi.InjectionTarget; import jakarta.enterprise.inject.spi.ProcessAnnotatedType; @@ -30,12 +29,15 @@ /** * Extension that makes a test instance appear like a regular bean even though instantiated by JUnit. - * Injection into all test instances, also {@link org.junit.jupiter.api.Nested @Nested} ones, is handled in {@link org.jboss.weld.junit5.WeldInitiator#addObjectsToInjectInto} and related. - * Proper handling of all other CDI annotations such as {@link jakarta.enterprise.inject.Produces @Produces} is supported only on top level test classes. + * Injection into all test instances, also {@link org.junit.jupiter.api.Nested @Nested} ones, is handled in + * {@link org.jboss.weld.junit5.WeldInitiator#addObjectsToInjectInto} and related. + * Proper handling of all other CDI annotations such as {@link jakarta.enterprise.inject.Produces @Produces} is supported + * only on top level test classes. */ public class TestInstanceInjectionExtension implements Extension { - private static final AnnotationLiteral SINGLETON_LITERAL = new AnnotationLiteral() {}; + private static final AnnotationLiteral SINGLETON_LITERAL = new AnnotationLiteral() { + }; private final Class testClass; private final T testInstance; diff --git a/junit5/src/main/java/org/jboss/weld/junit5/auto/WeldJunit5AutoExtension.java b/junit5/src/main/java/org/jboss/weld/junit5/auto/WeldJunit5AutoExtension.java index f2858196..0ff109ef 100644 --- a/junit5/src/main/java/org/jboss/weld/junit5/auto/WeldJunit5AutoExtension.java +++ b/junit5/src/main/java/org/jboss/weld/junit5/auto/WeldJunit5AutoExtension.java @@ -16,13 +16,6 @@ */ package org.jboss.weld.junit5.auto; -import org.jboss.weld.environment.se.Weld; -import org.jboss.weld.junit5.WeldInitiator; -import org.jboss.weld.junit5.WeldJunit5Extension; -import org.jboss.weld.junit5.WeldJunitEnricher; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.platform.commons.support.AnnotationSupport; - import static java.lang.String.format; import static java.util.stream.Collectors.joining; import static org.jboss.weld.junit5.ExtensionContextUtils.getExplicitInjectionInfoFromStore; @@ -31,16 +24,26 @@ import java.util.List; import java.util.stream.Collectors; +import org.jboss.weld.environment.se.Weld; +import org.jboss.weld.junit5.WeldInitiator; +import org.jboss.weld.junit5.WeldJunit5Extension; +import org.jboss.weld.junit5.WeldJunitEnricher; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.platform.commons.support.AnnotationSupport; + /** * An alternative to {@link WeldJunit5Extension} allowing to fully leverage an annotation based configuration approach. * When used, the extension will attempt to resolve all beans used in your test class and automatically adds them to * the Weld container while bootstrapping it. * - *

There are quite some annotations which can be used to configure it further. + *

+ * There are quite some annotations which can be used to configure it further. * - *

Furthermore, all discovered {@link WeldJunitEnricher}s are invoked after the annotations are processed. + *

+ * Furthermore, all discovered {@link WeldJunitEnricher}s are invoked after the annotations are processed. * - *

Note that this approach cannot be combined with {@link WeldJunit5Extension}, choose one or the other approach, not both. + *

+ * Note that this approach cannot be combined with {@link WeldJunit5Extension}, choose one or the other approach, not both. * * @see ActivateScopes * @see AddBeanClasses @@ -63,7 +66,9 @@ protected void validateInitiator(List foundInitiatorFields) { throw new IllegalStateException(foundInitiatorFields .stream() .map(f -> format("Field '%s' with type %s which is in %s", f.getName(), f.getType(), f.getDeclaringClass())) - .collect(joining("\n", "When using automagic mode, no @WeldSetup annotated field should be present! Fields found:\n", ""))); + .collect(joining("\n", + "When using automagic mode, no @WeldSetup annotated field should be present! Fields found:\n", + ""))); } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/alternative/AlternativeAsSoleBeanInSyntheticArchiveTest.java b/junit5/src/test/java/org/jboss/weld/junit5/alternative/AlternativeAsSoleBeanInSyntheticArchiveTest.java index 2472ea66..48f473b5 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/alternative/AlternativeAsSoleBeanInSyntheticArchiveTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/alternative/AlternativeAsSoleBeanInSyntheticArchiveTest.java @@ -1,5 +1,9 @@ package org.jboss.weld.junit5.alternative; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.spi.Bean; +import jakarta.inject.Inject; + import org.jboss.weld.junit.MockBean; import org.jboss.weld.junit5.EnableWeld; import org.jboss.weld.junit5.WeldInitiator; @@ -7,10 +11,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.inject.spi.Bean; -import jakarta.inject.Inject; - /** * Tests that synthetic archive with only enabled alternative in it still works. * This mimics problems in issue 64, but without the need for discovery @@ -18,12 +18,10 @@ @EnableWeld public class AlternativeAsSoleBeanInSyntheticArchiveTest { - @WeldSetup public WeldInitiator weld = WeldInitiator.from(WeldInitiator.createWeld()) .addBeans(createSelectedAlternativeBean()).build(); - static Bean createSelectedAlternativeBean() { return MockBean.builder().types(Fish.class).scope(ApplicationScoped.class).selectedAlternative(Fish.class) .creating(new Fish(200)).build(); diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesInheritanceTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesInheritanceTest.java index 88657b1a..0cc0e5c6 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesInheritanceTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesInheritanceTest.java @@ -1,10 +1,8 @@ package org.jboss.weld.junit5.auto; -import org.jboss.weld.junit5.auto.beans.Engine; -import org.jboss.weld.junit5.auto.beans.V6; -import org.jboss.weld.junit5.auto.beans.V8; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import jakarta.enterprise.context.ContextNotActiveException; import jakarta.enterprise.context.ConversationScoped; @@ -14,9 +12,11 @@ import jakarta.enterprise.inject.spi.BeanManager; import jakarta.inject.Named; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jboss.weld.junit5.auto.beans.Engine; +import org.jboss.weld.junit5.auto.beans.V6; +import org.jboss.weld.junit5.auto.beans.V8; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class ActivateScopesInheritanceTest extends BaseActivateScopesInheritanceTest { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesTest.java index d896c290..f45ec312 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ActivateScopesTest.java @@ -1,11 +1,8 @@ package org.jboss.weld.junit5.auto; - -import org.jboss.weld.junit5.auto.beans.Engine; -import org.jboss.weld.junit5.auto.beans.V6; -import org.jboss.weld.junit5.auto.beans.V8; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import jakarta.enterprise.context.ContextNotActiveException; import jakarta.enterprise.context.ConversationScoped; @@ -15,43 +12,43 @@ import jakarta.enterprise.inject.spi.BeanManager; import jakarta.inject.Named; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - - +import org.jboss.weld.junit5.auto.beans.Engine; +import org.jboss.weld.junit5.auto.beans.V6; +import org.jboss.weld.junit5.auto.beans.V8; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @EnableAutoWeld @ActivateScopes({ SessionScoped.class, RequestScoped.class }) class ActivateScopesTest { - @Produces - @SessionScoped - @Named("special") - V8 sessionEngine = new V8(); - - @Produces - @ConversationScoped - @ExcludeBean // V6 is annotated with @ApplicationScoped, this tells the container to use this producer instead - V6 convoEngine = new V6(); - - @Test - @DisplayName("Test that @ActivateScopes activates the specified scopes") - void test(BeanManager beanManager) { - assertTrue(beanManager.getContext(RequestScoped.class).isActive()); - assertTrue(beanManager.getContext(SessionScoped.class).isActive()); - } - - @Test - @DisplayName("Test that Engine is resolved to @SessionScoped V8") - void test(@Named("special") Engine engine) { - assertEquals(engine.getThrottle(), 0); - } - - @Test - @DisplayName("Test that non-activated scopes fail") - void test(V6 engine) { - assertThrows(ContextNotActiveException.class, engine::getThrottle); - } + @Produces + @SessionScoped + @Named("special") + V8 sessionEngine = new V8(); + + @Produces + @ConversationScoped + @ExcludeBean // V6 is annotated with @ApplicationScoped, this tells the container to use this producer instead + V6 convoEngine = new V6(); + + @Test + @DisplayName("Test that @ActivateScopes activates the specified scopes") + void test(BeanManager beanManager) { + assertTrue(beanManager.getContext(RequestScoped.class).isActive()); + assertTrue(beanManager.getContext(SessionScoped.class).isActive()); + } + + @Test + @DisplayName("Test that Engine is resolved to @SessionScoped V8") + void test(@Named("special") Engine engine) { + assertEquals(engine.getThrottle(), 0); + } + + @Test + @DisplayName("Test that non-activated scopes fail") + void test(V6 engine) { + assertThrows(ContextNotActiveException.class, engine::getThrottle); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddBeanClassesTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddBeanClassesTest.java index 33c0e390..78913e70 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddBeanClassesTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddBeanClassesTest.java @@ -1,28 +1,25 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.inject.Inject; import org.jboss.weld.junit5.auto.beans.Engine; import org.jboss.weld.junit5.auto.beans.V8; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.inject.Inject; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - - @EnableAutoWeld @AddBeanClasses(V8.class) public class AddBeanClassesTest { - @Inject - private Engine engine; + @Inject + private Engine engine; - @Test - @DisplayName("Test that @AddBeanClasses pulls in V8 to fulfill the injected Engine interface") - void test() { - assertNotNull(engine); - } + @Test + @DisplayName("Test that @AddBeanClasses pulls in V8 to fulfill the injected Engine interface") + void test() { + assertNotNull(engine); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddDecoratorTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddDecoratorTest.java index 9d958b73..61acb1f6 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddDecoratorTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddDecoratorTest.java @@ -35,10 +35,10 @@ @EnableAutoWeld @AddEnabledDecorators(TestDecorator.class) public class AddDecoratorTest { - + @Inject DecoratedBean bean; - + @Test public void testBeanIsDecorated() { Assertions.assertNotNull(bean); diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddExtensionsTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddExtensionsTest.java index 7bb22123..132ac094 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddExtensionsTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddExtensionsTest.java @@ -1,22 +1,19 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.jboss.weld.junit5.auto.extension.AddedExtension; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; - - - @EnableAutoWeld @AddExtensions(AddedExtension.class) public class AddExtensionsTest { - @Test - @DisplayName("Test that @AddExtensions adds the specified extensions") - void test() { - assertTrue(AddedExtension.isEnabled()); - } + @Test + @DisplayName("Test that @AddExtensions adds the specified extensions") + void test() { + assertTrue(AddedExtension.isEnabled()); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddInterceptorTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddInterceptorTest.java index 44b09b0f..7748dd83 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddInterceptorTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddInterceptorTest.java @@ -31,10 +31,10 @@ @EnableAutoWeld @AddEnabledInterceptors(TestInterceptor.class) public class AddInterceptorTest { - + @Inject InterceptedBean bean; - + @Test public void testBeanIsIntercepted() { Assertions.assertNotNull(bean); diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddPackagesTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddPackagesTest.java index f810850a..ac59e3dc 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/AddPackagesTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/AddPackagesTest.java @@ -1,28 +1,25 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.inject.Inject; import org.jboss.weld.junit5.auto.beans.Engine; import org.jboss.weld.junit5.auto.beans.V8; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.inject.Inject; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - - @EnableAutoWeld @AddPackages(value = Engine.class, recursively = false) public class AddPackagesTest { - @Inject - private V8 engine; + @Inject + private V8 engine; - @Test - @DisplayName("Test that @AddPackages pulls in V8 to fulfill the injected Engine interface") - void test() { - assertNotNull(engine); - } + @Test + @DisplayName("Test that @AddPackages pulls in V8 to fulfill the injected Engine interface") + void test() { + assertNotNull(engine); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/AutoConfigWithWeldSetupTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/AutoConfigWithWeldSetupTest.java index 318c5867..e2df7dee 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/AutoConfigWithWeldSetupTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/AutoConfigWithWeldSetupTest.java @@ -1,5 +1,9 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.fail; + import java.lang.reflect.Field; import java.util.Optional; @@ -12,10 +16,6 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.platform.engine.support.hierarchical.ThrowableCollector; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.fail; - /** * NOTE - this test is one massive hack because JUnit, at the time of writing, doesn't allow to assert that an * exception was throws inside an extension. The test is fragile and can break because of internal JUnit 5 changes @@ -26,38 +26,38 @@ @EnableAutoWeld class AutoConfigWithWeldSetupTest { - @WeldSetup - public WeldInitiator weld = WeldInitiator.of(WeldInitiator.createWeld()); - - @Test - @ExtendWith(AssertExceptionExtension.class) - @DisplayName("Ensure that @WeldSetup is not compatible with automagic mode") - void test() { - fail("IllegalStateException expected before test method is entered"); - } - - /** - * @author Björn Kautler - */ - static public class AssertExceptionExtension implements AfterEachCallback { - - @Override - public void afterEach(ExtensionContext context) throws NoSuchFieldException, IllegalAccessException { - Optional executionException = context.getExecutionException(); - if (executionException.isPresent()) { - Field throwableCollectorField = context.getClass().getDeclaredField("throwableCollector"); - throwableCollectorField.setAccessible(true); - ThrowableCollector throwableCollector = (ThrowableCollector) throwableCollectorField.get(context); - Field throwableField = ThrowableCollector.class.getDeclaredField("throwable"); - throwableField.setAccessible(true); - throwableField.set(throwableCollector, null); - - Throwable throwable = executionException.get(); - assertInstanceOf(IllegalStateException.class, throwable); - assertEquals("When using automagic mode, no @WeldSetup annotated field should be present! Fields found:\n" - + "Field 'weld' with type class org.jboss.weld.junit5.WeldInitiator which is in class org.jboss.weld.junit5.auto.AutoConfigWithWeldSetupTest", - throwable.getMessage()); - } + @WeldSetup + public WeldInitiator weld = WeldInitiator.of(WeldInitiator.createWeld()); + + @Test + @ExtendWith(AssertExceptionExtension.class) + @DisplayName("Ensure that @WeldSetup is not compatible with automagic mode") + void test() { + fail("IllegalStateException expected before test method is entered"); + } + + /** + * @author Björn Kautler + */ + static public class AssertExceptionExtension implements AfterEachCallback { + + @Override + public void afterEach(ExtensionContext context) throws NoSuchFieldException, IllegalAccessException { + Optional executionException = context.getExecutionException(); + if (executionException.isPresent()) { + Field throwableCollectorField = context.getClass().getDeclaredField("throwableCollector"); + throwableCollectorField.setAccessible(true); + ThrowableCollector throwableCollector = (ThrowableCollector) throwableCollectorField.get(context); + Field throwableField = ThrowableCollector.class.getDeclaredField("throwable"); + throwableField.setAccessible(true); + throwableField.set(throwableCollector, null); + + Throwable throwable = executionException.get(); + assertInstanceOf(IllegalStateException.class, throwable); + assertEquals("When using automagic mode, no @WeldSetup annotated field should be present! Fields found:\n" + + "Field 'weld' with type class org.jboss.weld.junit5.WeldInitiator which is in class org.jboss.weld.junit5.auto.AutoConfigWithWeldSetupTest", + throwable.getMessage()); + } + } } - } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/BasicAutoConfigTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/BasicAutoConfigTest.java index 35170253..68307dbd 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/BasicAutoConfigTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/BasicAutoConfigTest.java @@ -1,33 +1,30 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.inject.Inject; import org.jboss.weld.junit5.basic.Foo; import org.jboss.weld.junit5.explicitInjection.Bar; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.inject.Inject; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - - - @EnableAutoWeld class BasicAutoConfigTest { - @Inject - private Foo foo; + @Inject + private Foo foo; - @Inject - private Bar bar; + @Inject + private Bar bar; - @Test - @DisplayName("Ensure the injected Foo and Bar are automatically included in container with no configuration") - void test() { - assertNotNull(bar); - assertNotNull(foo); - assertEquals(foo.getBar(), "baz"); - } + @Test + @DisplayName("Ensure the injected Foo and Bar are automatically included in container with no configuration") + void test() { + assertNotNull(bar); + assertNotNull(foo); + assertEquals(foo.getBar(), "baz"); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesDepsTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesDepsTest.java index 7848ce41..22adcb87 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesDepsTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesDepsTest.java @@ -1,15 +1,14 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.inject.Produces; + import org.jboss.weld.junit5.basic.unsatisfied.FooDeps; import org.jboss.weld.junit5.basic.unsatisfied.SomeFooDeps; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.enterprise.inject.Produces; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - @EnableAutoWeld @AddBeanClasses(SomeFooDeps.class) @ExcludeBeanClasses(FooDeps.class) diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesTest.java index 6f9332c8..b1094561 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanClassesTest.java @@ -1,15 +1,14 @@ package org.jboss.weld.junit5.auto; -import org.jboss.weld.junit5.basic.SomeFoo; -import org.jboss.weld.junit5.basic.Foo; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import jakarta.enterprise.inject.Produces; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import jakarta.enterprise.inject.Produces; + +import org.jboss.weld.junit5.basic.Foo; +import org.jboss.weld.junit5.basic.SomeFoo; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @EnableAutoWeld @AddBeanClasses(SomeFoo.class) diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanDepsTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanDepsTest.java index 2c143295..fa17af05 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanDepsTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanDepsTest.java @@ -1,15 +1,14 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.inject.Produces; + import org.jboss.weld.junit5.basic.unsatisfied.FooDeps; import org.jboss.weld.junit5.basic.unsatisfied.SomeFooDeps; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.enterprise.inject.Produces; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - @EnableAutoWeld @AddBeanClasses(SomeFooDeps.class) class ExcludeBeanDepsTest { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanHierarchyTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanHierarchyTest.java index 074133ad..bffd4c7c 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanHierarchyTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanHierarchyTest.java @@ -1,17 +1,16 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.inject.Produces; + import org.jboss.weld.junit5.basic.Foo; import org.jboss.weld.junit5.basic.IFoo; import org.jboss.weld.junit5.basic.SomeIFoo; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.enterprise.inject.Produces; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - - @EnableAutoWeld @AddBeanClasses(SomeIFoo.class) class ExcludeBeanHierarchyTest { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanTest.java index 6542c5a9..4f5f1b07 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExcludeBeanTest.java @@ -1,16 +1,15 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.inject.Produces; + import org.jboss.weld.junit5.basic.Foo; import org.jboss.weld.junit5.basic.SomeFoo; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.enterprise.inject.Produces; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - - @EnableAutoWeld @AddBeanClasses(SomeFoo.class) class ExcludeBeanTest { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExplicitParametersAutoConfigTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExplicitParametersAutoConfigTest.java index a71db66e..d736b47f 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ExplicitParametersAutoConfigTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ExplicitParametersAutoConfigTest.java @@ -1,5 +1,10 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.inject.Default; + import org.jboss.weld.junit5.ExplicitParamInjection; import org.jboss.weld.junit5.basic.Foo; import org.jboss.weld.junit5.explicitInjection.Bar; @@ -8,25 +13,18 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import jakarta.enterprise.inject.Default; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - - - @EnableAutoWeld @ExplicitParamInjection @ExtendWith(CustomExtension.class) public class ExplicitParametersAutoConfigTest { - @Test - @DisplayName("Ensure the parameter Foo is automatically included in container and that Bar comes from the CustomExtension") - void test(@Default Foo foo, Bar bar) { - assertNotNull(bar); - assertEquals(bar.ping(), CustomExtension.class.getSimpleName()); - assertNotNull(foo); - assertEquals(foo.getBar(), "baz"); - } + @Test + @DisplayName("Ensure the parameter Foo is automatically included in container and that Bar comes from the CustomExtension") + void test(@Default Foo foo, Bar bar) { + assertNotNull(bar); + assertEquals(bar.ping(), CustomExtension.class.getSimpleName()); + assertNotNull(foo); + assertEquals(foo.getBar(), "baz"); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/InheritedInjectedTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/InheritedInjectedTest.java index 76b9a366..0f3a0860 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/InheritedInjectedTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/InheritedInjectedTest.java @@ -42,7 +42,8 @@ class InjectIntoInheritedFieldsFromBeanBaseClassTest { SubClass inheritsInjected; /** - * Injection of {@link #inheritsInjected} requires {@link InheritedInjectedTest.Foo} having been identified and added as a bean class to Weld. + * Injection of {@link #inheritsInjected} requires {@link InheritedInjectedTest.Foo} having been identified and added as + * a bean class to Weld. */ @Test @DisplayName("Test inherited injected fields") diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ParametersAutoConfigTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ParametersAutoConfigTest.java index deeeee06..ee766e5a 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ParametersAutoConfigTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ParametersAutoConfigTest.java @@ -1,26 +1,24 @@ package org.jboss.weld.junit5.auto; -import org.jboss.weld.junit5.basic.Foo; -import org.jboss.weld.junit5.explicitInjection.Bar; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; - +import org.jboss.weld.junit5.basic.Foo; +import org.jboss.weld.junit5.explicitInjection.Bar; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @EnableAutoWeld public class ParametersAutoConfigTest { - @Test - @DisplayName("Ensure the parameters Foo and Bar are automatically included in container with no configuration") - void test(Foo foo, Bar bar) { - assertNotNull(bar); - assertNull(bar.ping()); - assertNotNull(foo); - assertEquals(foo.getBar(), "baz"); - } + @Test + @DisplayName("Ensure the parameters Foo and Bar are automatically included in container with no configuration") + void test(Foo foo, Bar bar) { + assertNotNull(bar); + assertNull(bar.ping()); + assertNotNull(foo); + assertEquals(foo.getBar(), "baz"); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducerMethodParametersScanningTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducerMethodParametersScanningTest.java index 8ff2bb27..3e319f10 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducerMethodParametersScanningTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducerMethodParametersScanningTest.java @@ -1,14 +1,14 @@ package org.jboss.weld.junit5.auto; -import org.jboss.weld.junit5.auto.beans.Engine; -import org.jboss.weld.junit5.auto.beans.V6; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; import jakarta.enterprise.context.Dependent; import jakarta.enterprise.inject.Produces; import jakarta.inject.Named; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.jboss.weld.junit5.auto.beans.Engine; +import org.jboss.weld.junit5.auto.beans.V6; +import org.junit.jupiter.api.Test; @EnableAutoWeld public class ProducerMethodParametersScanningTest { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducesBeforeTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducesBeforeTest.java index f38782c9..65cb5582 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducesBeforeTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ProducesBeforeTest.java @@ -1,38 +1,36 @@ package org.jboss.weld.junit5.auto; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; import jakarta.enterprise.context.Dependent; import jakarta.enterprise.inject.Produces; import jakarta.inject.Named; -import static org.junit.jupiter.api.Assertions.assertNotNull; - - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; @EnableAutoWeld class ProducesBeforeTest { - private Integer requiredValue; - - @BeforeEach - void init() { - requiredValue = 10; - } - - @Produces - @Dependent - @Named("computed") - Integer provideComputedValue() { - return requiredValue * 10; - } - - @Test - @DisplayName("Ensure that @BeforeEach runs before any @Produces methods/fields are interrogated") - void test(@Named("computed") Integer computed) { - assertNotNull(computed); - } + private Integer requiredValue; + + @BeforeEach + void init() { + requiredValue = 10; + } + + @Produces + @Dependent + @Named("computed") + Integer provideComputedValue() { + return requiredValue * 10; + } + + @Test + @DisplayName("Ensure that @BeforeEach runs before any @Produces methods/fields are interrogated") + void test(@Named("computed") Integer computed) { + assertNotNull(computed); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedClassesAreNotForcedBeansTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedClassesAreNotForcedBeansTest.java index e4f24920..cf9c4385 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedClassesAreNotForcedBeansTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedClassesAreNotForcedBeansTest.java @@ -1,16 +1,14 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.inject.Produces; import org.jboss.weld.junit5.auto.beans.unsatisfied.InjectedV8NoAnnotation; import org.jboss.weld.junit5.auto.beans.unsatisfied.V8NoAnnotation; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.enterprise.inject.Produces; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - @EnableAutoWeld @AddBeanClasses(InjectedV8NoAnnotation.class) public class ScannedClassesAreNotForcedBeansTest { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedParameterClassesAreNotForcedBeansTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedParameterClassesAreNotForcedBeansTest.java index 5ec4ed17..114f803a 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedParameterClassesAreNotForcedBeansTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedParameterClassesAreNotForcedBeansTest.java @@ -1,16 +1,14 @@ package org.jboss.weld.junit5.auto; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import jakarta.enterprise.inject.Produces; import org.jboss.weld.junit5.auto.beans.unsatisfied.ConstructedV8NoAnnotation; import org.jboss.weld.junit5.auto.beans.unsatisfied.V8NoAnnotation; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import jakarta.enterprise.inject.Produces; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - @EnableAutoWeld @AddBeanClasses(ConstructedV8NoAnnotation.class) public class ScannedParameterClassesAreNotForcedBeansTest { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/SetDiscoveryModeAllTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/SetDiscoveryModeAllTest.java index c93f3d21..cd0e9306 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/SetDiscoveryModeAllTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/SetDiscoveryModeAllTest.java @@ -5,6 +5,7 @@ import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; + import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode; import org.jboss.weld.junit5.auto.discovery.WithBeanDefiningAnnotation; import org.jboss.weld.junit5.auto.discovery.WithoutBeanDefiningAnnotation; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/alternativeStereotype/SomeStereotype.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/alternativeStereotype/SomeStereotype.java index dbb9afeb..4c3aca33 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/alternativeStereotype/SomeStereotype.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/alternativeStereotype/SomeStereotype.java @@ -33,5 +33,5 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface SomeStereotype { - + } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/Engine.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/Engine.java index f5859bd7..9f6a26f2 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/Engine.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/Engine.java @@ -1,9 +1,9 @@ package org.jboss.weld.junit5.auto.beans; - public interface Engine { - int getThrottle(); - void setThrottle(int value); + int getThrottle(); + + void setThrottle(int value); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V6.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V6.java index ba433e9b..14eb0eb1 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V6.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V6.java @@ -1,24 +1,21 @@ package org.jboss.weld.junit5.auto.beans; - import java.io.Serializable; import jakarta.enterprise.context.ApplicationScoped; - - @ApplicationScoped public class V6 implements Engine, Serializable { - private int throttle = 0; + private int throttle = 0; - public int getThrottle() { - return throttle; - } + public int getThrottle() { + return throttle; + } - @Override - public void setThrottle(int throttle) { - this.throttle = throttle; - } + @Override + public void setThrottle(int throttle) { + this.throttle = throttle; + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V8.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V8.java index db356077..d818f0c3 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V8.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/V8.java @@ -1,22 +1,21 @@ package org.jboss.weld.junit5.auto.beans; +import java.io.Serializable; import jakarta.enterprise.context.Dependent; -import java.io.Serializable; - @Dependent public class V8 implements Engine, Serializable { - private int throttle = 0; + private int throttle = 0; - public int getThrottle() { - return throttle; - } + public int getThrottle() { + return throttle; + } - @Override - public void setThrottle(int throttle) { - this.throttle = throttle; - } + @Override + public void setThrottle(int throttle) { + this.throttle = throttle; + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/unsatisfied/V8NoAnnotation.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/unsatisfied/V8NoAnnotation.java index c0c89390..84f396ec 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/unsatisfied/V8NoAnnotation.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/beans/unsatisfied/V8NoAnnotation.java @@ -1,9 +1,9 @@ package org.jboss.weld.junit5.auto.beans.unsatisfied; -import org.jboss.weld.junit5.auto.beans.Engine; - import java.io.Serializable; +import org.jboss.weld.junit5.auto.beans.Engine; + // NOTE - deliberately missing bean defining annotation public class V8NoAnnotation implements Engine, Serializable { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/extension/AddedExtension.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/extension/AddedExtension.java index a63e253a..d804541e 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/extension/AddedExtension.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/extension/AddedExtension.java @@ -20,7 +20,6 @@ import jakarta.enterprise.inject.spi.AfterBeanDiscovery; import jakarta.enterprise.inject.spi.Extension; - public class AddedExtension implements Extension { private static boolean enabled = false; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBean.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBean.java index 4b0c6ba6..043937d1 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBean.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBean.java @@ -23,11 +23,11 @@ * @author Matej Novotny */ @Dependent -public class DecoratedBean implements DecoratedBeanInterface{ +public class DecoratedBean implements DecoratedBeanInterface { @Override public String ping() { return DecoratedBean.class.toString(); } - + } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBeanInterface.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBeanInterface.java index 32abb59c..57675a8d 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBeanInterface.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/DecoratedBeanInterface.java @@ -21,6 +21,6 @@ * @author Matej Novotny */ public interface DecoratedBeanInterface { - + public String ping(); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/InterceptedBean.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/InterceptedBean.java index ef1ab77f..7000ce61 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/InterceptedBean.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/InterceptedBean.java @@ -25,7 +25,7 @@ @TestInterceptorBinding @Dependent public class InterceptedBean { - + public String ping() { return InterceptedBean.class.toString(); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestDecorator.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestDecorator.java index 962eb88b..a9e797f8 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestDecorator.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestDecorator.java @@ -25,8 +25,8 @@ * @author Matej Novotny */ @Decorator -public class TestDecorator implements DecoratedBeanInterface{ - +public class TestDecorator implements DecoratedBeanInterface { + @Inject @Delegate DecoratedBeanInterface delegate; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptor.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptor.java index 2c1c2a34..078751ac 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptor.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptor.java @@ -27,7 +27,7 @@ @Interceptor @TestInterceptorBinding public class TestInterceptor { - + @AroundInvoke public Object intercept(InvocationContext ctx) throws Exception { return TestInterceptor.class.toString() + ctx.proceed(); diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptorBinding.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptorBinding.java index 1f00cd17..c36ca07e 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptorBinding.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/interceptorAndDecorator/TestInterceptorBinding.java @@ -31,5 +31,5 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface TestInterceptorBinding { - + } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/auto/nested/OuterTestClassAndBeanSameInstanceTest.java b/junit5/src/test/java/org/jboss/weld/junit5/auto/nested/OuterTestClassAndBeanSameInstanceTest.java index 57fdca9c..532a2dbc 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/auto/nested/OuterTestClassAndBeanSameInstanceTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/auto/nested/OuterTestClassAndBeanSameInstanceTest.java @@ -19,8 +19,10 @@ /** * Tests that outer test classes don't get instantiated again for CDI annotations. *

- * Classes with CDI annotations are usually treated as beans by Weld and, hence, instantiated as and when required. Test classes, however, are instantiated by JUnit. - * Weld should pick up the test instances instantiated by JUnit instead of instantiating another instance and continue to operate on them as usual with beans. + * Classes with CDI annotations are usually treated as beans by Weld and, hence, instantiated as and when required. Test + * classes, however, are instantiated by JUnit. + * Weld should pick up the test instances instantiated by JUnit instead of instantiating another instance and continue to + * operate on them as usual with beans. *
* This test asserts that the same instance as the {@link org.junit.jupiter.api.Test @Test} methods are invoked on *

    @@ -32,17 +34,26 @@ *
      *
    • {@link Observes @Observes} or
    • *
    • {@link Disposes @Disposes}
    • - *
+ * + * + * + * + * * and assumes if that were not true that there would have been another instance of the test class. *

- * In order to understand how the test works (or failed earlier), consider to with particular test instance each outer test class member variable would refer to - * if Weld instantiated another, second, and undesired instance of the outer test class besides the obviously wanted one already instantiated by JUnit. + * In order to understand how the test works (or failed earlier), consider to with particular test instance each outer test + * class member variable would refer to + * if Weld instantiated another, second, and undesired instance of the outer test class besides the obviously wanted one already + * instantiated by JUnit. *

- * Besides all that, Weld ignores classes that don't meet valid bean requirements which affects all {@link org.junit.jupiter.api.Nested @Nested} test classes due to a lack of a no-arg constructor and - * Weld is reluctant to handle {@link Produces @Produces}, {@link Observes @Observes}, or {@link Disposes @Disposes} annotations on them or + * Besides all that, Weld ignores classes that don't meet valid bean requirements which affects all + * {@link org.junit.jupiter.api.Nested @Nested} test classes due to a lack of a no-arg constructor and + * Weld is reluctant to handle {@link Produces @Produces}, {@link Observes @Observes}, or {@link Disposes + * @Disposes} annotations on them or * instances of {@link Inject @Inject}ing nested test classes into other beans - * but {@link Inject @Inject}ing into test instances works on all test classes whether {@link org.junit.jupiter.api.Nested @Nested} or not. - * + * but {@link Inject @Inject}ing into test instances works on all test classes whether {@link org.junit.jupiter.api.Nested + * @Nested} or not. + * * @see https://github.com/weld/weld-junit/issues/103 */ @EnableAutoWeld @@ -115,7 +126,8 @@ void disposeBean(@Disposes Bean bean) { assertEquals(theBean.ping(), bean.ping()); } - @Inject @Any + @Inject + @Any Event event; Bean observedBean; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/basic/BeanManagerTest.java b/junit5/src/test/java/org/jboss/weld/junit5/basic/BeanManagerTest.java index c32cb0ee..e75fce52 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/basic/BeanManagerTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/basic/BeanManagerTest.java @@ -23,7 +23,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - /** * * @author Matej Novotny diff --git a/junit5/src/test/java/org/jboss/weld/junit5/basic/CustomWeldTest.java b/junit5/src/test/java/org/jboss/weld/junit5/basic/CustomWeldTest.java index f16c5129..73a347f7 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/basic/CustomWeldTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/basic/CustomWeldTest.java @@ -31,7 +31,8 @@ public class CustomWeldTest { @WeldSetup - public WeldInitiator weld = WeldInitiator.of(WeldInitiator.createWeld().alternatives(FooAlternative.class).beanClasses(Foo.class, FooAlternative.class)); + public WeldInitiator weld = WeldInitiator + .of(WeldInitiator.createWeld().alternatives(FooAlternative.class).beanClasses(Foo.class, FooAlternative.class)); @Test public void testFooAlternative() { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/basic/DisabledMethodsTest.java b/junit5/src/test/java/org/jboss/weld/junit5/basic/DisabledMethodsTest.java index 1d4a27f9..297a98ed 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/basic/DisabledMethodsTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/basic/DisabledMethodsTest.java @@ -1,5 +1,8 @@ package org.jboss.weld.junit5.basic; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.jboss.weld.environment.se.WeldContainer; import org.jboss.weld.junit5.WeldInitiator; import org.jboss.weld.junit5.WeldJunit5Extension; @@ -13,9 +16,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.parallel.Isolated; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - /** * Tests that disabled methods do not trigger Weld container startup. * For this test to work, @TestMethodOrder is required. diff --git a/junit5/src/test/java/org/jboss/weld/junit5/basic/EnableWeldTest.java b/junit5/src/test/java/org/jboss/weld/junit5/basic/EnableWeldTest.java index 75864243..984e8a7c 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/basic/EnableWeldTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/basic/EnableWeldTest.java @@ -12,13 +12,13 @@ @EnableWeld public class EnableWeldTest { - @Inject - BeanManager beanManager; - - @Test - @DisplayName("@EnableWeld initializes the Weld CDI container") - void enableWeldAnnotationInitializesTheWeldContainer() { - assertNotNull(beanManager); - } - + @Inject + BeanManager beanManager; + + @Test + @DisplayName("@EnableWeld initializes the Weld CDI container") + void enableWeldAnnotationInitializesTheWeldContainer() { + assertNotNull(beanManager); + } + } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/basic/Foo.java b/junit5/src/test/java/org/jboss/weld/junit5/basic/Foo.java index 8b749a4b..e8c73e03 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/basic/Foo.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/basic/Foo.java @@ -19,14 +19,13 @@ import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.ApplicationScoped; - - @ApplicationScoped public class Foo implements IFoo { private String bar; - public Foo() {} + public Foo() { + } public Foo(String bar) { this.bar = bar; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/basic/SimpleTest.java b/junit5/src/test/java/org/jboss/weld/junit5/basic/SimpleTest.java index 64b03408..97977110 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/basic/SimpleTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/basic/SimpleTest.java @@ -19,6 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import jakarta.inject.Inject; + import org.jboss.weld.junit5.WeldInitiator; import org.jboss.weld.junit5.WeldJunit5Extension; import org.jboss.weld.junit5.WeldSetup; @@ -26,8 +28,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import jakarta.inject.Inject; - /** * * @author Matej Novotny diff --git a/junit5/src/test/java/org/jboss/weld/junit5/basic/unsatisfied/FooDeps.java b/junit5/src/test/java/org/jboss/weld/junit5/basic/unsatisfied/FooDeps.java index 06803d69..7c2c14af 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/basic/unsatisfied/FooDeps.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/basic/unsatisfied/FooDeps.java @@ -19,14 +19,14 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; - @ApplicationScoped public class FooDeps { @Inject Baz baz; - public FooDeps() {} + public FooDeps() { + } public String getBar() { return baz.getBar(); diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/AddBeanTest.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/AddBeanTest.java index c203eea4..88040b2e 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/bean/AddBeanTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/AddBeanTest.java @@ -61,27 +61,27 @@ public class AddBeanTest { @SuppressWarnings("serial") static Bean createListBean() { return MockBean.builder() - .types(new TypeLiteral>() { - }.getType()) - .qualifiers(Meaty.Literal.INSTANCE) - .creating( - // Mock object provided by Mockito - Mockito.when(Mockito.mock(List.class).get(0)).thenReturn("42").getMock()) - .build(); + .types(new TypeLiteral>() { + }.getType()) + .qualifiers(Meaty.Literal.INSTANCE) + .creating( + // Mock object provided by Mockito + Mockito.when(Mockito.mock(List.class).get(0)).thenReturn("42").getMock()) + .build(); } static Bean createSequenceBean() { - return MockBean.builder() - .types(Integer.class) - .qualifiers(Meaty.Literal.INSTANCE) - .create((ctx) -> SEQUENCE.incrementAndGet()).build(); + return MockBean. builder() + .types(Integer.class) + .qualifiers(Meaty.Literal.INSTANCE) + .create((ctx) -> SEQUENCE.incrementAndGet()).build(); } static Bean createIdSupplierBean() { - return MockBean.builder() - .types(IdSupplier.class) - .scope(ApplicationScoped.class) - .create(ctx -> new IdSupplier(UUID.randomUUID().toString())).build(); + return MockBean. builder() + .types(IdSupplier.class) + .scope(ApplicationScoped.class) + .create(ctx -> new IdSupplier(UUID.randomUUID().toString())).build(); } @Test @@ -93,7 +93,7 @@ public void testBeansAdded() { SEQUENCE.set(0); for (int i = 1; i < 11; i++) { assertEquals(Integer.valueOf(i), - weld.select(Integer.class, Meaty.Literal.INSTANCE).get()); + weld.select(Integer.class, Meaty.Literal.INSTANCE).get()); } // Mock with default settings diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/AddGloballyEnabledAlternativeTest.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/AddGloballyEnabledAlternativeTest.java index 3a09d1c0..3d31a294 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/bean/AddGloballyEnabledAlternativeTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/AddGloballyEnabledAlternativeTest.java @@ -1,5 +1,11 @@ package org.jboss.weld.junit5.bean; +import java.util.List; +import java.util.Set; + +import jakarta.enterprise.inject.spi.Bean; +import jakarta.enterprise.util.TypeLiteral; + import org.jboss.weld.junit.MockBean; import org.jboss.weld.junit5.WeldInitiator; import org.jboss.weld.junit5.WeldJunit5Extension; @@ -10,12 +16,6 @@ import org.junit.jupiter.api.parallel.Isolated; import org.mockito.Mockito; -import jakarta.enterprise.inject.spi.Bean; -import jakarta.enterprise.util.TypeLiteral; - -import java.util.List; -import java.util.Set; - /** * Tests {@link org.jboss.weld.junit.MockBean} adding a bean that is a globally enabled alternative. * @@ -30,7 +30,7 @@ public class AddGloballyEnabledAlternativeTest { .addBeans(createFooAlternativeBean(), createListBean()) .build(); - public static Bean createFooAlternativeBean(){ + public static Bean createFooAlternativeBean() { return MockBean.read(Foo.class) .priority(3) .alternative(true) @@ -61,7 +61,8 @@ public void testAllBeansAreAddedAndCanBeSelected() { Assertions.assertEquals(1, beans.size()); Assertions.assertTrue(beans.iterator().next().isAlternative()); - beans = weld.getBeanManager().getBeans(new TypeLiteral>(){}.getType()); + beans = weld.getBeanManager().getBeans(new TypeLiteral>() { + }.getType()); Assertions.assertEquals(1, beans.size()); Assertions.assertTrue(beans.iterator().next().isAlternative()); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/AddPassivatingBeanTest.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/AddPassivatingBeanTest.java index 79337ef2..048d1197 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/bean/AddPassivatingBeanTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/AddPassivatingBeanTest.java @@ -46,13 +46,13 @@ public class AddPassivatingBeanTest { @SuppressWarnings("serial") static Bean createListBean() { return MockBean.builder() - .types(new TypeLiteral>() { - }.getType()) - .scope(SessionScoped.class) - .creating( - // Mock object provided by Mockito - when(mock(List.class).get(0)).thenReturn("42").getMock()) - .build(); + .types(new TypeLiteral>() { + }.getType()) + .scope(SessionScoped.class) + .creating( + // Mock object provided by Mockito + when(mock(List.class).get(0)).thenReturn("42").getMock()) + .build(); } @SuppressWarnings("serial") diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/AlternativeMockBeanTest.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/AlternativeMockBeanTest.java index 331cfeae..719537b1 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/bean/AlternativeMockBeanTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/AlternativeMockBeanTest.java @@ -34,7 +34,8 @@ public class AlternativeMockBeanTest { @WeldSetup public WeldInitiator weld = WeldInitiator.from(SimpleService.class) - .addBeans(MockBean.builder().types(MyService.class).selectedAlternative().beanClass(CoolService.class).create(c -> new CoolService()).build()) + .addBeans(MockBean.builder().types(MyService.class).selectedAlternative().beanClass(CoolService.class) + .create(c -> new CoolService()).build()) .build(); @Test diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/Bar.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/Bar.java index ce53b1a0..f277548a 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/bean/Bar.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/Bar.java @@ -1,8 +1,9 @@ package org.jboss.weld.junit5.bean; +import java.util.List; + import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import java.util.List; @ApplicationScoped public class Bar { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/bean/MockBeanWithQualifiersTest.java b/junit5/src/test/java/org/jboss/weld/junit5/bean/MockBeanWithQualifiersTest.java index 5daa68d7..46be0655 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/bean/MockBeanWithQualifiersTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/bean/MockBeanWithQualifiersTest.java @@ -1,5 +1,7 @@ package org.jboss.weld.junit5.bean; +import jakarta.enterprise.inject.Any; + import org.jboss.weld.junit.MockBean; import org.jboss.weld.junit5.EnableWeld; import org.jboss.weld.junit5.WeldInitiator; @@ -7,8 +9,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import jakarta.enterprise.inject.Any; - /** * Tests that {@link MockBean} with custom qualifiers has {@link Any} qualifier automatically added. */ 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 index c7c8138b..6fd97e99 100644 --- 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 @@ -31,7 +31,7 @@ public class MyExtension implements Extension { public void observePAT(@Observes ProcessAnnotatedType event) { beanObserved = true; } - + public boolean beanObserved() { return beanObserved; } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/contexts/ContextsActivatedTest.java b/junit5/src/test/java/org/jboss/weld/junit5/contexts/ContextsActivatedTest.java index 9712edad..602f8838 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/contexts/ContextsActivatedTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/contexts/ContextsActivatedTest.java @@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - /** * * @author Matej Novotny diff --git a/junit5/src/test/java/org/jboss/weld/junit5/contexts/SomeAnnotation.java b/junit5/src/test/java/org/jboss/weld/junit5/contexts/SomeAnnotation.java index 1510040a..e06966bc 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/contexts/SomeAnnotation.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/contexts/SomeAnnotation.java @@ -25,5 +25,5 @@ */ @Retention(RetentionPolicy.RUNTIME) public @interface SomeAnnotation { - + } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/contexts/events/ContextLifecycleEventsTest.java b/junit5/src/test/java/org/jboss/weld/junit5/contexts/events/ContextLifecycleEventsTest.java index de4f914e..56776e11 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/contexts/events/ContextLifecycleEventsTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/contexts/events/ContextLifecycleEventsTest.java @@ -37,7 +37,8 @@ public class ContextLifecycleEventsTest { @WeldSetup - public WeldInitiator weld = WeldInitiator.from(ContextLifecycleEventsObserver.class).activate(RequestScoped.class, SessionScoped.class).build(); + public WeldInitiator weld = WeldInitiator.from(ContextLifecycleEventsObserver.class) + .activate(RequestScoped.class, SessionScoped.class).build(); @Test public void testInitFired() { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/enricher/FooWeldJunitEnricher.java b/junit5/src/test/java/org/jboss/weld/junit5/enricher/FooWeldJunitEnricher.java index 2c7348bc..b2edd397 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/enricher/FooWeldJunitEnricher.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/enricher/FooWeldJunitEnricher.java @@ -23,14 +23,13 @@ import org.jboss.weld.junit5.enricher.disabled.WeldJunitEnricherDisabledTest; import org.junit.jupiter.api.extension.ExtensionContext; - - public class FooWeldJunitEnricher implements WeldJunitEnricher { @Override public void enrich(Object testInstance, ExtensionContext context, Weld weld, - Builder weldInitiatorBuilder) { - if (WeldJunitEnricherTest.class.equals(testInstance.getClass()) || WeldJunitEnricherDisabledTest.class.equals(testInstance.getClass())) { + Builder weldInitiatorBuilder) { + if (WeldJunitEnricherTest.class.equals(testInstance.getClass()) + || WeldJunitEnricherDisabledTest.class.equals(testInstance.getClass())) { weld.addBeanClass(Foo.class); } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/explicitInjection/CustomExtension.java b/junit5/src/test/java/org/jboss/weld/junit5/explicitInjection/CustomExtension.java index 1972a24a..d497b7f3 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/explicitInjection/CustomExtension.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/explicitInjection/CustomExtension.java @@ -23,19 +23,22 @@ /** * Custom extension just to verify a case where we declare we cannot handle some types. + * * @author Matej Novotny */ public class CustomExtension implements ParameterResolver { @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { // dumb approach but we only ever resolve Bar anyway :) return new Bar(CustomExtension.class.getSimpleName()); } @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { return parameterContext.getParameter().getType().equals(Bar.class); } - + } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/JUnit5ExtensionTest.java b/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/JUnit5ExtensionTest.java index 257c5115..3c58aa16 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/JUnit5ExtensionTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/JUnit5ExtensionTest.java @@ -16,19 +16,21 @@ */ package org.jboss.weld.junit5.extensionInjection; +import java.util.Map; + import jakarta.enterprise.event.Event; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; + import org.jboss.weld.junit5.WeldJunit5Extension; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import java.util.Map; - /** * Basic test for JUnit 5 injection into parameter/field handled by Weld + * * @author Matej Novotny */ @ExtendWith(WeldJunit5Extension.class) @@ -58,6 +60,7 @@ public void testparamInjectionWithQualifier(@MyQualifier BarBean bar) { Assertions.assertNotNull(bar); bar.ping(); } + @Nested class TestParameterInjectionWithParametrizedTypes { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MapProducer.java b/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MapProducer.java index 181cb9ce..3018b508 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MapProducer.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MapProducer.java @@ -1,19 +1,19 @@ package org.jboss.weld.junit5.extensionInjection; +import java.util.HashMap; +import java.util.Map; + import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.Dependent; import jakarta.enterprise.inject.Produces; import jakarta.enterprise.inject.spi.InjectionPoint; -import java.util.HashMap; -import java.util.Map; - @ApplicationScoped public class MapProducer { @Produces @Dependent - public Map produceMap(InjectionPoint ip) { + public Map produceMap(InjectionPoint ip) { Map map = new HashMap<>(); map.put(ip.getType().getTypeName(), null); return map; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MyQualifier.java b/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MyQualifier.java index 4d73f164..e666e240 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MyQualifier.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/extensionInjection/MyQualifier.java @@ -28,8 +28,8 @@ * @author Matej Novotny */ @Qualifier -@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) +@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface MyQualifier { - + } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Bar.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Bar.java index 410a815e..f421cab0 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Bar.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Bar.java @@ -1,3 +1,4 @@ package org.jboss.weld.junit5.initiator.bean; -public class Bar {} +public class Bar { +} diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Foo.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Foo.java index 1641bdaf..776b237a 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Foo.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/bean/Foo.java @@ -1,6 +1,5 @@ package org.jboss.weld.junit5.initiator.bean; -public class Foo -{ +public class Foo { } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/NestedClassesWeldInitiatorTest.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/NestedClassesWeldInitiatorTest.java index 7e9f4393..af570233 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/NestedClassesWeldInitiatorTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/NestedClassesWeldInitiatorTest.java @@ -1,6 +1,7 @@ package org.jboss.weld.junit5.initiator.discovery; import jakarta.inject.Inject; + import org.jboss.weld.exceptions.UnsatisfiedResolutionException; import org.jboss.weld.junit5.EnableWeld; import org.jboss.weld.junit5.WeldInitiator; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/ObjectWeldInitiatorTest.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/ObjectWeldInitiatorTest.java index 5d39aa5b..cfc5c630 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/ObjectWeldInitiatorTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/ObjectWeldInitiatorTest.java @@ -16,6 +16,8 @@ */ package org.jboss.weld.junit5.initiator.discovery; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import org.jboss.weld.environment.se.Weld; import org.jboss.weld.junit5.EnableWeld; import org.jboss.weld.junit5.WeldInitiator; @@ -23,8 +25,6 @@ import org.jboss.weld.junit5.initiator.bean.Foo; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; - /** * Tests a case where WeldInitiator is an Object typed field * @@ -35,8 +35,8 @@ public class ObjectWeldInitiatorTest { @WeldSetup public Object weld = WeldInitiator - .of(new Weld() - .addBeanClass(Foo.class)); + .of(new Weld() + .addBeanClass(Foo.class)); @Test public void testObjectWeldInit() { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/PrivateWeldInitiatorTest.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/PrivateWeldInitiatorTest.java index bb53466c..1ac94b4c 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/PrivateWeldInitiatorTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/PrivateWeldInitiatorTest.java @@ -35,8 +35,8 @@ public class PrivateWeldInitiatorTest { @WeldSetup private WeldInitiator weld = WeldInitiator - .of(new Weld() - .addBeanClass(Foo.class)); + .of(new Weld() + .addBeanClass(Foo.class)); @Test public void testPrivateWeldInit() { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SubclassWithWeldInitiatorTest.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SubclassWithWeldInitiatorTest.java index c25cc131..e6e05736 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SubclassWithWeldInitiatorTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SubclassWithWeldInitiatorTest.java @@ -5,12 +5,10 @@ import org.jboss.weld.junit5.initiator.bean.Foo; import org.junit.jupiter.api.Test; -public class SubclassWithWeldInitiatorTest extends SuperclassWithWeldInitiator -{ - @Test - public void testSuperclassWeldInit() - { - final Foo foo = weld.select(Foo.class).get(); - assertNotNull(foo); - } +public class SubclassWithWeldInitiatorTest extends SuperclassWithWeldInitiator { + @Test + public void testSuperclassWeldInit() { + final Foo foo = weld.select(Foo.class).get(); + assertNotNull(foo); + } } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithPrivateWeldInitiator.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithPrivateWeldInitiator.java index dd355c2a..eb56d9ab 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithPrivateWeldInitiator.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithPrivateWeldInitiator.java @@ -29,6 +29,6 @@ public class SuperclassWithPrivateWeldInitiator { @WeldSetup private WeldInitiator weld = WeldInitiator - .of(new Weld() - .addBeanClass(Foo.class)); + .of(new Weld() + .addBeanClass(Foo.class)); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithProtectedWeldInitiator.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithProtectedWeldInitiator.java index 17c411ef..3e218bf3 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithProtectedWeldInitiator.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithProtectedWeldInitiator.java @@ -29,6 +29,6 @@ public class SuperclassWithProtectedWeldInitiator { @WeldSetup protected WeldInitiator weld = WeldInitiator - .of(new Weld() - .addBeanClass(Foo.class)); + .of(new Weld() + .addBeanClass(Foo.class)); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithWeldInitiator.java b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithWeldInitiator.java index e85b12a5..05777d6d 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithWeldInitiator.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/initiator/discovery/SuperclassWithWeldInitiator.java @@ -8,10 +8,9 @@ import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(WeldJunit5Extension.class) -public abstract class SuperclassWithWeldInitiator -{ - @WeldSetup - public WeldInitiator weld = WeldInitiator - .of(new Weld() - .addBeanClass(Foo.class)); +public abstract class SuperclassWithWeldInitiator { + @WeldSetup + public WeldInitiator weld = WeldInitiator + .of(new Weld() + .addBeanClass(Foo.class)); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/interceptor/MockInterceptorTest.java b/junit5/src/test/java/org/jboss/weld/junit5/interceptor/MockInterceptorTest.java index cae54b83..b5437e9d 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/interceptor/MockInterceptorTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/interceptor/MockInterceptorTest.java @@ -52,12 +52,14 @@ public class MockInterceptorTest { MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).aroundInvoke((ctx, b) -> { aroundInvokes.add(b.getBeanClass().getName()); return ctx.proceed(); - }), + }), // This interceptor is disabled MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).beanClass(String.class).aroundInvoke((ctx, b) -> { return false; - }), - MockInterceptor.withBindings(FooBinding.Literal.INSTANCE).postConstruct((ctx, b) -> postConstructs.add(b.getBeanClass().getName()))).build(); + }), + MockInterceptor.withBindings(FooBinding.Literal.INSTANCE) + .postConstruct((ctx, b) -> postConstructs.add(b.getBeanClass().getName()))) + .build(); @BeforeEach public void setup() { @@ -78,7 +80,8 @@ public void testInterception() { @Test public void testDisabledInterceptor() { - List> interceptors = weld.getBeanManager().resolveInterceptors(InterceptionType.AROUND_INVOKE, FooBinding.Literal.INSTANCE); + List> interceptors = weld.getBeanManager().resolveInterceptors(InterceptionType.AROUND_INVOKE, + FooBinding.Literal.INSTANCE); assertEquals(1, interceptors.size()); assertEquals(MockInterceptor.class, interceptors.get(0).getBeanClass()); } diff --git a/junit5/src/test/java/org/jboss/weld/junit5/nested/NestedTestClassTest.java b/junit5/src/test/java/org/jboss/weld/junit5/nested/NestedTestClassTest.java index b51c3b8a..709133d7 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/nested/NestedTestClassTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/nested/NestedTestClassTest.java @@ -1,5 +1,7 @@ package org.jboss.weld.junit5.nested; +import jakarta.inject.Inject; + import org.jboss.weld.junit5.WeldInitiator; import org.jboss.weld.junit5.WeldJunit5Extension; import org.jboss.weld.junit5.WeldSetup; @@ -9,8 +11,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import jakarta.inject.Inject; - /** * Tests a {@code @BeforeEach} method in superclass when actual test is in the inner class. * {@code @BeforeEach} should still be invoked for nested classes. For the below scenario to work, diff --git a/junit5/src/test/java/org/jboss/weld/junit5/resources/InjectResourcesTest.java b/junit5/src/test/java/org/jboss/weld/junit5/resources/InjectResourcesTest.java index 22eae56f..9e798dfe 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/resources/InjectResourcesTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/resources/InjectResourcesTest.java @@ -58,11 +58,11 @@ public class InjectResourcesTest { @WeldSetup public WeldInitiator weld = WeldInitiator.fromTestPackage() - .bindResource("bar", "hello1") - .bindResource("java:comp/env/baz", "hello2") - .setEjbFactory(ip -> new DummySessionBean("ping")) - .setPersistenceUnitFactory(getPUFactory()) - .setPersistenceContextFactory(getPCFactory()).build(); + .bindResource("bar", "hello1") + .bindResource("java:comp/env/baz", "hello2") + .setEjbFactory(ip -> new DummySessionBean("ping")) + .setPersistenceUnitFactory(getPUFactory()) + .setPersistenceContextFactory(getPCFactory()).build(); @Test public void testResourceInjection() { diff --git a/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PerClassLifecycleTest.java b/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PerClassLifecycleTest.java index 9e7ca683..0863e846 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PerClassLifecycleTest.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PerClassLifecycleTest.java @@ -39,7 +39,7 @@ public class PerClassLifecycleTest { @WeldSetup public WeldInitiator initiator = WeldInitiator.of(new Weld(String.valueOf(System.nanoTime())) - .disableDiscovery().addBeanClass(PlainBean.class)); + .disableDiscovery().addBeanClass(PlainBean.class)); String containerId = null; diff --git a/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PlainBean.java b/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PlainBean.java index f2f9bc30..73b0de02 100644 --- a/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PlainBean.java +++ b/junit5/src/test/java/org/jboss/weld/junit5/testLifecycle/PlainBean.java @@ -24,5 +24,5 @@ */ @ApplicationScoped public class PlainBean { - + } diff --git a/pom.xml b/pom.xml index b00859ea..5e31da19 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.jboss.weld weld-parent - 46 + 47 http://weld.cdi-spec.org diff --git a/spock/src/main/java/org/jboss/weld/spock/DisableWeld.java b/spock/src/main/java/org/jboss/weld/spock/DisableWeld.java index a2340948..f4d9cf68 100644 --- a/spock/src/main/java/org/jboss/weld/spock/DisableWeld.java +++ b/spock/src/main/java/org/jboss/weld/spock/DisableWeld.java @@ -17,29 +17,32 @@ package org.jboss.weld.spock; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; import spock.lang.Shared; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * An annotation with which Weld can be disabled on specification or feature level if it was * enabled globally or on specification level. * - *

If Weld is enabled for a specification globally or by annotation with specification scope, + *

+ * If Weld is enabled for a specification globally or by annotation with specification scope, * and disabled for a feature, there will still be the specification scoped Weld running during the * test and {@link Shared @Shared} fields injected from that instance, but the non-{@code @Shared} * fields, and parameters of {@code setup}, feature, and {@code cleanup} methods will not be injected. * - *

On any class that is not a specification and on any method that is not a feature, this annotation + *

+ * On any class that is not a specification and on any method that is not a feature, this annotation * is simply ignored and has no effect. * - *

If this annotation is applied on the same element as {@link EnableWeld @EnableWeld}, an exception + *

+ * If this annotation is applied on the same element as {@link EnableWeld @EnableWeld}, an exception * is thrown as it is unclear which should have precedence. * * @author Björn Kautler diff --git a/spock/src/main/java/org/jboss/weld/spock/EnableWeld.java b/spock/src/main/java/org/jboss/weld/spock/EnableWeld.java index 66ca470c..a180c4f6 100644 --- a/spock/src/main/java/org/jboss/weld/spock/EnableWeld.java +++ b/spock/src/main/java/org/jboss/weld/spock/EnableWeld.java @@ -17,29 +17,33 @@ package org.jboss.weld.spock; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static org.jboss.weld.spock.EnableWeld.Scope.ITERATION; + import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.jboss.weld.spock.impl.EnableWeldExtension; -import spock.lang.Shared; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static org.jboss.weld.spock.EnableWeld.Scope.ITERATION; +import spock.lang.Shared; /** * An annotation with which Weld can be enabled on specification or feature level if it was * disabled globally or on specification level. * - *

The exact effect of this annotation depends on the further properties set on it as described + *

+ * The exact effect of this annotation depends on the further properties set on it as described * in the documentation of the individual properties. * - *

On any class that is not a specification and on any method that is not a feature, this annotation + *

+ * On any class that is not a specification and on any method that is not a feature, this annotation * is simply ignored and has no effect. * - *

If this annotation is applied on the same element as {@link DisableWeld @DisableWeld}, an exception + *

+ * If this annotation is applied on the same element as {@link DisableWeld @DisableWeld}, an exception * is thrown as it is unclear which should have precedence. * * @author Björn Kautler @@ -56,7 +60,8 @@ * Whether to use the {@link org.jboss.weld.spock.impl.EnableWeldManualInterceptor} ({@code false}) with which you mostly * manually configure Weld and have full control over which beans make it into the container, or the * {@link org.jboss.weld.spock.impl.EnableWeldAutoInterceptor} with which most things should happen automagically - * but can be adjusted using annotations. See those classes' documentation and also {@link EnableWeldExtension} for further information. + * but can be adjusted using annotations. See those classes' documentation and also {@link EnableWeldExtension} for further + * information. * * @return whether to use automagic or manual logic */ @@ -77,7 +82,8 @@ * running Spock extension. Using this parameter, this automatic behavior can be disabled and instead require * that each parameter that should be injected has a qualifier annotation, like for example {@code @Default}. * - *

If explicit parameter injection is enabled and a parameter that is not yet injected by another Spock extension + *

+ * If explicit parameter injection is enabled and a parameter that is not yet injected by another Spock extension * but has a qualifier annotation cannot be resolved using the Weld container, an exception will be thrown. * * @return whether to require explicit parameter injection @@ -93,31 +99,40 @@ enum Scope { * exclusively used for this iteration and after the iteration (after the {@code cleanup} method is called) * shut down again. * - *

The {@link Shared @Shared} fields will be injected, but only at the time the iteration starts running. + *

+ * The {@link Shared @Shared} fields will be injected, but only at the time the iteration starts running. * If you have multiple such Weld instances in one specification and use the parallel execution feature of Spock, - * those Weld containers might overwrite each other's values, so be careful what you configure to not get unexpected results. + * those Weld containers might overwrite each other's values, so be careful what you configure to not get unexpected + * results. * - *

The non-{@code @Shared} fields will also be injected, as well as method parameters of {@code setup}, + *

+ * The non-{@code @Shared} fields will also be injected, as well as method parameters of {@code setup}, * feature, and {@code cleanup} methods. * - *

{@code setupSpec} and {@code cleanupSpec} method parameters will not be injected as at the time those + *

+ * {@code setupSpec} and {@code cleanupSpec} method parameters will not be injected as at the time those * methods are executed, the Weld container is either not yet running or already shut down. */ ITERATION, /** - * Before a feature (before the {@code setup} method of the first iteration is called) a new Weld container will be started, + * Before a feature (before the {@code setup} method of the first iteration is called) a new Weld container will be + * started, * exclusively used for all iterations of this feature and after the feature (after the {@code cleanup} method of * the last iteration is called) shut down again. * - *

The {@link Shared @Shared} fields will be injected, but only at the time the first iteration starts running. + *

+ * The {@link Shared @Shared} fields will be injected, but only at the time the first iteration starts running. * If you have multiple such Weld instances in one specification and use the parallel execution feature of Spock, - * those Weld containers might overwrite each other's values, so be careful what you configure to not get unexpected results. + * those Weld containers might overwrite each other's values, so be careful what you configure to not get unexpected + * results. * - *

The non-{@code @Shared} fields will also be injected, as well as method parameters of {@code setup}, + *

+ * The non-{@code @Shared} fields will also be injected, as well as method parameters of {@code setup}, * feature, and {@code cleanup} methods. * - *

{@code setupSpec} and {@code cleanupSpec} method parameters will not be injected as at the time those + *

+ * {@code setupSpec} and {@code cleanupSpec} method parameters will not be injected as at the time those * methods are executed, the Weld container is either not yet running or already shut down. */ FEATURE, @@ -127,12 +142,15 @@ enum Scope { * exclusively used for all iterations of all features of this specification and after the specification * (after the {@code cleanupSpec} method is called) shut down again. * - *

The {@link Shared @Shared} fields will be injected once after the container was booted successfully. + *

+ * The {@link Shared @Shared} fields will be injected once after the container was booted successfully. * - *

The non-{@code @Shared} fields will also be injected, as well as method parameters of feature, + *

+ * The non-{@code @Shared} fields will also be injected, as well as method parameters of feature, * and all fixture methods. * - *

This scope can only be selected on a specification or in the Spock configuration file. If it is used + *

+ * This scope can only be selected on a specification or in the Spock configuration file. If it is used * for a feature annotation, an exception will be thrown. */ SPECIFICATION diff --git a/spock/src/main/java/org/jboss/weld/spock/WeldConfiguration.java b/spock/src/main/java/org/jboss/weld/spock/WeldConfiguration.java index 11313a19..75cd6f6b 100644 --- a/spock/src/main/java/org/jboss/weld/spock/WeldConfiguration.java +++ b/spock/src/main/java/org/jboss/weld/spock/WeldConfiguration.java @@ -17,16 +17,19 @@ package org.jboss.weld.spock; +import static org.jboss.weld.spock.EnableWeld.Scope.ITERATION; + import org.jboss.weld.spock.EnableWeld.Scope; import org.jboss.weld.spock.impl.EnableWeldExtension; -import spock.config.ConfigurationObject; -import static org.jboss.weld.spock.EnableWeld.Scope.ITERATION; +import spock.config.ConfigurationObject; /** * Configuration settings for the weld-spock extensions. * - *

Example: + *

+ * Example: + * *

{@code
  * import static org.jboss.weld.spock.EnableWeld.Scope.SPECIFICATION
  *
diff --git a/spock/src/main/java/org/jboss/weld/spock/WeldInitiator.java b/spock/src/main/java/org/jboss/weld/spock/WeldInitiator.java
index afbf4cfe..477f11ae 100644
--- a/spock/src/main/java/org/jboss/weld/spock/WeldInitiator.java
+++ b/spock/src/main/java/org/jboss/weld/spock/WeldInitiator.java
@@ -26,6 +26,7 @@
 import jakarta.enterprise.inject.spi.Bean;
 import jakarta.enterprise.inject.spi.Extension;
 import jakarta.enterprise.inject.spi.InjectionPoint;
+
 import org.jboss.weld.environment.se.Weld;
 import org.jboss.weld.environment.se.WeldContainer;
 import org.jboss.weld.junit.AbstractWeldInitiator;
@@ -34,7 +35,9 @@
  * Weld initiator - can be used to customize the Weld SE container started by
  * {@link org.jboss.weld.spock.impl.EnableWeldInterceptor}.
  *
- * 

Example: + *

+ * Example: + * *

  * @EnableWeld
  * public class SimpleTest extends Specification {
@@ -166,15 +169,20 @@ protected Builder self() {
         }
 
         @Override
-        protected WeldInitiator build(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans) {
-            return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, getEjbFactory(), getPersistenceUnitFactory(), getPersistenceContextFactory());
+        protected WeldInitiator build(Weld weld, List instancesToInject,
+                Set> scopesToActivate, Set> beans) {
+            return new WeldInitiator(weld, instancesToInject, scopesToActivate, beans, resources, getEjbFactory(),
+                    getPersistenceUnitFactory(), getPersistenceContextFactory());
         }
     }
 
-    private WeldInitiator(Weld weld, List instancesToInject, Set> scopesToActivate, Set> beans,
-                          Map resources, Function ejbFactory, Function persistenceUnitFactory,
-                          Function persistenceContextFactory) {
-        super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory, persistenceContextFactory);
+    private WeldInitiator(Weld weld, List instancesToInject, Set> scopesToActivate,
+            Set> beans,
+            Map resources, Function ejbFactory,
+            Function persistenceUnitFactory,
+            Function persistenceContextFactory) {
+        super(weld, instancesToInject, scopesToActivate, beans, resources, ejbFactory, persistenceUnitFactory,
+                persistenceContextFactory);
     }
 
     public void addObjectToInjectInto(Object instanceToInjectInto) {
diff --git a/spock/src/main/java/org/jboss/weld/spock/WeldSetup.java b/spock/src/main/java/org/jboss/weld/spock/WeldSetup.java
index 3420fcf0..186d026a 100644
--- a/spock/src/main/java/org/jboss/weld/spock/WeldSetup.java
+++ b/spock/src/main/java/org/jboss/weld/spock/WeldSetup.java
@@ -17,12 +17,12 @@
 
 package org.jboss.weld.spock;
 
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
 /**
  * An annotation used to denote a field holding a {@link WeldInitiator}. This is then picked up by
  * {@link org.jboss.weld.spock.impl.EnableWeldManualInterceptor} and used for configuration.
diff --git a/spock/src/main/java/org/jboss/weld/spock/WeldSpockEnricher.java b/spock/src/main/java/org/jboss/weld/spock/WeldSpockEnricher.java
index 1248a031..cf167812 100644
--- a/spock/src/main/java/org/jboss/weld/spock/WeldSpockEnricher.java
+++ b/spock/src/main/java/org/jboss/weld/spock/WeldSpockEnricher.java
@@ -18,14 +18,18 @@
 package org.jboss.weld.spock;
 
 import org.jboss.weld.environment.se.Weld;
+
 import spock.lang.Specification;
 
 /**
- * If no {@link WeldInitiator} field annotated with {@link WeldSetup} is present on a test class, or if the automagic mode is used,
+ * If no {@link WeldInitiator} field annotated with {@link WeldSetup} is present on a test class, or if the automagic mode is
+ * used,
  * all service providers of this interface are used to enrich the default test environment. The initial {@link Weld} instance is
  * created using {@link WeldInitiator#createWeld()}.
  *
- * 

A system property with key equal to FQCN of a customizer class may be used to disable an enricher completely. E.g. for a class + *

+ * A system property with key equal to FQCN of a customizer class may be used to disable an enricher completely. E.g. for a + * class * {@code org.weld.FooEnricher} use {@code -Dorg.weld.FooEnricher=false} to disable the enricher. * * @author Björn Kautler @@ -34,12 +38,13 @@ public interface WeldSpockEnricher { /** * Enrich the default test environment. * - *

{@link Weld#initialize()} and {@link WeldInitiator.Builder#build()} methods must never be invoked in an enricher! + *

+ * {@link Weld#initialize()} and {@link WeldInitiator.Builder#build()} methods must never be invoked in an enricher! * - * @param testInstance the test instance for which the enricher is called; this is {@code null} - * if the enricher is called from a {@code SPECIFICATION} scoped interceptor of from a - * {@code FEATURE} scoped interceptor of a data-driven feature - * @param weld the weld instance to be customized + * @param testInstance the test instance for which the enricher is called; this is {@code null} + * if the enricher is called from a {@code SPECIFICATION} scoped interceptor of from a + * {@code FEATURE} scoped interceptor of a data-driven feature + * @param weld the weld instance to be customized * @param weldInitiatorBuilder the weld initiator builder to be customized */ void enrich(Specification testInstance, Weld weld, WeldInitiator.Builder weldInitiatorBuilder); diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/ActivateScopes.java b/spock/src/main/java/org/jboss/weld/spock/auto/ActivateScopes.java index 63630021..ba2638c4 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/ActivateScopes.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/ActivateScopes.java @@ -17,15 +17,15 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Activates the listed scopes for the duration of the test. * diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/AddBeanClasses.java b/spock/src/main/java/org/jboss/weld/spock/auto/AddBeanClasses.java index 98f7c081..2a49163d 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/AddBeanClasses.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/AddBeanClasses.java @@ -17,14 +17,14 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Adds the listed classes as beans to the deployed testing container. * diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledDecorators.java b/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledDecorators.java index 939d5615..9b7bf630 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledDecorators.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledDecorators.java @@ -17,14 +17,14 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Adds, and enables, the listed classes as CDI decorators to the deployed testing container. * diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledInterceptors.java b/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledInterceptors.java index 32b1ab7c..85489f66 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledInterceptors.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/AddEnabledInterceptors.java @@ -17,14 +17,14 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Adds, and enables, the listed classes as CDI interceptors to the deployed testing container. * diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/AddExtensions.java b/spock/src/main/java/org/jboss/weld/spock/auto/AddExtensions.java index c4d9afef..ef08c314 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/AddExtensions.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/AddExtensions.java @@ -17,6 +17,9 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; @@ -24,9 +27,6 @@ import jakarta.enterprise.inject.spi.Extension; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Adds the listed classes as portable CDI extensions to the deployed testing container. * diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/AddPackages.java b/spock/src/main/java/org/jboss/weld/spock/auto/AddPackages.java index f50c7f9c..a1010366 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/AddPackages.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/AddPackages.java @@ -17,18 +17,19 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Adds all bean classes from the listed packages to the deployed testing container. * - *

Packages are selected by providing any bean class in the package. + *

+ * Packages are selected by providing any bean class in the package. * * @author Björn Kautler */ diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternativeStereotypes.java b/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternativeStereotypes.java index 9b9f0192..0800f75b 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternativeStereotypes.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternativeStereotypes.java @@ -17,15 +17,15 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Adds the listed annotations as alternative stereotypes to the deployed container. * diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternatives.java b/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternatives.java index cefdab4b..7a550325 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternatives.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/EnableAlternatives.java @@ -17,14 +17,14 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Inherited; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * Enables the listed classes as bean class alternatives in the deployed testing container. * diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBean.java b/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBean.java index a85709ec..77204197 100644 --- a/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBean.java +++ b/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBean.java @@ -17,29 +17,33 @@ package org.jboss.weld.spock.auto; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.Target; import jakarta.enterprise.inject.Produces; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - /** * {@code @ExcludeBean} excludes a bean, or multiple beans, that include a bean defining annotation * (e.g. scope) from automatic discovery. This can be helpful to allow replacing a bean class with a different * implementation, typically a mock or stub. * - *

The type of bean to exclude is implied by the annotated fields' type or annotated methods' return type. If the type + *

+ * The type of bean to exclude is implied by the annotated fields' type or annotated methods' return type. If the type * is a base class or interface all beans extending / implementing that type will be excluded. * - *

NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the + *

+ * NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the * implied type that are defined by {@link Produces} producer methods / fields or synthetic * beans. Also, current implementation excludes beans based on type, disregarding any qualifiers that are specified. * - *

Example: + *

+ * Example: + * *

  * @EnableWeld(automagic = true)
  * class TestSomeFoo extends Specification {
diff --git a/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBeanClasses.java b/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBeanClasses.java
index f7b2072a..cc638722 100644
--- a/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBeanClasses.java
+++ b/spock/src/main/java/org/jboss/weld/spock/auto/ExcludeBeanClasses.java
@@ -17,6 +17,9 @@
 
 package org.jboss.weld.spock.auto;
 
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Repeatable;
 import java.lang.annotation.Retention;
@@ -24,21 +27,22 @@
 
 import jakarta.enterprise.inject.Produces;
 
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
 /**
  * {@code @ExcludeBeanClasses} excludes a set of classes with bean defining annotations (e.g. scopes) from automatic
  * discovery. This can be helpful to allow replacing bean classes with a different implementation, typically a mock
  * or stub.
  *
- * 

This annotation works as an inverse of {@link AddBeanClasses} hence usually requires actual bean implementation + *

+ * This annotation works as an inverse of {@link AddBeanClasses} hence usually requires actual bean implementation * classes as parameters. * - *

NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the + *

+ * NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the * specified type that are defined by {@link Produces} producer methods / fields or synthetic beans. * - *

Example: + *

+ * Example: + * *

  * @EnableWeld(automagic = true)
  * @ExcludeBeanClasses(Foo)   // Excludes Foo bean class from automatic discovery
diff --git a/spock/src/main/java/org/jboss/weld/spock/impl/ClassScanning.java b/spock/src/main/java/org/jboss/weld/spock/impl/ClassScanning.java
index aa0da2ef..78355886 100644
--- a/spock/src/main/java/org/jboss/weld/spock/impl/ClassScanning.java
+++ b/spock/src/main/java/org/jboss/weld/spock/impl/ClassScanning.java
@@ -17,6 +17,18 @@
 
 package org.jboss.weld.spock.impl;
 
+import static java.util.Arrays.asList;
+import static java.util.Arrays.stream;
+import static org.junit.platform.commons.support.AnnotationSupport.findAnnotatedFields;
+import static org.junit.platform.commons.support.AnnotationSupport.findAnnotatedMethods;
+import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
+import static org.junit.platform.commons.support.HierarchyTraversalMode.BOTTOM_UP;
+import static org.junit.platform.commons.support.ReflectionSupport.findMethods;
+import static org.spockframework.util.Identifiers.CLEANUP_METHOD;
+import static org.spockframework.util.Identifiers.CLEANUP_SPEC_METHOD;
+import static org.spockframework.util.Identifiers.SETUP_METHOD;
+import static org.spockframework.util.Identifiers.SETUP_SPEC_METHOD;
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Executable;
@@ -44,6 +56,7 @@
 import jakarta.inject.Inject;
 import jakarta.inject.Qualifier;
 import jakarta.interceptor.Interceptor;
+
 import org.jboss.weld.environment.se.Weld;
 import org.jboss.weld.spock.auto.AddBeanClasses;
 import org.jboss.weld.spock.auto.AddEnabledDecorators;
@@ -59,18 +72,6 @@
 import org.junit.platform.commons.util.Preconditions;
 import org.spockframework.runtime.model.FeatureMetadata;
 
-import static java.util.Arrays.asList;
-import static java.util.Arrays.stream;
-import static org.junit.platform.commons.support.AnnotationSupport.findAnnotatedFields;
-import static org.junit.platform.commons.support.AnnotationSupport.findAnnotatedMethods;
-import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
-import static org.junit.platform.commons.support.HierarchyTraversalMode.BOTTOM_UP;
-import static org.junit.platform.commons.support.ReflectionSupport.findMethods;
-import static org.spockframework.util.Identifiers.CLEANUP_METHOD;
-import static org.spockframework.util.Identifiers.CLEANUP_SPEC_METHOD;
-import static org.spockframework.util.Identifiers.SETUP_METHOD;
-import static org.spockframework.util.Identifiers.SETUP_SPEC_METHOD;
-
 /**
  * Provides automagic bean class discovery for a test class instance.
  *
@@ -89,9 +90,9 @@ static void scanForRequiredBeanClasses(Class testClass, Weld weld, boolean ex
             Class currClass = classesToProcess.remove(0);
 
             if (foundClasses.contains(currClass) ||
-                excludedBeanTypes.contains(currClass) || excludedBeanClasses.contains(currClass) ||
-                currClass.isPrimitive() || currClass.isSynthetic() ||
-                currClass.getName().startsWith("java") || currClass.getName().startsWith("sun")) {
+                    excludedBeanTypes.contains(currClass) || excludedBeanClasses.contains(currClass) ||
+                    currClass.isPrimitive() || currClass.isSynthetic() ||
+                    currClass.getName().startsWith("java") || currClass.getName().startsWith("sun")) {
                 continue;
             }
 
@@ -123,12 +124,9 @@ static void scanForRequiredBeanClasses(Class testClass, Weld weld, boolean ex
                     .forEach(cls -> addClassesToProcess(classesToProcess, cls));
 
             findAnnotatedDeclaredMethods(currClass, Produces.class).stream()
-                    .flatMap(method ->
-                            Stream.concat(
-                                    getExecutableParameterTypes(method, explicitInjection).stream(),
-                                    Stream.of(method.getReturnType())
-                            )
-                    )
+                    .flatMap(method -> Stream.concat(
+                            getExecutableParameterTypes(method, explicitInjection).stream(),
+                            Stream.of(method.getReturnType())))
                     .forEach(cls -> addClassesToProcess(classesToProcess, cls));
 
             findAnnotatedMethods(currClass, FeatureMetadata.class, BOTTOM_UP).stream()
@@ -152,10 +150,9 @@ static void scanForRequiredBeanClasses(Class testClass, Weld weld, boolean ex
                     .forEach(cls -> addClassesToProcess(classesToProcess, cls));
 
             AnnotationSupport.findRepeatableAnnotations(currClass, AddPackages.class)
-                    .forEach(ann ->
-                            stream(ann.value())
-                                    .distinct()
-                                    .forEach(cls -> weld.addPackage(ann.recursively(), cls)));
+                    .forEach(ann -> stream(ann.value())
+                            .distinct()
+                            .forEach(cls -> weld.addPackage(ann.recursively(), cls)));
 
             AnnotationSupport.findRepeatableAnnotations(currClass, AddBeanClasses.class).stream()
                     .flatMap(ann -> stream(ann.value()))
@@ -260,14 +257,13 @@ private static boolean isBeanParameterAnnotation(Annotation ann) {
 
     private static boolean hasBeanDefiningAnnotation(Class clazz) {
         return isAnnotated(clazz, NormalScope.class) || isAnnotated(clazz, Dependent.class) ||
-               isAnnotated(clazz, Interceptor.class) || isAnnotated(clazz, Decorator.class) ||
-               isAnnotated(clazz, Stereotype.class);
+                isAnnotated(clazz, Interceptor.class) || isAnnotated(clazz, Decorator.class) ||
+                isAnnotated(clazz, Stereotype.class);
     }
 
     private static List findAllFieldsInHierarchy(Class clazz) {
         Preconditions.notNull(clazz, "Class must not be null");
-        List localFields = getDeclaredFields(clazz).stream().
-                filter((field) -> !field.isSynthetic())
+        List localFields = getDeclaredFields(clazz).stream().filter((field) -> !field.isSynthetic())
                 .collect(Collectors.toList());
         List superclassFields = getSuperclassFields(clazz).stream()
                 .filter((field) -> !isMethodShadowedByLocalFields(field, localFields))
@@ -281,7 +277,8 @@ private static List findAllFieldsInHierarchy(Class clazz) {
 
     private static List getSuperclassFields(Class clazz) {
         Class superclass = clazz.getSuperclass();
-        return superclass != null && superclass != Object.class ? findAllFieldsInHierarchy(superclass) : Collections.emptyList();
+        return superclass != null && superclass != Object.class ? findAllFieldsInHierarchy(superclass)
+                : Collections.emptyList();
     }
 
     private static List getDeclaredFields(Class clazz) {
@@ -317,7 +314,8 @@ private static List> getDeclaredConstructors(Class clazz) {
         return asList(clazz.getDeclaredConstructors());
     }
 
-    private static Optional> findFirstAnnotatedConstructor(Class clazz, Class annotationType) {
+    private static Optional> findFirstAnnotatedConstructor(Class clazz,
+            Class annotationType) {
         Optional> found = getDeclaredConstructors(clazz).stream()
                 .filter((cons) -> isAnnotated(cons, annotationType))
                 .findFirst();
diff --git a/spock/src/main/java/org/jboss/weld/spock/impl/EagerExceptionRenderer.java b/spock/src/main/java/org/jboss/weld/spock/impl/EagerExceptionRenderer.java
index 75a90def..9308bce3 100644
--- a/spock/src/main/java/org/jboss/weld/spock/impl/EagerExceptionRenderer.java
+++ b/spock/src/main/java/org/jboss/weld/spock/impl/EagerExceptionRenderer.java
@@ -29,7 +29,8 @@
  * A global Spock extension that eagerly renders exceptions, otherwise {@code toString()} might be called
  * on a CDI proxy when the container is shut down already and the call cannot be done.
  *
- * 

If in a power assertion output you see something like + *

+ * If in a power assertion output you see something like * {@code Something$Proxy$_$$_WeldClientProxy@4303056f (renderer threw IllegalStateException)}, * this extension might miss some places where to eagerly render the exception, and you should * open an issue with a reproducer. @@ -43,14 +44,13 @@ public void visitSpec(SpecInfo spec) { .concat( StreamSupport.stream(spec.getAllFixtureMethods().spliterator(), false), spec.getAllFeatures().stream().map(FeatureInfo::getFeatureMethod)) - .forEach(method -> - method.addInterceptor(invocation -> { - try { - invocation.proceed(); - } catch (SpockAssertionError spockAssertionError) { - spockAssertionError.toString(); - throw spockAssertionError; - } - })); + .forEach(method -> method.addInterceptor(invocation -> { + try { + invocation.proceed(); + } catch (SpockAssertionError spockAssertionError) { + spockAssertionError.toString(); + throw spockAssertionError; + } + })); } } diff --git a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldAutoInterceptor.java b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldAutoInterceptor.java index 02816f91..cde486e1 100644 --- a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldAutoInterceptor.java +++ b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldAutoInterceptor.java @@ -17,6 +17,11 @@ package org.jboss.weld.spock.impl; +import static java.lang.String.format; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static org.jboss.weld.spock.impl.ClassScanning.scanForRequiredBeanClasses; + import java.util.Arrays; import java.util.List; @@ -39,25 +44,24 @@ import org.spockframework.runtime.extension.IMethodInvocation; import org.spockframework.runtime.model.FieldInfo; import org.spockframework.runtime.model.SpecInfo; -import spock.lang.Specification; -import static java.lang.String.format; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; -import static org.jboss.weld.spock.impl.ClassScanning.scanForRequiredBeanClasses; +import spock.lang.Specification; /** * An alternative to {@link EnableWeldManualInterceptor} allowing to fully leverage an annotation based configuration approach. * When selected by {@link EnableWeld#automagic()}, this interceptor will attempt to resolve all beans used in the test class * and automatically adds them to the Weld container while bootstrapping it. * - *

There are quite some annotations which can be used on the test class and on any discovered bean to configure it further. + *

+ * There are quite some annotations which can be used on the test class and on any discovered bean to configure it further. * - *

Having a {@link WeldSetup @WeldSetup} annotated field in the specification or a super specification results in an + *

+ * Having a {@link WeldSetup @WeldSetup} annotated field in the specification or a super specification results in an * exception, because it would not be considered and thus is a sign that the manual interceptor should be used, or that * the field is a left-over from switching and should be removed. * - *

Furthermore, all discovered {@link WeldSpockEnricher}s are invoked after the annotations are processed. + *

+ * Furthermore, all discovered {@link WeldSpockEnricher}s are invoked after the annotations are processed. * * @author Björn Kautler * @see ActivateScopes @@ -95,8 +99,11 @@ protected WeldInitiator weldInit(IMethodInvocation invocation) { if (weldSetupFields.size() > 0) { throw new InvalidSpecException(weldSetupFields .stream() - .map(f -> format("Field '%s' with type %s which is in %s", f.getName(), f.getType(), f.getParent().getDisplayName())) - .collect(joining("\n", "When using automagic mode, no @WeldSetup annotated field should be present! Fields found:\n", ""))); + .map(f -> format("Field '%s' with type %s which is in %s", f.getName(), f.getType(), + f.getParent().getDisplayName())) + .collect(joining("\n", + "When using automagic mode, no @WeldSetup annotated field should be present! Fields found:\n", + ""))); } Weld weld = WeldInitiator.createWeld(); diff --git a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldExtension.java b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldExtension.java index 26d8987b..0fd3eee4 100644 --- a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldExtension.java +++ b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldExtension.java @@ -17,6 +17,10 @@ package org.jboss.weld.spock.impl; +import static org.jboss.weld.spock.EnableWeld.Scope.FEATURE; +import static org.jboss.weld.spock.EnableWeld.Scope.ITERATION; +import static org.jboss.weld.spock.EnableWeld.Scope.SPECIFICATION; + import java.util.List; import java.util.Optional; import java.util.ServiceLoader; @@ -33,33 +37,35 @@ import org.spockframework.runtime.model.FeatureInfo; import org.spockframework.runtime.model.MethodInfo; import org.spockframework.runtime.model.SpecInfo; -import spock.lang.Shared; -import static org.jboss.weld.spock.EnableWeld.Scope.FEATURE; -import static org.jboss.weld.spock.EnableWeld.Scope.ITERATION; -import static org.jboss.weld.spock.EnableWeld.Scope.SPECIFICATION; +import spock.lang.Shared; /** * A global Spock extension evaluating the {@link EnableWeld @EnableWeld}, and {@link DisableWeld @DisableWeld} annotations, * and the Spock configuration file options. * - *

If a feature has an {@code @EnableWeld} or {@code @DisableWeld} annotation applied, this is what is effective. + *

+ * If a feature has an {@code @EnableWeld} or {@code @DisableWeld} annotation applied, this is what is effective. * If Weld is disabled, no container will be started for the feature or the iterations and no non-{@link Shared @Shared} * fields, or method parameters will be injected. However, if a for the specification a {@code SPECIFICATION} scoped * Weld was booted due to annotation or configuration file options, this container will have injected instances into * the {@code @Shared} fields already. * - *

If a feature has neither of the two annotations applied, the configuration of the specification is inherited. + *

+ * If a feature has neither of the two annotations applied, the configuration of the specification is inherited. * - *

If a specification has an {@code @EnableWeld} or {@code @DisableWeld} annotation applied, this is effective for + *

+ * If a specification has an {@code @EnableWeld} or {@code @DisableWeld} annotation applied, this is effective for * all features that do not have an own annotation. It will have the same effect as if the annotation is copied to all * features that have none of the two annotations already, except if scope {@code SPECIFICATION} is selected, as this * is only valid in a specification level annotation or the Spock configuration file. * - *

If a specification has neither of the two annotations applied, the super specifications are searched in order + *

+ * If a specification has neither of the two annotations applied, the super specifications are searched in order * and if an annotated one is found, its annotation is effective as if it were on the specification directly. * - *

If also no super specification has any of the annotations, the settings from the Spock configuration file + *

+ * If also no super specification has any of the annotations, the settings from the Spock configuration file * or the respective default settings are effective. * * @author Björn Kautler @@ -87,7 +93,8 @@ public void visitSpec(SpecInfo spec) { Optional optionalAnnotatedSpec = spec .getSpecsBottomToTop() .stream() - .filter(specInfo -> specInfo.isAnnotationPresent(EnableWeld.class) || specInfo.isAnnotationPresent(DisableWeld.class)) + .filter(specInfo -> specInfo.isAnnotationPresent(EnableWeld.class) + || specInfo.isAnnotationPresent(DisableWeld.class)) .findFirst(); boolean doEnableWeldForSpec; @@ -101,7 +108,8 @@ public void visitSpec(SpecInfo spec) { boolean disableWeldForSpec = annotatedSpec.isAnnotationPresent(DisableWeld.class); if (enableWeldForSpec && disableWeldForSpec) { - throw new InvalidSpecException("@EnableWeld and @DisableWeld must not be used on the same spec: " + annotatedSpec.getDisplayName()); + throw new InvalidSpecException( + "@EnableWeld and @DisableWeld must not be used on the same spec: " + annotatedSpec.getDisplayName()); } if (enableWeldForSpec) { @@ -126,8 +134,8 @@ public void visitSpec(SpecInfo spec) { EnableWeldInterceptor enableWeldInterceptorForSpec; if (doEnableWeldForSpec && (specScope == SPECIFICATION)) { enableWeldInterceptorForSpec = specAutomagic - ? new EnableWeldAutoInterceptor(weldSpockEnrichers, specExplicitParamInjection) - : new EnableWeldManualInterceptor(weldSpockEnrichers); + ? new EnableWeldAutoInterceptor(weldSpockEnrichers, specExplicitParamInjection) + : new EnableWeldManualInterceptor(weldSpockEnrichers); spec.addInterceptor(enableWeldInterceptorForSpec); // inject parameters for specification fixture methods @@ -135,7 +143,8 @@ public void visitSpec(SpecInfo spec) { .concat( spec.getSetupSpecMethods().stream(), spec.getCleanupSpecMethods().stream()) - .forEach(method -> attachParameterInjector(method, enableWeldInterceptorForSpec, specExplicitParamInjection)); + .forEach(method -> attachParameterInjector(method, enableWeldInterceptorForSpec, + specExplicitParamInjection)); } else { enableWeldInterceptorForSpec = null; } @@ -147,14 +156,15 @@ public void visitSpec(SpecInfo spec) { } private void visitFeature(FeatureInfo feature, boolean doEnableWeldForSpec, boolean specAutomagic, Scope specScope, - boolean specExplicitParamInjection, EnableWeldInterceptor enableWeldInterceptorForSpec) { + boolean specExplicitParamInjection, EnableWeldInterceptor enableWeldInterceptorForSpec) { MethodInfo featureMethod = feature.getFeatureMethod(); EnableWeld enableWeld = featureMethod.getAnnotation(EnableWeld.class); boolean enableWeldForFeature = enableWeld != null; boolean disableWeldForFeature = featureMethod.isAnnotationPresent(DisableWeld.class); if (enableWeldForFeature && disableWeldForFeature) { - throw new InvalidSpecException("@EnableWeld and @DisableWeld must not be used on the same feature: " + feature.getDisplayName()); + throw new InvalidSpecException( + "@EnableWeld and @DisableWeld must not be used on the same feature: " + feature.getDisplayName()); } boolean doEnableWeldForFeature; @@ -166,7 +176,8 @@ private void visitFeature(FeatureInfo feature, boolean doEnableWeldForSpec, bool featureAutomagic = enableWeld.automagic(); featureScope = enableWeld.scope(); if (featureScope.compareTo(FEATURE) > 0) { - throw new InvalidSpecException("@EnableWeld on feature cannot have broader scope than FEATURE on feature: " + feature.getDisplayName()); + throw new InvalidSpecException("@EnableWeld on feature cannot have broader scope than FEATURE on feature: " + + feature.getDisplayName()); } featureExplicitParamInjection = enableWeld.explicitParamInjection(); } else if (disableWeldForFeature) { @@ -193,16 +204,16 @@ private void visitFeature(FeatureInfo feature, boolean doEnableWeldForSpec, bool case FEATURE: enableWeldInterceptorForFeature = featureAutomagic - ? new EnableWeldAutoInterceptor(weldSpockEnrichers, featureExplicitParamInjection) - : new EnableWeldManualInterceptor(weldSpockEnrichers); + ? new EnableWeldAutoInterceptor(weldSpockEnrichers, featureExplicitParamInjection) + : new EnableWeldManualInterceptor(weldSpockEnrichers); enableWeldInterceptorForFeature.handleFeature(feature); feature.addInterceptor(enableWeldInterceptorForFeature); break; case ITERATION: enableWeldInterceptorForFeature = featureAutomagic - ? new EnableWeldAutoInterceptor(weldSpockEnrichers, featureExplicitParamInjection) - : new EnableWeldManualInterceptor(weldSpockEnrichers); + ? new EnableWeldAutoInterceptor(weldSpockEnrichers, featureExplicitParamInjection) + : new EnableWeldManualInterceptor(weldSpockEnrichers); enableWeldInterceptorForFeature.handleFeature(feature); feature.addIterationInterceptor(enableWeldInterceptorForFeature); break; @@ -221,11 +232,13 @@ private void visitFeature(FeatureInfo feature, boolean doEnableWeldForSpec, bool feature.getSpec().getCleanupMethods().forEach(streamBuilder); streamBuilder .build() - .forEach(method -> attachParameterInjector(method, enableWeldInterceptorForFeature, featureExplicitParamInjection)); + .forEach(method -> attachParameterInjector(method, enableWeldInterceptorForFeature, + featureExplicitParamInjection)); } } - private void attachParameterInjector(MethodInfo method, EnableWeldInterceptor enableWeldInterceptor, boolean explicitParamInjection) { + private void attachParameterInjector(MethodInfo method, EnableWeldInterceptor enableWeldInterceptor, + boolean explicitParamInjection) { int amountOfParameters = method.getReflection().getParameters().length; int amountOfDataVariables = method.getFeature() == null ? 0 : method.getFeature().getDataVariables().size(); // only attach if there could be injectable arguments diff --git a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldInterceptor.java b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldInterceptor.java index 3b343bda..7179c41d 100644 --- a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldInterceptor.java +++ b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldInterceptor.java @@ -17,6 +17,10 @@ package org.jboss.weld.spock.impl; +import static java.util.Collections.synchronizedMap; +import static java.util.stream.Collectors.toList; +import static org.spockframework.runtime.model.MethodInfo.MISSING_ARGUMENT; + import java.lang.annotation.Annotation; import java.lang.reflect.Parameter; import java.util.Arrays; @@ -26,6 +30,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import jakarta.enterprise.inject.spi.BeanManager; + import org.jboss.weld.inject.WeldInstance; import org.jboss.weld.spock.WeldInitiator; import org.jboss.weld.spock.WeldSpockEnricher; @@ -33,11 +38,6 @@ import org.spockframework.runtime.extension.IMethodInvocation; import org.spockframework.runtime.model.FeatureInfo; -import static java.util.Collections.singleton; -import static java.util.Collections.synchronizedMap; -import static java.util.stream.Collectors.toList; -import static org.spockframework.runtime.model.MethodInfo.MISSING_ARGUMENT; - /** * A Spock interceptor, that serves as base for the manual and automatic interceptors and has the common logic. * It first calls the custom logic of the subclass, then adds the shared instance as injection target, initializes diff --git a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldManualInterceptor.java b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldManualInterceptor.java index e961a39c..82d0fdd2 100644 --- a/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldManualInterceptor.java +++ b/spock/src/main/java/org/jboss/weld/spock/impl/EnableWeldManualInterceptor.java @@ -17,6 +17,10 @@ package org.jboss.weld.spock.impl; +import static java.lang.String.format; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; + import java.util.List; import org.jboss.weld.environment.se.Weld; @@ -27,27 +31,29 @@ import org.spockframework.runtime.InvalidSpecException; import org.spockframework.runtime.extension.IMethodInvocation; import org.spockframework.runtime.model.FieldInfo; + import spock.lang.Shared; import spock.lang.Specification; -import static java.lang.String.format; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; - /** * A Spock interceptor that is used for manual configuration of the booted Weld container. * - *

If the interceptor is for scope {@code SPECIFICATION}, or for a data-driven feature with scope {@code FEATURE}, + *

+ * If the interceptor is for scope {@code SPECIFICATION}, or for a data-driven feature with scope {@code FEATURE}, * {@link Shared @Shared} fields of the specification and its super specifications are searched for exactly one * field that is annotated with {@link WeldSetup @WeldSetup}. * - *

If multiple such fields are found, an exception is thrown. + *

+ * If multiple such fields are found, an exception is thrown. * - *

If exactly one is found, and its value is not of type {@link WeldInitiator}, an exception is thrown. + *

+ * If exactly one is found, and its value is not of type {@link WeldInitiator}, an exception is thrown. * - *

Otherwise, as the type is correct, it is used as-is to initialize the Weld container. + *

+ * Otherwise, as the type is correct, it is used as-is to initialize the Weld container. * - *

If no field with that annotation is found, a new Weld initiator is created and the package of the test + *

+ * If no field with that annotation is found, a new Weld initiator is created and the package of the test * class is added as beans to the container. Then all discovered {@link WeldSpockEnricher}s are applied to that instance * and the result is used to initialize the Weld container. * @@ -96,8 +102,8 @@ protected WeldInitiator weldInit(IMethodInvocation invocation) { if (!(weldSetupCandidate instanceof WeldInitiator)) { throw new InvalidSpecException(format( "@WeldSetup annotation should only be used on a field with a " - + "WeldInitiator value but was found on field %s with a " - + "%s value which is declared in %s", + + "WeldInitiator value but was found on field %s with a " + + "%s value which is declared in %s", weldSetupField.getName(), ((weldSetupCandidate == null) ? "null" : weldSetupCandidate.getClass()), weldSetupField.getParent().getDisplayName())); @@ -107,8 +113,10 @@ protected WeldInitiator weldInit(IMethodInvocation invocation) { default: throw new InvalidSpecException(weldSetupFields .stream() - .map(f -> format("Field '%s' with type %s which is in %s", f.getName(), f.getType(), f.getParent().getDisplayName())) - .collect(joining("\n", "Multiple @WeldSetup annotated fields found, only one is allowed! Fields found:\n", ""))); + .map(f -> format("Field '%s' with type %s which is in %s", f.getName(), f.getType(), + f.getParent().getDisplayName())) + .collect(joining("\n", + "Multiple @WeldSetup annotated fields found, only one is allowed! Fields found:\n", ""))); } } } diff --git a/spock/src/main/java/org/jboss/weld/spock/impl/TestInstanceInjectionExtension.java b/spock/src/main/java/org/jboss/weld/spock/impl/TestInstanceInjectionExtension.java index 3d4e3b3d..dfe5a893 100644 --- a/spock/src/main/java/org/jboss/weld/spock/impl/TestInstanceInjectionExtension.java +++ b/spock/src/main/java/org/jboss/weld/spock/impl/TestInstanceInjectionExtension.java @@ -25,6 +25,7 @@ import jakarta.enterprise.inject.spi.ProcessInjectionTarget; import jakarta.enterprise.util.AnnotationLiteral; import jakarta.inject.Singleton; + import org.jboss.weld.injection.ForwardingInjectionTarget; /** From f2c6f3d0d167296ec2c6d29c6a0c5f5b60a88325 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Wed, 1 Nov 2023 10:31:33 +0100 Subject: [PATCH 2/4] Update Weld version to 5.1.2.Final --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5e31da19..994b7e2b 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ 2.1-groovy-3.0 1.8.2 3.0.10 - 5.0.0.SP1 + 5.1.2.Final 4.4.0 4.0.1 2.0.1 From b05c7939c6e25a6a117690f0599c6cb84fa2891c Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Wed, 1 Nov 2023 10:34:10 +0100 Subject: [PATCH 3/4] Update JUnit Jupiter version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 994b7e2b..a4852198 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 11 4.13.2 - 5.8.2 + 5.10.0 2.1-groovy-3.0 1.8.2 3.0.10 From 7b4ab3629d5e5cd2a54fc979b126ec7f5481b651 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Wed, 1 Nov 2023 10:36:58 +0100 Subject: [PATCH 4/4] Update CI actions --- .github/workflows/ci-actions.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-actions.yml b/.github/workflows/ci-actions.yml index 96a5913c..3b205653 100644 --- a/.github/workflows/ci-actions.yml +++ b/.github/workflows/ci-actions.yml @@ -20,11 +20,12 @@ jobs: java-version: 17, } steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK @{} - uses: actions/setup-java@v1.4.3 + uses: actions/setup-java@v3.12.0 with: java-version: ${{ matrix.java.java-version }} + distribution: 'temurin' - name: Get Date id: get-date run: | @@ -32,14 +33,14 @@ jobs: shell: bash - name: Cache Maven Repository id: cache-maven - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.m2/repository # Caching is an automated pre/post action that installs the cache if the key exists and exports the cache # after the job is done. In this case we refresh the cache monthly (by changing key) to avoid unlimited growth. key: q2maven-master-${{ steps.get-date.outputs.date }} - name: Build with Maven - run: WELD_JUNIT_DEBUG=spotbugs mvn clean install -Dspotbugs.failOnError=true + run: WELD_JUNIT_DEBUG=spotbugs mvn clean install -Dno-format -Dspotbugs.failOnError=true - name: Delete Local Artifacts From Cache shell: bash run: rm -r ~/.m2/repository/org/jboss/weld/weld-junit* @@ -48,7 +49,7 @@ jobs: shell: bash run: find . -name '*-reports' -type d | tar -czf test-reports.tgz -T - - name: Upload failure Archive (if maven failed) - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 if: failure() with: name: test-reports-jdk${{matrix.java.name}}