Author: hardy.ferentschik
Date: 2009-06-24 10:43:50 -0400 (Wed, 24 Jun 2009)
New Revision: 16944
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/impl/PatternValidatorTest.java
Log:
Added some more test
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/impl/PatternValidatorTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/impl/PatternValidatorTest.java 2009-06-24
14:42:43 UTC (rev 16943)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/impl/PatternValidatorTest.java 2009-06-24
14:43:50 UTC (rev 16944)
@@ -36,7 +36,7 @@
public void testIsValid() {
AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
descriptor.setValue( "regexp", "foobar" );
- descriptor.setValue( "message", "{validator.pattern}" );
+ descriptor.setValue( "message", "pattern does not match" );
Pattern p = AnnotationFactory.create( descriptor );
PatternValidator constraint = new PatternValidator();
@@ -48,11 +48,28 @@
assertFalse( constraint.isValid( "This test is not foobar", null ) );
}
+ @Test
+ public void testIsValidForEmptyStringRegexp() {
+ AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
+ descriptor.setValue( "regexp", "|^.*foo$" );
+ descriptor.setValue( "message", "pattern does not match" );
+ Pattern p = AnnotationFactory.create( descriptor );
+
+ PatternValidator constraint = new PatternValidator();
+ constraint.initialize( p );
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "", null ) );
+ assertFalse( constraint.isValid( "bla bla", null ) );
+ assertTrue( constraint.isValid( "foo", null ) );
+ assertTrue( constraint.isValid( "a b c foo", null ) );
+ }
+
@Test(expectedExceptions = ValidationException.class)
public void testInvalidRegularExpression() {
AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
descriptor.setValue( "regexp", "(unbalanced parentheses" );
- descriptor.setValue( "message", "{validator.pattern}" );
+ descriptor.setValue( "message", "pattern does not match" );
Pattern p = AnnotationFactory.create( descriptor );
PatternValidator constraint = new PatternValidator();
Show replies by date