1
1
/*
2
- * Copyright 2002-2014 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.
@@ -71,7 +71,7 @@ public void testStringToCharacterEmptyString() {
71
71
assertEquals (null , conversionService .convert ("" , Character .class ));
72
72
}
73
73
74
- @ Test (expected = ConversionFailedException .class )
74
+ @ Test (expected = ConversionFailedException .class )
75
75
public void testStringToCharacterInvalidString () {
76
76
conversionService .convert ("invalid" , Character .class );
77
77
}
@@ -108,7 +108,7 @@ public void testStringToBooleanEmptyString() {
108
108
assertEquals (null , conversionService .convert ("" , Boolean .class ));
109
109
}
110
110
111
- @ Test (expected = ConversionFailedException .class )
111
+ @ Test (expected = ConversionFailedException .class )
112
112
public void testStringToBooleanInvalidString () {
113
113
conversionService .convert ("invalid" , Boolean .class );
114
114
}
@@ -267,36 +267,11 @@ public void testNumberToNumber() {
267
267
assertEquals (Long .valueOf (1 ), conversionService .convert (1 , Long .class ));
268
268
}
269
269
270
- @ Test (expected = ConversionFailedException .class )
270
+ @ Test (expected = ConversionFailedException .class )
271
271
public void testNumberToNumberNotSupportedNumber () {
272
272
conversionService .convert (1 , CustomNumber .class );
273
273
}
274
274
275
- @ SuppressWarnings ("serial" )
276
- public static class CustomNumber extends Number {
277
-
278
- @ Override
279
- public double doubleValue () {
280
- return 0 ;
281
- }
282
-
283
- @ Override
284
- public float floatValue () {
285
- return 0 ;
286
- }
287
-
288
- @ Override
289
- public int intValue () {
290
- return 0 ;
291
- }
292
-
293
- @ Override
294
- public long longValue () {
295
- return 0 ;
296
- }
297
-
298
- }
299
-
300
275
@ Test
301
276
public void testNumberToCharacter () {
302
277
assertEquals (Character .valueOf ('A' ), conversionService .convert (65 , Character .class ));
@@ -827,7 +802,7 @@ public void convertObjectToOptional() {
827
802
TypeDescriptor descriptor = new TypeDescriptor (parameter );
828
803
Object actual = conversionService .convert ("1,2,3" , TypeDescriptor .valueOf (String .class ), descriptor );
829
804
assertEquals (Optional .class , actual .getClass ());
830
- assertEquals (Arrays .asList (1 ,2 , 3 ), ((Optional <List <Integer >>) actual ).get ());
805
+ assertEquals (Arrays .asList (1 , 2 , 3 ), ((Optional <List <Integer >>) actual ).get ());
831
806
}
832
807
833
808
@ Test
@@ -837,6 +812,38 @@ public void convertObjectToOptionalNull() {
837
812
assertSame (Optional .empty (), conversionService .convert (null , Optional .class ));
838
813
}
839
814
815
+ @ Test
816
+ public void convertExistingOptional () {
817
+ assertSame (Optional .empty (), conversionService .convert (Optional .empty (), TypeDescriptor .valueOf (Object .class ),
818
+ TypeDescriptor .valueOf (Optional .class )));
819
+ assertSame (Optional .empty (), conversionService .convert (Optional .empty (), Optional .class ));
820
+ }
821
+
822
+
823
+ @ SuppressWarnings ("serial" )
824
+ public static class CustomNumber extends Number {
825
+
826
+ @ Override
827
+ public double doubleValue () {
828
+ return 0 ;
829
+ }
830
+
831
+ @ Override
832
+ public float floatValue () {
833
+ return 0 ;
834
+ }
835
+
836
+ @ Override
837
+ public int intValue () {
838
+ return 0 ;
839
+ }
840
+
841
+ @ Override
842
+ public long longValue () {
843
+ return 0 ;
844
+ }
845
+ }
846
+
840
847
841
848
public static class TestEntity {
842
849
0 commit comments