11
11
import java .util .Map ;
12
12
import java .util .Properties ;
13
13
14
- import org .junit .Test ;
14
+ import org .junit .jupiter . api . Test ;
15
15
import org .python .core .PyDictionary ;
16
16
import org .python .core .PyLong ;
17
17
import org .python .core .PyObject ;
18
18
import org .python .core .PyString ;
19
19
import org .python .core .PyTuple ;
20
20
21
- import static org .junit .Assert .*;
21
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
22
+ import static org .junit .jupiter .api .Assertions .assertNull ;
23
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
24
+ import static org .powermock .utils .Asserts .assertNotNull ;
22
25
23
26
public class TypeUtilsTest {
24
27
@ Test
25
28
public void convertToType () throws Exception {
26
- assertEquals ("Integer conversion failed" , 123 , TypeUtils .convertToType ("integer" , "123" ));
27
- assertEquals ("Long conversion failed" , 123L , TypeUtils .convertToType ( "long" , "123" ));
28
- assertEquals ("Double conversion failed" , 123.45D , TypeUtils .convertToType ( "double" , "123.45" ));
29
- assertEquals ("Boolean conversion failed" , " true" , TypeUtils .convertToType ( "boolean" , "true" ));
30
- assertEquals ("Boolean conversion failed" , " false" , TypeUtils .convertToType ( "boolean" , 0 ));
29
+ assertEquals (123 , TypeUtils .convertToType ("integer" , "123" ), "Integer conversion failed" );
30
+ assertEquals (123L , TypeUtils .convertToType ( "long" , "123" ), "Long conversion failed" );
31
+ assertEquals (123.45D , TypeUtils .convertToType ( "double" , "123.45" ), "Double conversion failed" );
32
+ assertEquals ("true" , TypeUtils .convertToType ( "boolean" , "true" ), "Boolean conversion failed" );
33
+ assertEquals ("false" , TypeUtils .convertToType ( "boolean" , 0 ), "Boolean conversion failed" );
31
34
32
- assertEquals ("String conversion failed" , " 222" , TypeUtils .convertToType ( "string" , 222 ));
33
- assertEquals ("Password conversion failed" , " abcdef" , TypeUtils .convertToType ( "password" , "abcdef" ));
34
- assertEquals ("String conversion failed" , " 222" , TypeUtils .convertToType ( "string" , "222" .toCharArray ()));
35
+ assertEquals ("222" , TypeUtils .convertToType ( "string" , 222 ), "String conversion failed" );
36
+ assertEquals ("abcdef" , TypeUtils .convertToType ( "password" , "abcdef" ), "Password conversion failed" );
37
+ assertEquals ("222" , TypeUtils .convertToType ( "string" , "222" .toCharArray ()), "String conversion failed" );
35
38
36
39
String [] strings = {"one" , "two" , "three" };
37
- assertEquals ("List conversion failed" ,
38
- Arrays .asList (strings ),
39
- TypeUtils .convertToType ( "list" , "one, two, three" ));
40
+ assertEquals (Arrays .asList (strings ), TypeUtils .convertToType ( "list" , "one, two, three" ), "List conversion failed" );
40
41
}
41
42
42
- @ Test ( expected = AliasException . class )
43
- public void convertToTypeInvalidStringType () throws Exception {
44
- TypeUtils .convertToType ( "fancy" , "123" );
43
+ @ Test
44
+ public void convertToTypeInvalidStringType () {
45
+ assertThrows ( AliasException . class , () -> TypeUtils .convertToType ("fancy" , "123" ) );
45
46
}
46
47
47
- @ Test ( expected = AliasException . class )
48
- public void convertToTypeInvalidPrimitiveType () throws Exception {
49
- TypeUtils .convertToType ( int .class , "123" );
48
+ @ Test
49
+ public void convertToTypeInvalidPrimitiveType () {
50
+ assertThrows ( AliasException . class , () -> TypeUtils .convertToType (int .class , "123" ) );
50
51
}
51
52
52
- @ Test ( expected = AliasException . class )
53
- public void convertInvalidInteger () throws Exception {
54
- TypeUtils .convertToType (Integer .class , "this is a string" );
53
+ @ Test
54
+ public void convertInvalidInteger () {
55
+ assertThrows ( AliasException . class , () -> TypeUtils .convertToType (Integer .class , "this is a string" ) );
55
56
}
56
57
57
58
@ Test
58
59
public void convertToTypeNullTest () throws Exception {
59
- assertEquals ( "String null conversion failed" , null , TypeUtils .convertToType ( String .class , null )); ;
60
- assertEquals ( "Character null conversion failed" , null , TypeUtils .convertToType ( Character .class , "" )); ;
60
+ assertNull ( TypeUtils .convertToType (String .class , null ), "String null conversion failed" ) ;
61
+ assertNull ( TypeUtils .convertToType (Character .class , "" ), "Character null conversion failed" ) ;
61
62
}
62
63
63
64
@ Test
@@ -95,10 +96,10 @@ public void convertStringToMap() throws Exception {
95
96
expected .put ("key2" , "value2" );
96
97
expected .put ("key3" , "value3" );
97
98
expected .put ("key4" , "value4" );
98
- assertEquals ("String to Map conversion failed" , expected , TypeUtils .convertStringToMap (str , "," ));
99
- assertEquals ("JSON to Map conversion failed" , expected , TypeUtils .convertStringToMap (json , "," ));
100
- assertEquals ("String to Map conversion failed" , expected , TypeUtils .convertToType (Map .class , str , "," ));
101
- assertEquals ("Map to Map conversion failed" , expected , TypeUtils .convertToType (Map .class , expected ));
99
+ assertEquals (expected , TypeUtils .convertStringToMap (str , "," ), "String to Map conversion failed" );
100
+ assertEquals (expected , TypeUtils .convertStringToMap (json , "," ), "JSON to Map conversion failed" );
101
+ assertEquals (expected , TypeUtils .convertToType (Map .class , str , "," ), "String to Map conversion failed" );
102
+ assertEquals (expected , TypeUtils .convertToType (Map .class , expected ), "Map to Map conversion failed" );
102
103
}
103
104
104
105
@ Test
@@ -108,21 +109,20 @@ public void convertListToArray() throws Exception {
108
109
list .add ("two" );
109
110
list .add ("three" );
110
111
Object result = TypeUtils .convertToType (String [].class , list );
111
- if ( result == null )
112
- fail ("convertToType returned null for List conversion to String[]" );
113
- assertEquals ("List conversion failed" , String [].class , result .getClass ());
112
+ assertNotNull (result , "convertToType returned null for List conversion to String[]" );
113
+ assertEquals (String [].class , result .getClass (), "List conversion failed" );
114
114
115
115
}
116
116
117
117
@ Test
118
118
public void convertToList () throws Exception {
119
119
String [] array = { "one" , "two" , "three" };
120
120
List <String > expected = Arrays .asList (array );
121
- assertEquals ("List from array conversion failed" , expected , TypeUtils .convertToType (List .class , array ));
121
+ assertEquals (expected , TypeUtils .convertToType (List .class , array ), "List from array conversion failed" );
122
122
String str = "one, two, three" ;
123
- assertEquals ("List from string conversion failed" , expected , TypeUtils .convertToType (List .class , str ));
123
+ assertEquals (expected , TypeUtils .convertToType (List .class , str ), "List from string conversion failed" );
124
124
String [] empty = {};
125
- assertEquals ( "List from empty list conversion failed" , null , TypeUtils . convertToType ( List . class , empty ) );
125
+ assertNull ( TypeUtils . convertToType ( List . class , empty ), "List from empty list conversion failed" );
126
126
}
127
127
128
128
@ Test
@@ -132,12 +132,12 @@ public void convertToProperties() throws Exception {
132
132
Properties expected = new Properties ();
133
133
expected .put ("key1" , "value1" );
134
134
expected .put ("key2" , "value2" );
135
- assertEquals ("Properties from String failed" , expected , TypeUtils .convertToType (Properties .class , str , ";" ));
135
+ assertEquals (expected , TypeUtils .convertToType (Properties .class , str , ";" ), "Properties from String failed" );
136
136
137
137
Map <String , String > map = new HashMap <>();
138
138
map .put ("key1" , "value1" );
139
139
map .put ("key2" , "value2" );
140
- assertEquals ("Properties from Map failed" , expected , TypeUtils .convertToType (Properties .class , map , ";" ));
140
+ assertEquals (expected , TypeUtils .convertToType (Properties .class , map , ";" ), "Properties from Map failed" );
141
141
142
142
}
143
143
@@ -154,6 +154,6 @@ public void convertDictToProperties() throws Exception {
154
154
expected .put ("mail.smtp.port" , "25" );
155
155
expected .put ("mail.smtp.host" , "192.168.56.1" );
156
156
157
- assertEquals ("Properties from dict failed" , expected , result );
157
+ assertEquals (expected , result , "Properties from dict failed" );
158
158
}
159
159
}
0 commit comments