From bd1b559d47603748f6d57a0ff21f68505258ace5 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 May 2010 14:05:21 +0000 Subject: [PATCH] MockHttpServletResponse supports multiple includes (SPR-7188) --- .../mock/web/MockHttpServletResponse.java | 25 ++++++++++++++++--- .../mock/web/MockRequestDispatcher.java | 4 +-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java b/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java index 6256bbe5163..6d220572665 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -98,7 +98,7 @@ public class MockHttpServletResponse implements HttpServletResponse { private String forwardedUrl; - private String includedUrl; + private final List includedUrls = new ArrayList(); //--------------------------------------------------------------------- @@ -443,11 +443,28 @@ public class MockHttpServletResponse implements HttpServletResponse { } public void setIncludedUrl(String includedUrl) { - this.includedUrl = includedUrl; + this.includedUrls.clear(); + if (includedUrl != null) { + this.includedUrls.add(includedUrl); + } } public String getIncludedUrl() { - return this.includedUrl; + int count = this.includedUrls.size(); + if (count > 1) { + throw new IllegalStateException( + "More than 1 URL included - check getIncludedUrls instead: " + this.includedUrls); + } + return (count == 1 ? this.includedUrls.get(0) : null); + } + + public void addIncludedUrl(String includedUrl) { + Assert.notNull(includedUrl, "Included URL must not be null"); + this.includedUrls.add(includedUrl); + } + + public List getIncludedUrls() { + return this.includedUrls; } diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java b/org.springframework.test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java index 17485d21f38..a87bea43c91 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -68,7 +68,7 @@ public class MockRequestDispatcher implements RequestDispatcher { public void include(ServletRequest request, ServletResponse response) { Assert.notNull(request, "Request must not be null"); Assert.notNull(response, "Response must not be null"); - getMockHttpServletResponse(response).setIncludedUrl(this.url); + getMockHttpServletResponse(response).addIncludedUrl(this.url); if (logger.isDebugEnabled()) { logger.debug("MockRequestDispatcher: including URL [" + this.url + "]"); }