1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
59
59
* @author Rob Harrop
60
60
* @author Arjen Poutsma
61
61
* @author Chris Beams
62
- *
63
62
* @since 10.06.2003
64
63
*/
65
64
public class CustomEditorTests {
@@ -302,8 +301,8 @@ public void testCustomBooleanEditorWithAllowEmpty() {
302
301
303
302
@ Test
304
303
public void testCustomBooleanEditorWithSpecialTrueAndFalseStrings () throws Exception {
305
- final String trueString = "pechorin" ;
306
- final String falseString = "nash" ;
304
+ String trueString = "pechorin" ;
305
+ String falseString = "nash" ;
307
306
308
307
CustomBooleanEditor editor = new CustomBooleanEditor (trueString , falseString , false );
309
308
@@ -320,6 +319,14 @@ public void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Excep
320
319
editor .setAsText (falseString .toUpperCase ());
321
320
assertFalse (((Boolean ) editor .getValue ()).booleanValue ());
322
321
assertEquals (falseString , editor .getAsText ());
322
+
323
+ try {
324
+ editor .setAsText (null );
325
+ fail ("Should have thrown IllegalArgumentException" );
326
+ }
327
+ catch (IllegalArgumentException ex ) {
328
+ // expected
329
+ }
323
330
}
324
331
325
332
@ Test
@@ -423,7 +430,7 @@ public void testCustomNumberEditorWithoutAllowEmpty() {
423
430
assertTrue ("Correct bigDecimal value" , new BigDecimal ("4.5" ).equals (tb .getBigDecimal ()));
424
431
}
425
432
426
- @ Test (expected = IllegalArgumentException .class )
433
+ @ Test (expected = IllegalArgumentException .class )
427
434
public void testCustomNumberEditorCtorWithNullNumberType () throws Exception {
428
435
new CustomNumberEditor (null , true );
429
436
}
@@ -543,7 +550,7 @@ public void testCharacterEditorWithAllowEmpty() {
543
550
assertNull (cb .getMyCharacter ());
544
551
}
545
552
546
- @ Test (expected = IllegalArgumentException .class )
553
+ @ Test (expected = IllegalArgumentException .class )
547
554
public void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter () throws Exception {
548
555
PropertyEditor charEditor = new CharacterEditor (false );
549
556
charEditor .setAsText ("ColdWaterCanyon" );
@@ -562,7 +569,7 @@ public void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws
562
569
assertEquals (" " , charEditor .getAsText ());
563
570
}
564
571
565
- @ Test (expected = IllegalArgumentException .class )
572
+ @ Test (expected = IllegalArgumentException .class )
566
573
public void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull () throws Exception {
567
574
PropertyEditor charEditor = new CharacterEditor (false );
568
575
charEditor .setAsText (null );
@@ -583,7 +590,7 @@ public void testClassEditor() {
583
590
assertEquals ("" , classEditor .getAsText ());
584
591
}
585
592
586
- @ Test (expected = IllegalArgumentException .class )
593
+ @ Test (expected = IllegalArgumentException .class )
587
594
public void testClassEditorWithNonExistentClass () throws Exception {
588
595
PropertyEditor classEditor = new ClassEditor ();
589
596
classEditor .setAsText ("hairdresser.on.Fire" );
@@ -685,26 +692,40 @@ public void testPatternEditor() {
685
692
@ Test
686
693
public void testCustomBooleanEditor () {
687
694
CustomBooleanEditor editor = new CustomBooleanEditor (false );
695
+
688
696
editor .setAsText ("true" );
689
697
assertEquals (Boolean .TRUE , editor .getValue ());
690
698
assertEquals ("true" , editor .getAsText ());
699
+
691
700
editor .setAsText ("false" );
692
701
assertEquals (Boolean .FALSE , editor .getValue ());
693
702
assertEquals ("false" , editor .getAsText ());
703
+
694
704
editor .setValue (null );
695
705
assertEquals (null , editor .getValue ());
696
706
assertEquals ("" , editor .getAsText ());
707
+
708
+ try {
709
+ editor .setAsText (null );
710
+ fail ("Should have thrown IllegalArgumentException" );
711
+ }
712
+ catch (IllegalArgumentException ex ) {
713
+ // expected
714
+ }
697
715
}
698
716
699
717
@ Test
700
718
public void testCustomBooleanEditorWithEmptyAsNull () {
701
719
CustomBooleanEditor editor = new CustomBooleanEditor (true );
720
+
702
721
editor .setAsText ("true" );
703
722
assertEquals (Boolean .TRUE , editor .getValue ());
704
723
assertEquals ("true" , editor .getAsText ());
724
+
705
725
editor .setAsText ("false" );
706
726
assertEquals (Boolean .FALSE , editor .getValue ());
707
727
assertEquals ("false" , editor .getAsText ());
728
+
708
729
editor .setValue (null );
709
730
assertEquals (null , editor .getValue ());
710
731
assertEquals ("" , editor .getAsText ());
@@ -750,7 +771,7 @@ public void testCustomDateEditorWithExactDateLength() {
750
771
}
751
772
catch (IllegalArgumentException ex ) {
752
773
// expected
753
- assertTrue (ex .getMessage ().indexOf ("10" ) != - 1 );
774
+ assertTrue (ex .getMessage ().contains ("10" ));
754
775
}
755
776
}
756
777
0 commit comments