Skip to content

Commit

Permalink
Merge pull request #24271 from manovotn/removeCdiDeprecatedCalls
Browse files Browse the repository at this point in the history
Remove @OverRide annotations from to-be-removed API methods and replace BM#fireEvent calls
  • Loading branch information
gsmet authored Mar 13, 2022
2 parents b46fdbb + 89e383a commit 7e76a47
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void execute(BuildContext context) {
@Test
public void testSyntheticObserver() {
MyObserver.EVENTS.clear();
Arc.container().beanManager().fireEvent("foo");
Arc.container().beanManager().getEvent().fire("foo");
assertEquals(2, MyObserver.EVENTS.size(), "Events: " + MyObserver.EVENTS);
assertTrue(MyObserver.EVENTS.contains("synthetic"));
assertTrue(MyObserver.EVENTS.contains("foo_MyObserver"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ default Set<InjectionPoint> getInjectionPoints() {
return Collections.emptySet();
}

@Override
// Deprecated method which can be safely removed once we use CDI 4.0+
@Deprecated
default boolean isNullable() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public void validate(InjectionPoint injectionPoint) {
throw new UnsupportedOperationException();
}

@Override
// Deprecated method which can be safely removed once we use CDI 4.0+
@Deprecated
public void fireEvent(Object event, Annotation... qualifiers) {
Set<Annotation> eventQualifiers = new HashSet<>();
Collections.addAll(eventQualifiers, qualifiers);
Expand Down Expand Up @@ -235,7 +236,8 @@ public <T> AnnotatedType<T> createAnnotatedType(Class<T> type) {
throw new UnsupportedOperationException();
}

@Override
// Deprecated method which can be safely removed once we use CDI 4.0+
@Deprecated
public <T> InjectionTarget<T> createInjectionTarget(AnnotatedType<T> type) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public void register(RegistrationContext context) {
@Test
public void testSyntheticObserver() {
MyObserver.EVENTS.clear();
Arc.container().beanManager().fireEvent("foo");
Arc.container().beanManager().getEvent().fire("foo");
assertEquals(2, MyObserver.EVENTS.size(), "Events: " + MyObserver.EVENTS);
assertTrue(MyObserver.EVENTS.contains("foo"));
assertTrue(MyObserver.EVENTS.contains("foo_MyObserver"));

MyObserver.EVENTS.clear();
Arc.container().beanManager().fireEvent("foo", NamedLiteral.of("bla"));
Arc.container().beanManager().getEvent().select(String.class, NamedLiteral.of("bla")).fire("foo");
assertEquals(3, MyObserver.EVENTS.size(), "Events: " + MyObserver.EVENTS);
assertTrue(MyObserver.EVENTS.contains("foo"));
assertTrue(MyObserver.EVENTS.contains("foo_MyObserver"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class ReceptionIfExistsTest {
@Test
public void testObserver() {
ArcContainer container = Arc.container();
container.beanManager().fireEvent("foo");
container.beanManager().getEvent().fire("foo");
assertEquals(1, EVENTS.size());
assertEquals(DependentObserver.class.getName() + "foo", EVENTS.get(0));

// Activate the request context but the instance still does not exist
EVENTS.clear();
container.requestContext().activate();
container.beanManager().fireEvent("foo");
container.beanManager().getEvent().fire("foo");
assertEquals(1, EVENTS.size());
assertEquals(DependentObserver.class.getName() + "foo", EVENTS.get(0));
container.requestContext().deactivate();
Expand All @@ -42,7 +42,7 @@ public void testObserver() {
container.requestContext().activate();
// Force bean instance creation
container.instance(RequestScopedObserver.class).get().ping();
container.beanManager().fireEvent("foo");
container.beanManager().getEvent().fire("foo");
assertEquals(2, EVENTS.size());
assertEquals(RequestScopedObserver.class.getName() + "foo", EVENTS.get(0));
assertEquals(DependentObserver.class.getName() + "foo", EVENTS.get(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.enterprise.context.Dependent;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Instance;
import javax.enterprise.util.TypeLiteral;
import javax.inject.Singleton;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -27,12 +28,14 @@ public class SimpleObserverInjectionTest {
public void testObserverInjection() {
AtomicReference<String> msg = new AtomicReference<String>();
Fool.DESTROYED.set(false);
Arc.container().beanManager().fireEvent(msg);
Arc.container().beanManager().getEvent().select(new TypeLiteral<AtomicReference<String>>() {
}).fire(msg);
String id1 = msg.get();
assertNotNull(id1);
assertTrue(Fool.DESTROYED.get());
Fool.DESTROYED.set(false);
Arc.container().beanManager().fireEvent(msg);
Arc.container().beanManager().getEvent().select(new TypeLiteral<AtomicReference<String>>() {
}).fire(msg);
assertNotEquals(id1, msg.get());
assertTrue(Fool.DESTROYED.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ObserverNotificationTest {
public void testContextualInstanceIsUsed() {
assertEquals(0, StringObserver.CONSTRUCTED.get());
assertEquals(0, StringObserver.NOTIFIED.get());
Arc.container().beanManager().fireEvent("hello");
Arc.container().beanManager().getEvent().fire("hello");
assertEquals(1, StringObserver.CONSTRUCTED.get());
assertEquals(1, StringObserver.NOTIFIED.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class StaticObserverTest {
public void testObserver() {
assertEquals(0, StringObserver.EVENTS.size());
assertFalse(Fool.DESTROYED.get());
Arc.container().beanManager().fireEvent("hello");
Arc.container().beanManager().getEvent().fire("hello");
assertEquals(1, StringObserver.EVENTS.size());
assertEquals("hello", StringObserver.EVENTS.get(0));
assertTrue(Fool.DESTROYED.get());
Expand Down

0 comments on commit 7e76a47

Please sign in to comment.