@@ -118,22 +118,40 @@ public void getModuleWebFolder_shouldReturnNullIfTheDispatcherServletIsNotYetSet
118
118
*/
119
119
@ Test
120
120
public void getModuleWebFolder_shouldReturnTheCorrectModuleFolder () throws Exception {
121
+ setupMocks (false );
122
+ String moduleId = "basicmodule" ;
123
+ String expectedPath = (REAL_PATH + "/WEB-INF/view/module/" + moduleId ).replace ("/" , File .separator );
124
+ String actualPath = WebModuleUtil .getModuleWebFolder (moduleId );
125
+
126
+ assertEquals (expectedPath , actualPath );
127
+ }
128
+
129
+ /**
130
+ * @see WebModuleUtil#getModuleWebFolder(String)
131
+ * @verifies return the correct module folder if real path has a trailing slash
132
+ */
133
+ @ Test
134
+ public void getModuleWebFolder_shouldReturnTheCorrectModuleFolderIfRealPathHasATrailingSlash () throws Exception {
135
+ setupMocks (true );
136
+ String moduleId = "basicmodule" ;
137
+ String expectedPath = (REAL_PATH + "/WEB-INF/view/module/" + moduleId ).replace ("/" , File .separator );
138
+ String actualPath = WebModuleUtil .getModuleWebFolder (moduleId );
139
+
140
+ assertEquals (expectedPath , actualPath );
141
+ }
142
+
143
+ private static void setupMocks (boolean includeTrailingSlash ) {
121
144
ServletConfig servletConfig = mock (ServletConfig .class );
122
145
123
146
ServletContext servletContext = mock (ServletContext .class );
124
- when (servletContext .getRealPath ("" )).thenReturn (REAL_PATH );
147
+ String realPath = (includeTrailingSlash ) ? REAL_PATH + "/" : REAL_PATH ;
148
+ when (servletContext .getRealPath ("" )).thenReturn (realPath );
125
149
126
150
DispatcherServlet dispatcherServlet = mock (DispatcherServlet .class );
127
151
when (dispatcherServlet .getServletConfig ()).thenReturn (servletConfig );
128
152
when (dispatcherServlet .getServletContext ()).thenReturn (servletContext );
129
153
130
154
WebModuleUtil .setDispatcherServlet (dispatcherServlet );
131
-
132
- String moduleId = "basicmodule" ;
133
- String expectedPath = (REAL_PATH + "WEB-INF/view/module/" + moduleId ).replace ("/" , File .separator );
134
- String actualPath = WebModuleUtil .getModuleWebFolder (moduleId );
135
-
136
- assertEquals (expectedPath , actualPath );
137
155
}
138
156
139
157
}
0 commit comments