Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various changes to observer methods to align them with spec expectations #30950

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ Collection<Resource> generate(ObserverInfo observer) {

implementGetBeanClass(observerCreator, observer.getBeanClass());
implementNotify(observer, observerCreator, injectionPointToProviderField, reflectionRegistration, isApplicationClass);
if (Reception.IF_EXISTS == observer.getReception()) {
implementIfExistsGetReception(observerCreator);
}
if (observer.getPriority() != ObserverMethod.DEFAULT_PRIORITY) {
implementGetPriority(observerCreator, observer);
}
Expand Down Expand Up @@ -258,6 +261,12 @@ protected void initMaps(ObserverInfo observer, Map<InjectionPointInfo, String> i
}
}

protected void implementIfExistsGetReception(ClassCreator observerCreator) {
MethodCreator getReception = observerCreator.getMethodCreator("getReception", Reception.class)
.setModifiers(ACC_PUBLIC);
getReception.returnValue(getReception.load(Reception.IF_EXISTS));
}

protected void implementGetObservedType(ClassCreator observerCreator, FieldDescriptor observedTypeField) {
MethodCreator getObservedType = observerCreator.getMethodCreator("getObservedType", Type.class)
.setModifiers(ACC_PUBLIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

import jakarta.annotation.Priority;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.event.Reception;
import jakarta.enterprise.inject.spi.ObserverMethod;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -50,6 +52,17 @@ public void testObserver() {
assertEquals(RequestScopedObserver.class.getName() + "foo", EVENTS.get(0));
assertEquals(DependentObserver.class.getName() + "foo", EVENTS.get(1));
container.requestContext().deactivate();

// TODO check reception metadata
Ladicek marked this conversation as resolved.
Show resolved Hide resolved
Set<ObserverMethod<? super String>> foundOm = Arc.container().beanManager().resolveObserverMethods("eventString");
assertEquals(2, foundOm.size());
for (ObserverMethod<? super String> om : foundOm) {
if (om.getDeclaringBean().getBeanClass().equals(RequestScopedObserver.class)) {
assertEquals(Reception.IF_EXISTS, om.getReception());
} else {
assertEquals(Reception.ALWAYS, om.getReception());
}
}
}

@RequestScoped
Expand Down