File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
main/java/org/springframework/web/context/request/async
test/java/org/springframework/web/context/request/async Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,22 @@ public final boolean isSetOrExpired() {
107
107
return ((this .result != RESULT_NONE ) || this .expired );
108
108
}
109
109
110
+ /**
111
+ * @return {@code true} if the DeferredResult has been set.
112
+ */
113
+ public boolean hasResult () {
114
+ return this .result != RESULT_NONE ;
115
+ }
116
+
117
+ /**
118
+ * @return the result or {@code null} if the result wasn't set; since the result can
119
+ * also be {@code null}, it is recommended to use {@link #hasResult()} first
120
+ * to check if there is a result prior to calling this method.
121
+ */
122
+ public Object getResult () {
123
+ return hasResult () ? this .result : null ;
124
+ }
125
+
110
126
/**
111
127
* Return the configured timeout value in milliseconds.
112
128
*/
Original file line number Diff line number Diff line change 20
20
import org .springframework .web .context .request .async .DeferredResult .DeferredResultHandler ;
21
21
22
22
import static org .junit .Assert .*;
23
- import static org .mockito .BDDMockito .*;
23
+ import static org .mockito .Mockito .*;
24
24
25
25
/**
26
26
* DeferredResult tests.
@@ -69,6 +69,21 @@ public void isSetOrExpired() {
69
69
verify (handler ).handleResult ("hello" );
70
70
}
71
71
72
+ @ Test
73
+ public void hasResult () {
74
+ DeferredResultHandler handler = mock (DeferredResultHandler .class );
75
+
76
+ DeferredResult <String > result = new DeferredResult <String >();
77
+ result .setResultHandler (handler );
78
+
79
+ assertFalse (result .hasResult ());
80
+ assertNull (result .getResult ());
81
+
82
+ result .setResult ("hello" );
83
+
84
+ assertEquals ("hello" , result .getResult ());
85
+ }
86
+
72
87
@ Test
73
88
public void onCompletion () throws Exception {
74
89
final StringBuilder sb = new StringBuilder ();
You can’t perform that action at this time.
0 commit comments