11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2013 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3535import java .util .Locale ;
3636import java .util .Map ;
3737import java .util .Set ;
38-
3938import javax .servlet .RequestDispatcher ;
4039import javax .servlet .ServletContext ;
4140import javax .servlet .ServletException ;
@@ -97,8 +96,10 @@ public class MockHttpServletRequest implements HttpServletRequest {
9796
9897 private static final String CHARSET_PREFIX = "charset=" ;
9998
99+
100100 private boolean active = true ;
101101
102+
102103 // ---------------------------------------------------------------------
103104 // ServletRequest properties
104105 // ---------------------------------------------------------------------
@@ -140,6 +141,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
140141
141142 private int localPort = DEFAULT_SERVER_PORT ;
142143
144+
143145 // ---------------------------------------------------------------------
144146 // HttpServletRequest properties
145147 // ---------------------------------------------------------------------
@@ -235,6 +237,7 @@ public MockHttpServletRequest(ServletContext servletContext, String method, Stri
235237 this .locales .add (Locale .ENGLISH );
236238 }
237239
240+
238241 // ---------------------------------------------------------------------
239242 // Lifecycle methods
240243 // ---------------------------------------------------------------------
@@ -279,6 +282,7 @@ protected void checkActive() throws IllegalStateException {
279282 }
280283 }
281284
285+
282286 // ---------------------------------------------------------------------
283287 // ServletRequest interface
284288 // ---------------------------------------------------------------------
@@ -351,7 +355,7 @@ public ServletInputStream getInputStream() {
351355 * parameter name, they will be replaced.
352356 */
353357 public void setParameter (String name , String value ) {
354- setParameter (name , new String [] { value });
358+ setParameter (name , new String [] {value });
355359 }
356360
357361 /**
@@ -373,7 +377,8 @@ public void setParameter(String name, String[] values) {
373377 public void setParameters (Map params ) {
374378 Assert .notNull (params , "Parameter map must not be null" );
375379 for (Object key : params .keySet ()) {
376- Assert .isInstanceOf (String .class , key , "Parameter map key must be of type [" + String .class .getName () + "]" );
380+ Assert .isInstanceOf (String .class , key ,
381+ "Parameter map key must be of type [" + String .class .getName () + "]" );
377382 Object value = params .get (key );
378383 if (value instanceof String ) {
379384 this .setParameter ((String ) key , (String ) value );
@@ -382,8 +387,8 @@ else if (value instanceof String[]) {
382387 this .setParameter ((String ) key , (String []) value );
383388 }
384389 else {
385- throw new IllegalArgumentException ("Parameter map value must be single value " + " or array of type ["
386- + String .class .getName () + "]" );
390+ throw new IllegalArgumentException (
391+ "Parameter map value must be single value " + " or array of type [" + String .class .getName () + "]" );
387392 }
388393 }
389394 }
@@ -394,7 +399,7 @@ else if (value instanceof String[]) {
394399 * parameter name, the given value will be added to the end of the list.
395400 */
396401 public void addParameter (String name , String value ) {
397- addParameter (name , new String [] { value });
402+ addParameter (name , new String [] {value });
398403 }
399404
400405 /**
@@ -425,7 +430,8 @@ public void addParameter(String name, String[] values) {
425430 public void addParameters (Map params ) {
426431 Assert .notNull (params , "Parameter map must not be null" );
427432 for (Object key : params .keySet ()) {
428- Assert .isInstanceOf (String .class , key , "Parameter map key must be of type [" + String .class .getName () + "]" );
433+ Assert .isInstanceOf (String .class , key ,
434+ "Parameter map key must be of type [" + String .class .getName () + "]" );
429435 Object value = params .get (key );
430436 if (value instanceof String ) {
431437 this .addParameter ((String ) key , (String ) value );
@@ -434,8 +440,8 @@ else if (value instanceof String[]) {
434440 this .addParameter ((String ) key , (String []) value );
435441 }
436442 else {
437- throw new IllegalArgumentException ("Parameter map value must be single value " + " or array of type ["
438- + String .class .getName () + "]" );
443+ throw new IllegalArgumentException ("Parameter map value must be single value " +
444+ " or array of type [" + String .class .getName () + "]" );
439445 }
440446 }
441447 }
@@ -456,8 +462,7 @@ public void removeAllParameters() {
456462 }
457463
458464 public String getParameter (String name ) {
459- Assert .notNull (name , "Parameter name must not be null" );
460- String [] arr = this .parameters .get (name );
465+ String [] arr = (name != null ? this .parameters .get (name ) : null );
461466 return (arr != null && arr .length > 0 ? arr [0 ] : null );
462467 }
463468
@@ -466,8 +471,7 @@ public Enumeration<String> getParameterNames() {
466471 }
467472
468473 public String [] getParameterValues (String name ) {
469- Assert .notNull (name , "Parameter name must not be null" );
470- return this .parameters .get (name );
474+ return (name != null ? this .parameters .get (name ) : null );
471475 }
472476
473477 public Map <String , String []> getParameterMap () {
@@ -509,8 +513,8 @@ public int getServerPort() {
509513 public BufferedReader getReader () throws UnsupportedEncodingException {
510514 if (this .content != null ) {
511515 InputStream sourceStream = new ByteArrayInputStream (this .content );
512- Reader sourceReader = (this .characterEncoding != null ) ? new InputStreamReader ( sourceStream ,
513- this .characterEncoding ) : new InputStreamReader (sourceStream );
516+ Reader sourceReader = (this .characterEncoding != null ) ?
517+ new InputStreamReader ( sourceStream , this .characterEncoding ) : new InputStreamReader (sourceStream );
514518 return new BufferedReader (sourceReader );
515519 }
516520 else {
@@ -574,7 +578,7 @@ public void addPreferredLocale(Locale locale) {
574578 * @since 3.2
575579 */
576580 public void setPreferredLocales (List <Locale > locales ) {
577- Assert .notEmpty (locales , "preferred locales list must not be empty" );
581+ Assert .notEmpty (locales , "Locale list must not be empty" );
578582 this .locales .clear ();
579583 this .locales .addAll (locales );
580584 }
@@ -635,6 +639,7 @@ public int getLocalPort() {
635639 return this .localPort ;
636640 }
637641
642+
638643 // ---------------------------------------------------------------------
639644 // HttpServletRequest interface
640645 // ---------------------------------------------------------------------
@@ -797,8 +802,8 @@ public void addUserRole(String role) {
797802 }
798803
799804 public boolean isUserInRole (String role ) {
800- return (this .userRoles .contains (role ) || (this .servletContext instanceof MockServletContext && (( MockServletContext ) this . servletContext ). getDeclaredRoles (). contains (
801- role )));
805+ return (this .userRoles .contains (role ) || (this .servletContext instanceof MockServletContext &&
806+ (( MockServletContext ) this . servletContext ). getDeclaredRoles (). contains ( role )));
802807 }
803808
804809 public void setUserPrincipal (Principal userPrincipal ) {
0 commit comments