Add getResult/hasResult methods to DeferredResult
Issue: SPR-10603
This commit is contained in:
parent
9bc4663ead
commit
c6ecaacc03
|
@ -107,6 +107,22 @@ public class DeferredResult<T> {
|
|||
return ((this.result != RESULT_NONE) || this.expired);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the DeferredResult has been set.
|
||||
*/
|
||||
public boolean hasResult() {
|
||||
return this.result != RESULT_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the result or {@code null} if the result wasn't set; since the result can
|
||||
* also be {@code null}, it is recommended to use {@link #hasResult()} first
|
||||
* to check if there is a result prior to calling this method.
|
||||
*/
|
||||
public Object getResult() {
|
||||
return hasResult() ? this.result : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured timeout value in milliseconds.
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.junit.Test;
|
|||
import org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* DeferredResult tests.
|
||||
|
@ -69,6 +69,21 @@ public class DeferredResultTests {
|
|||
verify(handler).handleResult("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasResult() {
|
||||
DeferredResultHandler handler = mock(DeferredResultHandler.class);
|
||||
|
||||
DeferredResult<String> result = new DeferredResult<String>();
|
||||
result.setResultHandler(handler);
|
||||
|
||||
assertFalse(result.hasResult());
|
||||
assertNull(result.getResult());
|
||||
|
||||
result.setResult("hello");
|
||||
|
||||
assertEquals("hello", result.getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCompletion() throws Exception {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
|
Loading…
Reference in New Issue