Skip to content

Commit 402753e

Browse files
committed
Adds extra test and minor cleanups.
1 parent a2ad5f6 commit 402753e

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

jooby-servlet/src/main/java/org/jooby/servlet/ServletServletRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.net.URLDecoder;
2626
import java.util.*;
2727
import java.util.concurrent.Executor;
28+
import java.util.function.Function;
2829
import java.util.stream.Collectors;
2930

3031
import javax.servlet.ServletException;
@@ -121,7 +122,8 @@ public Map<String, Object> attributes() {
121122
if (!attributeNames.hasMoreElements()) {
122123
return Collections.emptyMap();
123124
}
124-
return Collections.list(attributeNames).stream().collect(Collectors.toMap(name -> name, name -> req.getAttribute(name)));
125+
return Collections.list(attributeNames).stream()
126+
.collect(Collectors.toMap(Function.identity(), name -> req.getAttribute(name)));
125127
}
126128

127129
@Override

jooby-servlet/src/test/java/org/jooby/servlet/ServletServletRequestTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ public void noparams() throws IOException, Exception {
154154

155155
@Test
156156
public void attributes() throws Exception {
157-
String tmpdir = System.getProperty("java.io.tmpdir");
158-
UUID serverAttribute = UUID.randomUUID();
159-
new MockUnit(HttpServletRequest.class)
157+
String tmpdir = System.getProperty("java.io.tmpdir");
158+
final UUID serverAttribute = UUID.randomUUID();
159+
new MockUnit(HttpServletRequest.class)
160160
.expect(unit -> {
161161
HttpServletRequest req = unit.get(HttpServletRequest.class);
162162
expect(req.getContentType()).andReturn("text/html");
@@ -173,6 +173,24 @@ public void attributes() throws Exception {
173173

174174
}
175175

176+
@Test
177+
public void emptyAttributes() throws Exception {
178+
String tmpdir = System.getProperty("java.io.tmpdir");
179+
new MockUnit(HttpServletRequest.class)
180+
.expect(unit -> {
181+
HttpServletRequest req = unit.get(HttpServletRequest.class);
182+
expect(req.getContentType()).andReturn("text/html");
183+
expect(req.getPathInfo()).andReturn("/");
184+
expect(req.getAttributeNames()).andReturn(Collections.emptyEnumeration());
185+
})
186+
.run(unit -> {
187+
assertEquals(Collections.emptyMap(),
188+
new ServletServletRequest(unit.get(HttpServletRequest.class), tmpdir)
189+
.attributes());
190+
});
191+
192+
}
193+
176194
@Test(expected = IOException.class)
177195
public void filesFailure() throws IOException, Exception {
178196
String tmpdir = System.getProperty("java.io.tmpdir");

0 commit comments

Comments
 (0)