From 8ddb432694aa97332dddcbefcdfe4a7434ac8ad1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 27 Apr 2016 21:35:26 +0200 Subject: [PATCH] Polishing --- .../test/web/servlet/DefaultMvcResult.java | 49 ++++++++++--------- .../test/web/servlet/MvcResult.java | 10 ++-- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java index 35a686287ff..4bf5f8dd10f 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java +++ b/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"); * 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 * limitations under the License. */ + package org.springframework.test.web.servlet; import java.util.concurrent.atomic.AtomicReference; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.util.Assert; import org.springframework.web.servlet.FlashMap; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; @@ -60,19 +60,15 @@ class DefaultMvcResult implements MvcResult { this.mockResponse = response; } - @Override - public MockHttpServletResponse getResponse() { - return mockResponse; - } @Override public MockHttpServletRequest getRequest() { - return mockRequest; + return this.mockRequest; } @Override - public Object getHandler() { - return this.handler; + public MockHttpServletResponse getResponse() { + return this.mockResponse; } public void setHandler(Object handler) { @@ -80,17 +76,17 @@ class DefaultMvcResult implements MvcResult { } @Override - public HandlerInterceptor[] getInterceptors() { - return this.interceptors; + public Object getHandler() { + return this.handler; } - public void setInterceptors(HandlerInterceptor[] interceptors) { + public void setInterceptors(HandlerInterceptor... interceptors) { this.interceptors = interceptors; } @Override - public Exception getResolvedException() { - return this.resolvedException; + public HandlerInterceptor[] getInterceptors() { + return this.interceptors; } public void setResolvedException(Exception resolvedException) { @@ -98,17 +94,22 @@ class DefaultMvcResult implements MvcResult { } @Override - public ModelAndView getModelAndView() { - return this.modelAndView; + public Exception getResolvedException() { + return this.resolvedException; } public void setModelAndView(ModelAndView mav) { this.modelAndView = mav; } + @Override + public ModelAndView getModelAndView() { + return this.modelAndView; + } + @Override public FlashMap getFlashMap() { - return RequestContextUtils.getOutputFlashMap(mockRequest); + return RequestContextUtils.getOutputFlashMap(this.mockRequest); } public void setAsyncResult(Object asyncResult) { @@ -122,7 +123,6 @@ class DefaultMvcResult implements MvcResult { @Override public Object getAsyncResult(long timeToWait) { - if (this.mockRequest.getAsyncContext() != null) { timeToWait = (timeToWait == -1 ? this.mockRequest.getAsyncContext().getTimeout() : timeToWait); } @@ -131,7 +131,7 @@ class DefaultMvcResult implements MvcResult { long endTime = System.currentTimeMillis() + timeToWait; while (System.currentTimeMillis() < endTime && this.asyncResult.get() == RESULT_NONE) { try { - Thread.sleep(200); + Thread.sleep(100); } catch (InterruptedException ex) { throw new IllegalStateException("Interrupted while waiting for " + @@ -140,11 +140,12 @@ class DefaultMvcResult implements MvcResult { } } - Assert.state(this.asyncResult.get() != RESULT_NONE, - "Async result for handler [" + this.handler + "] " + - "was not set during the specified timeToWait=" + timeToWait); - - return this.asyncResult.get(); + Object result = this.asyncResult.get(); + if (result == RESULT_NONE) { + throw new IllegalStateException("Async result for handler [" + this.handler + "] " + + "was not set during the specified timeToWait=" + timeToWait); + } + return result; } } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java index 0aabe54563e..a0676a238e8 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/MvcResult.java +++ b/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"); * 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 * through a {@link HandlerExceptionResolver}. - * * @return an exception, possibly {@code null} */ Exception getResolvedException(); @@ -79,20 +78,17 @@ public interface MvcResult { * 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, * 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(); /** * 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. - * * @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, * 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);