1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 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.
49
49
import org .springframework .util .StopWatch ;
50
50
import org .springframework .util .StringUtils ;
51
51
52
- import static org .hamcrest .Matchers .greaterThan ;
52
+ import static org .hamcrest .Matchers .* ;
53
53
import static org .junit .Assert .*;
54
54
55
55
/**
@@ -81,14 +81,14 @@ public void canConvertIllegalArgumentNullTargetType() {
81
81
try {
82
82
assertFalse (conversionService .canConvert (String .class , null ));
83
83
fail ("Should have failed" );
84
- } catch ( IllegalArgumentException e ) {
85
-
84
+ }
85
+ catch ( IllegalArgumentException ex ) {
86
86
}
87
87
try {
88
88
assertFalse (conversionService .canConvert (TypeDescriptor .valueOf (String .class ), null ));
89
89
fail ("Should have failed" );
90
- } catch ( IllegalArgumentException e ) {
91
-
90
+ }
91
+ catch ( IllegalArgumentException ex ) {
92
92
}
93
93
}
94
94
@@ -151,8 +151,8 @@ public Object convert(Object source) {
151
151
}
152
152
});
153
153
fail ("Should have failed" );
154
- } catch ( IllegalArgumentException e ) {
155
-
154
+ }
155
+ catch ( IllegalArgumentException ex ) {
156
156
}
157
157
}
158
158
@@ -254,7 +254,8 @@ public void genericConverterDelegatingBackToConversionServiceConverterNotFound()
254
254
try {
255
255
conversionService .convert ("3,4,5" , Integer [].class );
256
256
fail ("should have failed" );
257
- } catch (ConverterNotFoundException e ) {
257
+ }
258
+ catch (ConverterNotFoundException ex ) {
258
259
}
259
260
}
260
261
@@ -389,7 +390,7 @@ public void testIgnoreCopyConstructor() {
389
390
}
390
391
391
392
@ Test
392
- public void testConvertUUID () throws Exception {
393
+ public void testConvertUUID () {
393
394
GenericConversionService service = new DefaultConversionService ();
394
395
UUID uuid = UUID .randomUUID ();
395
396
String convertToString = service .convert (uuid , String .class );
@@ -472,7 +473,7 @@ public void testPerformance3() throws Exception {
472
473
public static Map <String , Integer > map ;
473
474
474
475
@ Test
475
- public void emptyListToArray () throws Exception {
476
+ public void emptyListToArray () {
476
477
conversionService .addConverter (new CollectionToArrayConverter (conversionService ));
477
478
conversionService .addConverterFactory (new StringToNumberConverterFactory ());
478
479
List <String > list = new ArrayList <String >();
@@ -483,7 +484,7 @@ public void emptyListToArray() throws Exception {
483
484
}
484
485
485
486
@ Test
486
- public void emptyListToObject () throws Exception {
487
+ public void emptyListToObject () {
487
488
conversionService .addConverter (new CollectionToObjectConverter (conversionService ));
488
489
conversionService .addConverterFactory (new StringToNumberConverterFactory ());
489
490
List <String > list = new ArrayList <String >();
@@ -590,30 +591,30 @@ public void stringToCollectionCanConvert() throws Exception {
590
591
public Collection <Integer > stringToCollection ;
591
592
592
593
@ Test
593
- public void testConvertiblePairsInSet () throws Exception {
594
+ public void testConvertiblePairsInSet () {
594
595
Set <GenericConverter .ConvertiblePair > set = new HashSet <GenericConverter .ConvertiblePair >();
595
596
set .add (new GenericConverter .ConvertiblePair (Number .class , String .class ));
596
597
assert set .contains (new GenericConverter .ConvertiblePair (Number .class , String .class ));
597
598
}
598
599
599
600
@ Test
600
- public void testConvertiblePairEqualsAndHash () throws Exception {
601
+ public void testConvertiblePairEqualsAndHash () {
601
602
GenericConverter .ConvertiblePair pair = new GenericConverter .ConvertiblePair (Number .class , String .class );
602
603
GenericConverter .ConvertiblePair pairEqual = new GenericConverter .ConvertiblePair (Number .class , String .class );
603
604
assertEquals (pair , pairEqual );
604
605
assertEquals (pair .hashCode (), pairEqual .hashCode ());
605
606
}
606
607
607
608
@ Test
608
- public void testConvertiblePairDifferentEqualsAndHash () throws Exception {
609
+ public void testConvertiblePairDifferentEqualsAndHash () {
609
610
GenericConverter .ConvertiblePair pair = new GenericConverter .ConvertiblePair (Number .class , String .class );
610
611
GenericConverter .ConvertiblePair pairOpposite = new GenericConverter .ConvertiblePair (String .class , Number .class );
611
612
assertFalse (pair .equals (pairOpposite ));
612
613
assertFalse (pair .hashCode () == pairOpposite .hashCode ());
613
614
}
614
615
615
616
@ Test
616
- public void convertPrimitiveArray () throws Exception {
617
+ public void convertPrimitiveArray () {
617
618
GenericConversionService conversionService = new DefaultConversionService ();
618
619
byte [] byteArray = new byte [] { 1 , 2 , 3 };
619
620
Byte [] converted = conversionService .convert (byteArray , Byte [].class );
@@ -625,7 +626,8 @@ public void canConvertIllegalArgumentNullTargetTypeFromClass() {
625
626
try {
626
627
conversionService .canConvert (String .class , null );
627
628
fail ("Did not thow IllegalArgumentException" );
628
- } catch (IllegalArgumentException e ) {
629
+ }
630
+ catch (IllegalArgumentException ex ) {
629
631
}
630
632
}
631
633
@@ -634,13 +636,14 @@ public void canConvertIllegalArgumentNullTargetTypeFromTypeDescriptor() {
634
636
try {
635
637
conversionService .canConvert (TypeDescriptor .valueOf (String .class ), null );
636
638
fail ("Did not thow IllegalArgumentException" );
637
- } catch (IllegalArgumentException e ) {
639
+ }
640
+ catch (IllegalArgumentException ex ) {
638
641
}
639
642
}
640
643
641
644
@ Test
642
645
@ SuppressWarnings ({ "rawtypes" })
643
- public void convertHashMapValuesToList () throws Exception {
646
+ public void convertHashMapValuesToList () {
644
647
GenericConversionService conversionService = new DefaultConversionService ();
645
648
Map <String , Integer > hashMap = new LinkedHashMap <String , Integer >();
646
649
hashMap .put ("1" , 1 );
@@ -650,15 +653,15 @@ public void convertHashMapValuesToList() throws Exception {
650
653
}
651
654
652
655
@ Test
653
- public void removeConvertible () throws Exception {
656
+ public void removeConvertible () {
654
657
conversionService .addConverter (new ColorConverter ());
655
658
assertTrue (conversionService .canConvert (String .class , Color .class ));
656
659
conversionService .removeConvertible (String .class , Color .class );
657
660
assertFalse (conversionService .canConvert (String .class , Color .class ));
658
661
}
659
662
660
663
@ Test
661
- public void conditionalConverter () throws Exception {
664
+ public void conditionalConverter () {
662
665
GenericConversionService conversionService = new GenericConversionService ();
663
666
MyConditionalConverter converter = new MyConditionalConverter ();
664
667
conversionService .addConverter (new ColorConverter ());
@@ -668,7 +671,7 @@ public void conditionalConverter() throws Exception {
668
671
}
669
672
670
673
@ Test
671
- public void conditionalConverterFactory () throws Exception {
674
+ public void conditionalConverterFactory () {
672
675
GenericConversionService conversionService = new GenericConversionService ();
673
676
MyConditionalConverterFactory converter = new MyConditionalConverterFactory ();
674
677
conversionService .addConverter (new ColorConverter ());
@@ -679,32 +682,29 @@ public void conditionalConverterFactory() throws Exception {
679
682
}
680
683
681
684
@ Test
682
- public void shouldNotSuportNullConvertibleTypesFromNonConditionalGenericConverter ()
683
- throws Exception {
685
+ public void shouldNotSuportNullConvertibleTypesFromNonConditionalGenericConverter () {
684
686
GenericConversionService conversionService = new GenericConversionService ();
685
687
GenericConverter converter = new GenericConverter () {
686
-
687
688
@ Override
688
689
public Set <ConvertiblePair > getConvertibleTypes () {
689
690
return null ;
690
691
}
691
-
692
692
@ Override
693
- public Object convert (Object source , TypeDescriptor sourceType ,
694
- TypeDescriptor targetType ) {
693
+ public Object convert (Object source , TypeDescriptor sourceType , TypeDescriptor targetType ) {
695
694
return null ;
696
695
}
697
696
};
698
697
try {
699
698
conversionService .addConverter (converter );
700
699
fail ("Did not throw" );
701
- } catch (IllegalStateException e ) {
702
- assertEquals ("Only conditional converters may return null convertible types" , e .getMessage ());
700
+ }
701
+ catch (IllegalStateException ex ) {
702
+ assertEquals ("Only conditional converters may return null convertible types" , ex .getMessage ());
703
703
}
704
704
}
705
705
706
706
@ Test
707
- public void conditionalConversionForAllTypes () throws Exception {
707
+ public void conditionalConversionForAllTypes () {
708
708
GenericConversionService conversionService = new GenericConversionService ();
709
709
MyConditionalGenericConverter converter = new MyConditionalGenericConverter ();
710
710
conversionService .addConverter (converter );
@@ -717,7 +717,7 @@ public void conditionalConversionForAllTypes() throws Exception {
717
717
}
718
718
719
719
@ Test
720
- public void convertOptimizeArray () throws Exception {
720
+ public void convertOptimizeArray () {
721
721
// SPR-9566
722
722
GenericConversionService conversionService = new DefaultConversionService ();
723
723
byte [] byteArray = new byte [] { 1 , 2 , 3 };
@@ -726,7 +726,7 @@ public void convertOptimizeArray() throws Exception {
726
726
}
727
727
728
728
@ Test
729
- public void convertCannotOptimizeArray () throws Exception {
729
+ public void convertCannotOptimizeArray () {
730
730
GenericConversionService conversionService = new GenericConversionService ();
731
731
conversionService .addConverter (new Converter <Byte , Byte >() {
732
732
@ Override
@@ -766,15 +766,15 @@ public void convertNullAnnotatedStringToString() throws Exception {
766
766
conversionService .convert (source , sourceType , targetType );
767
767
}
768
768
769
+
769
770
@ ExampleAnnotation
770
771
public String annotatedString ;
771
772
772
773
@ Retention (RetentionPolicy .RUNTIME )
773
774
public static @interface ExampleAnnotation {
774
775
}
775
776
776
- private static class MyConditionalConverter implements Converter <String , Color >,
777
- ConditionalConverter {
777
+ private static class MyConditionalConverter implements Converter <String , Color >, ConditionalConverter {
778
778
779
779
private int matchAttempts = 0 ;
780
780
@@ -850,23 +850,26 @@ public int getNestedMatchAttempts() {
850
850
}
851
851
852
852
interface MyEnumInterface {
853
+
853
854
String getCode ();
854
855
}
855
856
856
857
public static enum MyEnum implements MyEnumInterface {
858
+
857
859
A {
858
860
@ Override
859
861
public String getCode () {
860
862
return "1" ;
861
863
}
862
- };
864
+ }
863
865
}
864
866
865
- private static class MyEnumInterfaceToStringConverter <T extends MyEnumInterface >
866
- implements Converter < T , String > {
867
+ private static class MyEnumInterfaceToStringConverter <T extends MyEnumInterface > implements Converter < T , String > {
868
+
867
869
@ Override
868
870
public String convert (T source ) {
869
871
return source .getCode ();
870
872
}
871
873
}
874
+
872
875
}
0 commit comments