11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2015 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.
5959 * @author Rob Harrop
6060 * @author Arjen Poutsma
6161 * @author Chris Beams
62- *
6362 * @since 10.06.2003
6463 */
6564public class CustomEditorTests {
@@ -302,8 +301,8 @@ public void testCustomBooleanEditorWithAllowEmpty() {
302301
303302 @ Test
304303 public void testCustomBooleanEditorWithSpecialTrueAndFalseStrings () throws Exception {
305- final String trueString = "pechorin" ;
306- final String falseString = "nash" ;
304+ String trueString = "pechorin" ;
305+ String falseString = "nash" ;
307306
308307 CustomBooleanEditor editor = new CustomBooleanEditor (trueString , falseString , false );
309308
@@ -320,6 +319,14 @@ public void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Excep
320319 editor .setAsText (falseString .toUpperCase ());
321320 assertFalse (((Boolean ) editor .getValue ()).booleanValue ());
322321 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+ }
323330 }
324331
325332 @ Test
@@ -423,7 +430,7 @@ public void testCustomNumberEditorWithoutAllowEmpty() {
423430 assertTrue ("Correct bigDecimal value" , new BigDecimal ("4.5" ).equals (tb .getBigDecimal ()));
424431 }
425432
426- @ Test (expected = IllegalArgumentException .class )
433+ @ Test (expected = IllegalArgumentException .class )
427434 public void testCustomNumberEditorCtorWithNullNumberType () throws Exception {
428435 new CustomNumberEditor (null , true );
429436 }
@@ -543,7 +550,7 @@ public void testCharacterEditorWithAllowEmpty() {
543550 assertNull (cb .getMyCharacter ());
544551 }
545552
546- @ Test (expected = IllegalArgumentException .class )
553+ @ Test (expected = IllegalArgumentException .class )
547554 public void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter () throws Exception {
548555 PropertyEditor charEditor = new CharacterEditor (false );
549556 charEditor .setAsText ("ColdWaterCanyon" );
@@ -562,7 +569,7 @@ public void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws
562569 assertEquals (" " , charEditor .getAsText ());
563570 }
564571
565- @ Test (expected = IllegalArgumentException .class )
572+ @ Test (expected = IllegalArgumentException .class )
566573 public void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull () throws Exception {
567574 PropertyEditor charEditor = new CharacterEditor (false );
568575 charEditor .setAsText (null );
@@ -583,7 +590,7 @@ public void testClassEditor() {
583590 assertEquals ("" , classEditor .getAsText ());
584591 }
585592
586- @ Test (expected = IllegalArgumentException .class )
593+ @ Test (expected = IllegalArgumentException .class )
587594 public void testClassEditorWithNonExistentClass () throws Exception {
588595 PropertyEditor classEditor = new ClassEditor ();
589596 classEditor .setAsText ("hairdresser.on.Fire" );
@@ -685,26 +692,40 @@ public void testPatternEditor() {
685692 @ Test
686693 public void testCustomBooleanEditor () {
687694 CustomBooleanEditor editor = new CustomBooleanEditor (false );
695+
688696 editor .setAsText ("true" );
689697 assertEquals (Boolean .TRUE , editor .getValue ());
690698 assertEquals ("true" , editor .getAsText ());
699+
691700 editor .setAsText ("false" );
692701 assertEquals (Boolean .FALSE , editor .getValue ());
693702 assertEquals ("false" , editor .getAsText ());
703+
694704 editor .setValue (null );
695705 assertEquals (null , editor .getValue ());
696706 assertEquals ("" , editor .getAsText ());
707+
708+ try {
709+ editor .setAsText (null );
710+ fail ("Should have thrown IllegalArgumentException" );
711+ }
712+ catch (IllegalArgumentException ex ) {
713+ // expected
714+ }
697715 }
698716
699717 @ Test
700718 public void testCustomBooleanEditorWithEmptyAsNull () {
701719 CustomBooleanEditor editor = new CustomBooleanEditor (true );
720+
702721 editor .setAsText ("true" );
703722 assertEquals (Boolean .TRUE , editor .getValue ());
704723 assertEquals ("true" , editor .getAsText ());
724+
705725 editor .setAsText ("false" );
706726 assertEquals (Boolean .FALSE , editor .getValue ());
707727 assertEquals ("false" , editor .getAsText ());
728+
708729 editor .setValue (null );
709730 assertEquals (null , editor .getValue ());
710731 assertEquals ("" , editor .getAsText ());
@@ -750,7 +771,7 @@ public void testCustomDateEditorWithExactDateLength() {
750771 }
751772 catch (IllegalArgumentException ex ) {
752773 // expected
753- assertTrue (ex .getMessage ().indexOf ("10" ) != - 1 );
774+ assertTrue (ex .getMessage ().contains ("10" ));
754775 }
755776 }
756777
0 commit comments