Skip to content

Commit 34ce0ad

Browse files
committed
GH-919 - Add @CheckReturnValue and use it in Scenario API.
1 parent 7320b3b commit 34ce0ad

File tree

2 files changed

+45
-0
lines changed
  • spring-modulith-core/src/main/java/org/springframework/modulith/core/util
  • spring-modulith-test/src/main/java/org/springframework/modulith/test

2 files changed

+45
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.modulith.core.util;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* Findbugs and IDEA handle any annotation with name "CheckReturnValue" in return value check.
25+
*
26+
* @see <a href=
27+
* "https://github.com/findbugsproject/findbugs/blob/264ae7baf890d2b347d91805c90057062b5dcb1e/findbugs/src/java/edu/umd/cs/findbugs/detect/BuildCheckReturnAnnotationDatabase.java#L120">Findbugs
28+
* source code</a>
29+
* @since 1.3
30+
*/
31+
@Target({
32+
ElementType.CONSTRUCTOR,
33+
ElementType.METHOD,
34+
ElementType.PACKAGE,
35+
ElementType.TYPE,
36+
})
37+
@Retention(RetentionPolicy.CLASS)
38+
public @interface CheckReturnValue {}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.awaitility.core.ConditionFactory;
3232
import org.springframework.context.ApplicationEventPublisher;
3333
import org.springframework.lang.Nullable;
34+
import org.springframework.modulith.core.util.CheckReturnValue;
3435
import org.springframework.modulith.test.PublishedEvents.TypedPublishedEvents;
3536
import org.springframework.modulith.test.PublishedEventsAssert.PublishedEventAssert;
3637
import org.springframework.modulith.test.Scenario.When.EventResult;
@@ -53,6 +54,7 @@
5354
* @author Oliver Drotbohm
5455
* @see ApplicationModuleTest
5556
*/
57+
@CheckReturnValue
5658
public class Scenario {
5759

5860
private static final Predicate<Object> DEFAULT_ACCEPTANCE = it -> {
@@ -216,6 +218,7 @@ Scenario setDefaultCustomizer(Function<ConditionFactory, ConditionFactory> custo
216218
return this;
217219
}
218220

221+
@CheckReturnValue
219222
public class When<T> {
220223

221224
private final BiFunction<TransactionOperations, ApplicationEventPublisher, T> stimulus;
@@ -460,6 +463,7 @@ public void andVerifyEvents(Consumer<AssertablePublishedEvents> events) {
460463
* @param eventType must not be {@literal null}.
461464
* @return will never be {@literal null}.
462465
*/
466+
@CheckReturnValue
463467
public <E> EventResult<E> andExpect(Class<E> eventType) {
464468
return new EventResult<>(eventType, Function.identity(), result);
465469
}
@@ -501,6 +505,7 @@ public class EventResult<E> {
501505
* @param filter must not be {@literal null}.
502506
* @return will never be {@literal null}.
503507
*/
508+
@CheckReturnValue
504509
public EventResult<E> matching(Predicate<? super E> filter) {
505510

506511
Assert.notNull(filter, "Filter must not be null!");
@@ -517,6 +522,7 @@ public EventResult<E> matching(Predicate<? super E> filter) {
517522
* @param filter must not be {@literal null}.
518523
* @return will never be {@literal null}.
519524
*/
525+
@CheckReturnValue
520526
public <S> EventResult<E> matchingMapped(Function<E, S> extractor, Predicate<? super S> filter) {
521527
return new EventResult<E>(type, createOrAdd(it -> it.matching(extractor, filter)), previousResult);
522528
}
@@ -529,6 +535,7 @@ public <S> EventResult<E> matchingMapped(Function<E, S> extractor, Predicate<? s
529535
* @param value can be {@literal null}.
530536
* @return will never be {@literal null}.
531537
*/
538+
@CheckReturnValue
532539
public <S> EventResult<E> matchingMappedValue(Function<E, S> extractor, @Nullable S value) {
533540
return new EventResult<E>(type, createOrAdd(it -> it.matching(extractor, value)), previousResult);
534541
}

0 commit comments

Comments
 (0)