@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2013 the original author or authors .
* Copyright 2002 - 2014 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -17,6 +17,7 @@
package org.springframework.test.web.servlet.result ;
package org.springframework.test.web.servlet.result ;
import static org.hamcrest.Matchers.is ;
import static org.hamcrest.Matchers.is ;
import static org.hamcrest.Matchers.startsWith ;
import java.util.Date ;
import java.util.Date ;
@ -24,12 +25,14 @@ import org.junit.Before;
import org.junit.Test ;
import org.junit.Test ;
import org.springframework.test.web.servlet.MvcResult ;
import org.springframework.test.web.servlet.MvcResult ;
import org.springframework.test.web.servlet.StubMvcResult ;
import org.springframework.test.web.servlet.StubMvcResult ;
import org.springframework.test.web.servlet.result.ModelResultMatchers ;
import org.springframework.validation.BeanPropertyBindingResult ;
import org.springframework.validation.BeanPropertyBindingResult ;
import org.springframework.validation.BindingResult ;
import org.springframework.validation.BindingResult ;
import org.springframework.web.servlet.ModelAndView ;
import org.springframework.web.servlet.ModelAndView ;
/ * *
/ * *
* Unit tests for
* { @link org . springframework . test . web . servlet . result . ModelResultMatchers } .
*
* @author Craig Walls
* @author Craig Walls
* /
* /
public class ModelResultMatchersTests {
public class ModelResultMatchersTests {
@ -145,6 +148,26 @@ public class ModelResultMatchersTests {
this . matchers . attributeHasFieldErrors ( "date" , "good" , "time" ) . match ( this . mvcResultWithError ) ;
this . matchers . attributeHasFieldErrors ( "date" , "good" , "time" ) . match ( this . mvcResultWithError ) ;
}
}
@Test
public void attributeHasFieldErrorCode ( ) throws Exception {
this . matchers . attributeHasFieldErrorCode ( "date" , "time" , "error" ) . match ( this . mvcResultWithError ) ;
}
@Test ( expected = AssertionError . class )
public void attributeHasFieldErrorCode_withoutErrorOnField ( ) throws Exception {
this . matchers . attributeHasFieldErrorCode ( "date" , "time" , "incorrectError" ) . match ( this . mvcResultWithError ) ;
}
@Test
public void attributeHasFieldErrorCode_startsWith ( ) throws Exception {
this . matchers . attributeHasFieldErrorCode ( "date" , "time" , startsWith ( "err" ) ) . match ( this . mvcResultWithError ) ;
}
@Test ( expected = AssertionError . class )
public void attributeHasFieldErrorCode_startsWith_withoutErrorOnField ( ) throws Exception {
this . matchers . attributeHasFieldErrorCode ( "date" , "time" , startsWith ( "inc" ) ) . match ( this . mvcResultWithError ) ;
}
private MvcResult getMvcResult ( ModelAndView modelAndView ) {
private MvcResult getMvcResult ( ModelAndView modelAndView ) {
return new StubMvcResult ( null , null , null , null , modelAndView , null , null ) ;
return new StubMvcResult ( null , null , null , null , modelAndView , null , null ) ;
}
}