@ -22,8 +22,10 @@ import java.util.HashMap;
@@ -22,8 +22,10 @@ import java.util.HashMap;
import java.util.List ;
import java.util.Map ;
import javax.servlet.http.Cookie ;
import javax.servlet.http.HttpSession ;
import org.junit.Test ;
import org.mockito.Mockito ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.MediaType ;
@ -40,8 +42,7 @@ import org.springframework.web.servlet.DispatcherServlet;
@@ -40,8 +42,7 @@ import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.FlashMap ;
import org.springframework.web.servlet.ModelAndView ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.* ;
/ * *
* Unit tests for { @link PrintingResultHandler } .
@ -93,6 +94,55 @@ public class PrintingResultHandlerTests {
@@ -93,6 +94,55 @@ public class PrintingResultHandlerTests {
assertValue ( "MockHttpServletRequest" , "Session Attrs" , Collections . singletonMap ( "foo" , "bar" ) ) ;
}
@Test
public void printRequestWithoutSession ( ) throws Exception {
this . request . addParameter ( "param" , "paramValue" ) ;
this . request . addHeader ( "header" , "headerValue" ) ;
this . request . setCharacterEncoding ( "UTF-16" ) ;
String palindrome = "ablE was I ere I saw Elba" ;
byte [ ] bytes = palindrome . getBytes ( "UTF-16" ) ;
this . request . setContent ( bytes ) ;
this . handler . handle ( this . mvcResult ) ;
HttpHeaders headers = new HttpHeaders ( ) ;
headers . set ( "header" , "headerValue" ) ;
MultiValueMap < String , String > params = new LinkedMultiValueMap < > ( ) ;
params . add ( "param" , "paramValue" ) ;
assertValue ( "MockHttpServletRequest" , "HTTP Method" , this . request . getMethod ( ) ) ;
assertValue ( "MockHttpServletRequest" , "Request URI" , this . request . getRequestURI ( ) ) ;
assertValue ( "MockHttpServletRequest" , "Parameters" , params ) ;
assertValue ( "MockHttpServletRequest" , "Headers" , headers ) ;
assertValue ( "MockHttpServletRequest" , "Body" , palindrome ) ;
}
@Test
public void printRequestWithEmptySessionMock ( ) throws Exception {
this . request . addParameter ( "param" , "paramValue" ) ;
this . request . addHeader ( "header" , "headerValue" ) ;
this . request . setCharacterEncoding ( "UTF-16" ) ;
String palindrome = "ablE was I ere I saw Elba" ;
byte [ ] bytes = palindrome . getBytes ( "UTF-16" ) ;
this . request . setContent ( bytes ) ;
this . request . setSession ( Mockito . mock ( HttpSession . class ) ) ;
this . handler . handle ( this . mvcResult ) ;
HttpHeaders headers = new HttpHeaders ( ) ;
headers . set ( "header" , "headerValue" ) ;
MultiValueMap < String , String > params = new LinkedMultiValueMap < > ( ) ;
params . add ( "param" , "paramValue" ) ;
assertValue ( "MockHttpServletRequest" , "HTTP Method" , this . request . getMethod ( ) ) ;
assertValue ( "MockHttpServletRequest" , "Request URI" , this . request . getRequestURI ( ) ) ;
assertValue ( "MockHttpServletRequest" , "Parameters" , params ) ;
assertValue ( "MockHttpServletRequest" , "Headers" , headers ) ;
assertValue ( "MockHttpServletRequest" , "Body" , palindrome ) ;
}
@Test
@SuppressWarnings ( "deprecation" )
public void printResponse ( ) throws Exception {
@ -325,6 +375,7 @@ public class PrintingResultHandlerTests {
@@ -325,6 +375,7 @@ public class PrintingResultHandlerTests {
}
}
public void handle ( ) {
}