Skip to content

Commit 7771254

Browse files
committed
GH-1448 - Polish deprecations in PublishedEvents.
Unfortunately, using the same overload for matching(Function, S) and matching(Function, Predicate<S>) doesn't work. Thus, the deprecation of matchingMapped(…) is broken as the suggested new method causes compiler errors on the command line (interestingly, they work in Eclipse). We now introduce a method matchingValue(Function, S) as a specialized version of matching(Function, Predicate<S>) as it's performing a static equality check.
1 parent e442c3b commit 7771254

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

spring-modulith-test/src/main/java/org/springframework/modulith/test/DefaultPublishedEvents.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ public <S> TypedPublishedEvents<T> matching(Function<T, S> mapper, @Nullable S v
150150
return matching(mapper, (Predicate<S>) it -> Objects.equals(it, value));
151151
}
152152

153+
/*
154+
* (non-Javadoc)
155+
* @see org.springframework.modulith.test.PublishedEvents.TypedPublishedEvents#matchingValue(java.util.function.Function, java.lang.Object)
156+
*/
157+
@Override
158+
public <S> TypedPublishedEvents<T> matchingValue(Function<T, S> mapper, @Nullable S value) {
159+
return matching(mapper, (Predicate<S>) it -> Objects.equals(it, value));
160+
}
161+
153162
/**
154163
* Returns a {@link Stream} of events filtered by the given {@link Predicate}.
155164
*

spring-modulith-test/src/main/java/org/springframework/modulith/test/PublishedEvents.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,23 @@ default <S extends T> TypedPublishedEvents<S> ofSubType(Class<S> subType) {
112112
* must not be {@literal null}.
113113
* @param value the value expected as outcome of the mapping step, can be {@literal null}.
114114
* @return will never be {@literal null}.
115+
* @deprecated use {@link #matchingValue(Function, Object)} instead.
115116
*/
117+
@Deprecated(since = "2.0", forRemoval = true)
116118
<S> TypedPublishedEvents<T> matching(Function<T, S> mapper, @Nullable S value);
117119

120+
/**
121+
* Returns all {@link TypedPublishedEvents} that match the given value after applying the given mapping step.
122+
*
123+
* @param <S> the intermediate type to apply the {@link Predicate} on
124+
* @param mapper the mapping step to extract a part of the original event subject to verify against the given value,
125+
* must not be {@literal null}.
126+
* @param value the value expected as outcome of the mapping step, can be {@literal null}.
127+
* @return will never be {@literal null}.
128+
* @since 2.0
129+
*/
130+
<S> TypedPublishedEvents<T> matchingValue(Function<T, S> mapper, @Nullable S value);
131+
118132
/**
119133
* Returns all {@link TypedPublishedEvents} that match the given predicate after applying the given mapping step.
120134
*

0 commit comments

Comments
 (0)