Skip to content

Commit d66186a

Browse files
committed
Polishing
(cherry picked from commit 8ddb432)
1 parent 75a8f5b commit d66186a

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,13 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.test.web.servlet;
1718

1819
import java.util.concurrent.atomic.AtomicReference;
1920

2021
import org.springframework.mock.web.MockHttpServletRequest;
2122
import org.springframework.mock.web.MockHttpServletResponse;
22-
import org.springframework.util.Assert;
2323
import org.springframework.web.servlet.FlashMap;
2424
import org.springframework.web.servlet.HandlerInterceptor;
2525
import org.springframework.web.servlet.ModelAndView;
@@ -60,55 +60,56 @@ public DefaultMvcResult(MockHttpServletRequest request, MockHttpServletResponse
6060
this.mockResponse = response;
6161
}
6262

63-
@Override
64-
public MockHttpServletResponse getResponse() {
65-
return mockResponse;
66-
}
6763

6864
@Override
6965
public MockHttpServletRequest getRequest() {
70-
return mockRequest;
66+
return this.mockRequest;
7167
}
7268

7369
@Override
74-
public Object getHandler() {
75-
return this.handler;
70+
public MockHttpServletResponse getResponse() {
71+
return this.mockResponse;
7672
}
7773

7874
public void setHandler(Object handler) {
7975
this.handler = handler;
8076
}
8177

8278
@Override
83-
public HandlerInterceptor[] getInterceptors() {
84-
return this.interceptors;
79+
public Object getHandler() {
80+
return this.handler;
8581
}
8682

87-
public void setInterceptors(HandlerInterceptor[] interceptors) {
83+
public void setInterceptors(HandlerInterceptor... interceptors) {
8884
this.interceptors = interceptors;
8985
}
9086

9187
@Override
92-
public Exception getResolvedException() {
93-
return this.resolvedException;
88+
public HandlerInterceptor[] getInterceptors() {
89+
return this.interceptors;
9490
}
9591

9692
public void setResolvedException(Exception resolvedException) {
9793
this.resolvedException = resolvedException;
9894
}
9995

10096
@Override
101-
public ModelAndView getModelAndView() {
102-
return this.modelAndView;
97+
public Exception getResolvedException() {
98+
return this.resolvedException;
10399
}
104100

105101
public void setModelAndView(ModelAndView mav) {
106102
this.modelAndView = mav;
107103
}
108104

105+
@Override
106+
public ModelAndView getModelAndView() {
107+
return this.modelAndView;
108+
}
109+
109110
@Override
110111
public FlashMap getFlashMap() {
111-
return RequestContextUtils.getOutputFlashMap(mockRequest);
112+
return RequestContextUtils.getOutputFlashMap(this.mockRequest);
112113
}
113114

114115
public void setAsyncResult(Object asyncResult) {
@@ -122,7 +123,6 @@ public Object getAsyncResult() {
122123

123124
@Override
124125
public Object getAsyncResult(long timeToWait) {
125-
126126
if (this.mockRequest.getAsyncContext() != null) {
127127
timeToWait = (timeToWait == -1 ? this.mockRequest.getAsyncContext().getTimeout() : timeToWait);
128128
}
@@ -131,7 +131,7 @@ public Object getAsyncResult(long timeToWait) {
131131
long endTime = System.currentTimeMillis() + timeToWait;
132132
while (System.currentTimeMillis() < endTime && this.asyncResult.get() == RESULT_NONE) {
133133
try {
134-
Thread.sleep(200);
134+
Thread.sleep(100);
135135
}
136136
catch (InterruptedException ex) {
137137
throw new IllegalStateException("Interrupted while waiting for " +
@@ -140,11 +140,12 @@ public Object getAsyncResult(long timeToWait) {
140140
}
141141
}
142142

143-
Assert.state(this.asyncResult.get() != RESULT_NONE,
144-
"Async result for handler [" + this.handler + "] " +
145-
"was not set during the specified timeToWait=" + timeToWait);
146-
147-
return this.asyncResult.get();
143+
Object result = this.asyncResult.get();
144+
if (result == RESULT_NONE) {
145+
throw new IllegalStateException("Async result for handler [" + this.handler + "] " +
146+
"was not set during the specified timeToWait=" + timeToWait);
147+
}
148+
return result;
148149
}
149150

150151
}

spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License; Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,7 +64,6 @@ public interface MvcResult {
6464
/**
6565
* Return any exception raised by a handler and successfully resolved
6666
* through a {@link HandlerExceptionResolver}.
67-
*
6867
* @return an exception, possibly {@code null}
6968
*/
7069
Exception getResolvedException();
@@ -79,20 +78,17 @@ public interface MvcResult {
7978
* Get the result of async execution. This method will wait for the async result
8079
* to be set for up to the amount of time configured on the async request,
8180
* i.e. {@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
82-
*
83-
* @throws IllegalStateException if the async result was not set.
81+
* @throws IllegalStateException if the async result was not set
8482
*/
8583
Object getAsyncResult();
8684

8785
/**
8886
* Get the result of async execution. This method will wait for the async result
8987
* to be set for up to the specified amount of time.
90-
*
9188
* @param timeToWait how long to wait for the async result to be set, in
9289
* milliseconds; if -1, then the async request timeout value is used,
9390
* i.e.{@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
94-
*
95-
* @throws IllegalStateException if the async result was not set.
91+
* @throws IllegalStateException if the async result was not set
9692
*/
9793
Object getAsyncResult(long timeToWait);
9894

0 commit comments

Comments
 (0)