Browse Source

Polishing

pull/1046/head
Juergen Hoeller 10 years ago
parent
commit
8ddb432694
  1. 47
      spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java
  2. 10
      spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.test.web.servlet; package org.springframework.test.web.servlet;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.util.Assert;
import org.springframework.web.servlet.FlashMap; import org.springframework.web.servlet.FlashMap;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -60,19 +60,15 @@ class DefaultMvcResult implements MvcResult {
this.mockResponse = response; this.mockResponse = response;
} }
@Override
public MockHttpServletResponse getResponse() {
return mockResponse;
}
@Override @Override
public MockHttpServletRequest getRequest() { public MockHttpServletRequest getRequest() {
return mockRequest; return this.mockRequest;
} }
@Override @Override
public Object getHandler() { public MockHttpServletResponse getResponse() {
return this.handler; return this.mockResponse;
} }
public void setHandler(Object handler) { public void setHandler(Object handler) {
@ -80,17 +76,17 @@ class DefaultMvcResult implements MvcResult {
} }
@Override @Override
public HandlerInterceptor[] getInterceptors() { public Object getHandler() {
return this.interceptors; return this.handler;
} }
public void setInterceptors(HandlerInterceptor[] interceptors) { public void setInterceptors(HandlerInterceptor... interceptors) {
this.interceptors = interceptors; this.interceptors = interceptors;
} }
@Override @Override
public Exception getResolvedException() { public HandlerInterceptor[] getInterceptors() {
return this.resolvedException; return this.interceptors;
} }
public void setResolvedException(Exception resolvedException) { public void setResolvedException(Exception resolvedException) {
@ -98,17 +94,22 @@ class DefaultMvcResult implements MvcResult {
} }
@Override @Override
public ModelAndView getModelAndView() { public Exception getResolvedException() {
return this.modelAndView; return this.resolvedException;
} }
public void setModelAndView(ModelAndView mav) { public void setModelAndView(ModelAndView mav) {
this.modelAndView = mav; this.modelAndView = mav;
} }
@Override
public ModelAndView getModelAndView() {
return this.modelAndView;
}
@Override @Override
public FlashMap getFlashMap() { public FlashMap getFlashMap() {
return RequestContextUtils.getOutputFlashMap(mockRequest); return RequestContextUtils.getOutputFlashMap(this.mockRequest);
} }
public void setAsyncResult(Object asyncResult) { public void setAsyncResult(Object asyncResult) {
@ -122,7 +123,6 @@ class DefaultMvcResult implements MvcResult {
@Override @Override
public Object getAsyncResult(long timeToWait) { public Object getAsyncResult(long timeToWait) {
if (this.mockRequest.getAsyncContext() != null) { if (this.mockRequest.getAsyncContext() != null) {
timeToWait = (timeToWait == -1 ? this.mockRequest.getAsyncContext().getTimeout() : timeToWait); timeToWait = (timeToWait == -1 ? this.mockRequest.getAsyncContext().getTimeout() : timeToWait);
} }
@ -131,7 +131,7 @@ class DefaultMvcResult implements MvcResult {
long endTime = System.currentTimeMillis() + timeToWait; long endTime = System.currentTimeMillis() + timeToWait;
while (System.currentTimeMillis() < endTime && this.asyncResult.get() == RESULT_NONE) { while (System.currentTimeMillis() < endTime && this.asyncResult.get() == RESULT_NONE) {
try { try {
Thread.sleep(200); Thread.sleep(100);
} }
catch (InterruptedException ex) { catch (InterruptedException ex) {
throw new IllegalStateException("Interrupted while waiting for " + throw new IllegalStateException("Interrupted while waiting for " +
@ -140,11 +140,12 @@ class DefaultMvcResult implements MvcResult {
} }
} }
Assert.state(this.asyncResult.get() != RESULT_NONE, Object result = this.asyncResult.get();
"Async result for handler [" + this.handler + "] " + if (result == RESULT_NONE) {
throw new IllegalStateException("Async result for handler [" + this.handler + "] " +
"was not set during the specified timeToWait=" + timeToWait); "was not set during the specified timeToWait=" + timeToWait);
}
return this.asyncResult.get(); return result;
} }
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License; Version 2.0 (the "License"); * Licensed under the Apache License; Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -64,7 +64,6 @@ public interface MvcResult {
/** /**
* Return any exception raised by a handler and successfully resolved * Return any exception raised by a handler and successfully resolved
* through a {@link HandlerExceptionResolver}. * through a {@link HandlerExceptionResolver}.
*
* @return an exception, possibly {@code null} * @return an exception, possibly {@code null}
*/ */
Exception getResolvedException(); Exception getResolvedException();
@ -79,20 +78,17 @@ public interface MvcResult {
* Get the result of async execution. This method will wait for the async result * Get the result of async execution. This method will wait for the async result
* to be set for up to the amount of time configured on the async request, * to be set for up to the amount of time configured on the async request,
* i.e. {@link org.springframework.mock.web.MockAsyncContext#getTimeout()}. * i.e. {@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
* * @throws IllegalStateException if the async result was not set
* @throws IllegalStateException if the async result was not set.
*/ */
Object getAsyncResult(); Object getAsyncResult();
/** /**
* Get the result of async execution. This method will wait for the async result * Get the result of async execution. This method will wait for the async result
* to be set for up to the specified amount of time. * to be set for up to the specified amount of time.
*
* @param timeToWait how long to wait for the async result to be set, in * @param timeToWait how long to wait for the async result to be set, in
* milliseconds; if -1, then the async request timeout value is used, * milliseconds; if -1, then the async request timeout value is used,
* i.e.{@link org.springframework.mock.web.MockAsyncContext#getTimeout()}. * i.e.{@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
* * @throws IllegalStateException if the async result was not set
* @throws IllegalStateException if the async result was not set.
*/ */
Object getAsyncResult(long timeToWait); Object getAsyncResult(long timeToWait);

Loading…
Cancel
Save