5
5
package oracle .weblogic .deploy .create ;
6
6
7
7
import org .junit .jupiter .api .Test ;
8
+ import org .junit .jupiter .api .function .Executable ;
8
9
9
10
import static org .junit .jupiter .api .Assertions .assertEquals ;
10
11
import static org .junit .jupiter .api .Assertions .assertThrows ;
14
15
public class CustomBeanUtilsTest {
15
16
16
17
@ Test
17
- public void testSimpleTypes () {
18
- Object result ;
19
-
20
- // boolean to boolean
21
- result = CustomBeanUtils .convertValue (Boolean .TRUE , Boolean .class );
18
+ public void testBooleanValueToBooleanConversion () {
19
+ Object result = CustomBeanUtils .convertValue (Boolean .TRUE , Boolean .class );
22
20
assertEquals (Boolean .TRUE , result , "Boolean result does not match" );
21
+ }
23
22
24
- // string to boolean
25
- result = CustomBeanUtils .convertValue ("true" , Boolean .class );
23
+ @ Test
24
+ public void testStringToBooleanConversion () {
25
+ Object result = CustomBeanUtils .convertValue ("true" , Boolean .class );
26
26
assertEquals (Boolean .TRUE , result , "String to boolean result does not match" );
27
+ }
27
28
28
- // character to character
29
- result = CustomBeanUtils .convertValue ('x' , Character .class );
29
+ @ Test
30
+ public void testCharacterConversion () {
31
+ Object result = CustomBeanUtils .convertValue ('x' , Character .class );
30
32
assertEquals ('x' , result , "Character result does not match" );
33
+ }
31
34
32
- // string to character
33
- result = CustomBeanUtils .convertValue ("x" , Character .class );
35
+ @ Test
36
+ public void testStringToCharacterConversion () {
37
+ Object result = CustomBeanUtils .convertValue ("x" , Character .class );
34
38
assertEquals ('x' , result , "String to character result does not match" );
39
+ }
35
40
36
- // string to double
37
- result = CustomBeanUtils .convertValue ("123.4" , Double .class );
38
- assertEquals (123.4 , result , "String to double result does not match" );
39
-
40
- // string to float
41
- result = CustomBeanUtils .convertValue ("123.4" , Float .class );
42
- assertEquals (123.4f , result , "String to float result does not match" );
43
-
44
- // string to integer
45
- result = CustomBeanUtils .convertValue ("1234" , Integer .class );
41
+ @ Test
42
+ public void testStringToIntegerConversion () {
43
+ Object result = CustomBeanUtils .convertValue ("1234" , Integer .class );
46
44
assertEquals (1234 , result , "String to integer does not match" );
45
+ }
47
46
48
- // string to long
49
- result = CustomBeanUtils .convertValue ("1234" , Long .class );
47
+ @ Test
48
+ public void testStringToLongConversion () {
49
+ Object result = CustomBeanUtils .convertValue ("1234" , Long .class );
50
50
assertEquals (1234L , result , "Boolean text result does not match" );
51
+ }
52
+
53
+ @ Test
54
+ public void testStringToFloatConversion () {
55
+ Object result = CustomBeanUtils .convertValue ("123.4" , Float .class );
56
+ assertEquals (123.4f , result , "String to float result does not match" );
57
+ }
58
+
59
+ @ Test
60
+ public void testStringToDoubleConversion () {
61
+ Object result = CustomBeanUtils .convertValue ("123.4" , Double .class );
62
+ assertEquals (123.4 , result , "String to double result does not match" );
63
+ }
51
64
52
- // string to string
65
+ @ Test
66
+ public void testStringToStringConversion () {
53
67
String sourceText = "textValue" ;
54
- result = CustomBeanUtils .convertValue (sourceText , String .class );
68
+ Object result = CustomBeanUtils .convertValue (sourceText , String .class );
55
69
assertEquals (sourceText , result , "String result does not match" );
56
-
57
- // fail with bad numeric value
58
- assertThrows (IllegalArgumentException .class , () -> CustomBeanUtils .convertValue ("1234X" , Integer .class ));
59
70
}
60
71
61
72
@ Test
62
- public void testArrayTypes () {
63
- Object result ;
73
+ public void testBadStringToIntegerConversionThrowsException () {
74
+ assertThrows (IllegalArgumentException .class , new Executable () {
75
+ @ Override
76
+ public void execute () throws Throwable {
77
+ CustomBeanUtils .convertValue ("1234X" , Integer .class );
78
+ }
79
+ });
80
+ }
64
81
65
- // string[] to string[]
82
+ @ Test
83
+ public void testStringArrayToStringArrayConversion () {
66
84
String [] sourceTexts = { "textValue" , "textValue2" };
67
- result = CustomBeanUtils .convertValue (sourceTexts , String [].class );
85
+ Object result = CustomBeanUtils .convertValue (sourceTexts , String [].class );
68
86
assertTrue (arraysMatch (sourceTexts , (String []) result ), "String array result does not match" );
87
+ }
69
88
70
- // delimited string to string[]
89
+ @ Test
90
+ public void testDelimitedStringToStringArrayConversion () {
71
91
String sourceDelimited = "textValue,textValue2" ;
72
- result = CustomBeanUtils .convertValue (sourceDelimited , String [].class );
92
+ String [] sourceTexts = { "textValue" , "textValue2" };
93
+
94
+ Object result = CustomBeanUtils .convertValue (sourceDelimited , String [].class );
73
95
assertTrue (arraysMatch (sourceTexts , (String []) result ), "Delimited string array result does not match" );
96
+ }
74
97
75
- // integer[] to integer[]
98
+ @ Test
99
+ public void testIntegerArrayToIntegerArrayConversion () {
76
100
Integer [] sourceInts = { 123 , 456 };
77
- result = CustomBeanUtils .convertValue (sourceInts , Integer [].class );
101
+ Object result = CustomBeanUtils .convertValue (sourceInts , Integer [].class );
78
102
assertTrue (arraysMatch (sourceInts , (Integer []) result ), "String array result does not match" );
103
+ }
79
104
80
- // string[] to integer[]
105
+ @ Test
106
+ public void testStringArrayToIntegerArrayConversion () {
81
107
String [] sourceTextInts = { "123" , "456" };
82
- result = CustomBeanUtils .convertValue (sourceTextInts , Integer [].class );
108
+ Integer [] sourceInts = { 123 , 456 };
109
+
110
+ Object result = CustomBeanUtils .convertValue (sourceTextInts , Integer [].class );
83
111
assertTrue (arraysMatch (sourceInts , (Integer []) result ), "Integer string array result does not match" );
112
+ }
84
113
85
- // delimited string to string[]
114
+ @ Test
115
+ public void testDelimitedStringToIntegerArrayConversion () {
86
116
String sourceDelimitedInts = "123,456" ;
87
- result = CustomBeanUtils .convertValue (sourceDelimitedInts , Integer [].class );
117
+ Integer [] sourceInts = { 123 , 456 };
118
+
119
+ Object result = CustomBeanUtils .convertValue (sourceDelimitedInts , Integer [].class );
88
120
assertTrue (arraysMatch (sourceInts , (Integer []) result ), "Delimited integer array result does not match" );
89
121
}
90
122
@@ -98,7 +130,6 @@ private boolean arraysMatch(Object[] array1, Object[] array2) {
98
130
return false ;
99
131
}
100
132
}
101
-
102
133
return true ;
103
134
}
104
135
}
0 commit comments