From 8f6879f8f3279f45451df0794b283ff5f7222af2 Mon Sep 17 00:00:00 2001 From: mia-li-001 Date: Sun, 1 Nov 2026 10:05:46 -0600 Subject: [PATCH] Extracted duplicated stubbings in HttpContentServiceImplTest into 2 helpers --- .../web/HttpContentServiceImplTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/jasig/portlet/proxy/service/web/HttpContentServiceImplTest.java b/src/test/java/org/jasig/portlet/proxy/service/web/HttpContentServiceImplTest.java index 7b91dbf1..4c5f7941 100644 --- a/src/test/java/org/jasig/portlet/proxy/service/web/HttpContentServiceImplTest.java +++ b/src/test/java/org/jasig/portlet/proxy/service/web/HttpContentServiceImplTest.java @@ -58,9 +58,7 @@ public void setUp() { @Test public void testPostFormNoParams() { - when(request.getParameter(HttpContentServiceImpl.IS_FORM_PARAM)).thenReturn("true"); - when(request.getParameter(HttpContentServiceImpl.FORM_METHOD_PARAM)).thenReturn("POST"); - when(processor.process(any(String.class), any(PortletRequest.class))).thenReturn("http://somewhere.com/path/page.html"); + setupSpringELProcessorProcessAndGetParameterStubs2("POST"); HttpContentRequestImpl proxyRequest = new HttpContentRequestImpl(request, processor); final HttpUriRequest httpRequest = service.getHttpRequest(proxyRequest, request); @@ -75,9 +73,7 @@ public void testGetForm() { params.put("param1", new String[]{"value1"}); params.put("param2", new String[]{"value3", "value4"}); - when(request.getParameter(HttpContentServiceImpl.IS_FORM_PARAM)).thenReturn("true"); - when(request.getParameter(HttpContentServiceImpl.FORM_METHOD_PARAM)).thenReturn("GET"); - when(processor.process(any(String.class), any(PortletRequest.class))).thenReturn("http://somewhere.com/path/page.html"); + setupSpringELProcessorProcessAndGetParameterStubs2("GET"); HttpContentRequestImpl proxyRequest = new HttpContentRequestImpl(request, processor); final HttpUriRequest httpRequest = service.getHttpRequest(proxyRequest, request); @@ -88,9 +84,7 @@ public void testGetForm() { @Test public void testGetFormNoParams() { - when(request.getParameter(HttpContentServiceImpl.IS_FORM_PARAM)).thenReturn("true"); - when(request.getParameter(HttpContentServiceImpl.FORM_METHOD_PARAM)).thenReturn("GET"); - when(processor.process(any(String.class), any(PortletRequest.class))).thenReturn("http://somewhere.com/path/page.html"); + setupSpringELProcessorProcessAndGetParameterStubs2("GET"); HttpContentRequestImpl proxyRequest = new HttpContentRequestImpl(request, processor); final HttpUriRequest httpRequest = service.getHttpRequest(proxyRequest, request); @@ -103,8 +97,7 @@ public void testGetFormNoParams() { @Test public void testNonForm() { - when(request.getParameter(HttpContentServiceImpl.IS_FORM_PARAM)).thenReturn("false"); - when(processor.process(any(String.class), any(PortletRequest.class))).thenReturn("http://somewhere.com/path/page.html"); + setupSpringELProcessorProcessAndGetParameterStubs("false"); HttpContentRequestImpl proxyRequest = new HttpContentRequestImpl(request, processor); final HttpUriRequest httpRequest = service.getHttpRequest(proxyRequest, request); @@ -113,5 +106,13 @@ public void testNonForm() { } + private void setupSpringELProcessorProcessAndGetParameterStubs(String getParameterReturnValue) { + when(request.getParameter(HttpContentServiceImpl.IS_FORM_PARAM)).thenReturn(getParameterReturnValue); + when(processor.process(any(String.class), any(PortletRequest.class))).thenReturn("http://somewhere.com/path/page.html"); + } + private void setupSpringELProcessorProcessAndGetParameterStubs2(String getParameterReturnValue) { + setupSpringELProcessorProcessAndGetParameterStubs("true"); + when(request.getParameter(HttpContentServiceImpl.FORM_METHOD_PARAM)).thenReturn(getParameterReturnValue); + } }