16
16
17
17
import static org .assertj .core .api .Assertions .assertThat ;
18
18
import static org .eclipse .core .tests .resources .ResourceTestUtil .createRandomString ;
19
- import static org .junit .Assert .assertEquals ;
20
- import static org .junit .Assert .assertFalse ;
21
- import static org .junit .Assert .assertNotNull ;
22
- import static org .junit .Assert .assertTrue ;
19
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
20
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
23
21
24
22
import java .util .Collection ;
25
23
import java .util .HashMap ;
26
24
import java .util .Map ;
27
25
import java .util .Set ;
28
26
import org .eclipse .core .internal .utils .ObjectMap ;
29
- import org .junit .Test ;
27
+ import org .junit .jupiter . api . Test ;
30
28
31
29
public class ObjectMapTest {
32
30
private static final int MAXIMUM = 100 ;
@@ -44,17 +42,17 @@ public void testPut() {
44
42
for (int i = 0 ; i < values .length ; i ++) {
45
43
Integer key = Integer .valueOf (i );
46
44
map .put (key , values [i ]);
47
- assertTrue ( "2.0." + i , map .containsKey (key ) );
48
- assertTrue ( "2.1." + i , map .containsValue (values [i ]) );
49
- assertEquals ( "2.2." + i , i + 1 , map . size () );
45
+ assertThat ( map ) .containsKey (key );
46
+ assertThat ( map ) .containsValue (values [i ]);
47
+ assertThat ( map ). hasSize ( i + 1 );
50
48
}
51
49
52
50
// make sure they are all still there
53
- assertEquals ( "3.0" , MAXIMUM , map . size () );
51
+ assertThat ( map ). hasSize ( MAXIMUM );
54
52
for (int i = 0 ; i < values .length ; i ++) {
55
53
Integer key = Integer .valueOf (i );
56
- assertTrue ( "3.1." + i , map .containsKey (key ) );
57
- assertNotNull ("3.2." + i , map .get (key ));
54
+ assertThat ( map ) .containsKey (key );
55
+ assertNotNull (map .get (key ), "" + i );
58
56
}
59
57
}
60
58
@@ -72,18 +70,18 @@ public void testRemove() {
72
70
73
71
// remove each element
74
72
for (int i = MAXIMUM - 1 ; i >= 0 ; i --) {
75
- Object key = Integer .valueOf (i );
73
+ Integer key = Integer .valueOf (i );
76
74
map .remove (key );
77
- assertTrue ( "2.0." + i , ! map . containsKey (key ) );
78
- assertEquals ( "2.1," + i , i , map . size () );
75
+ assertThat ( map ). doesNotContainKey (key );
76
+ assertThat ( map ). hasSize ( i );
79
77
// check that the others still exist
80
78
for (int j = 0 ; j < i ; j ++) {
81
- assertTrue ( "2.2." + j , map .containsKey (Integer .valueOf (j ) ));
79
+ assertThat ( map ) .containsKey (Integer .valueOf (j ));
82
80
}
83
81
}
84
82
85
83
// all gone?
86
- assertEquals ( "3.0" , 0 , map . size () );
84
+ assertThat ( map ). isEmpty ( );
87
85
}
88
86
89
87
@ Test
@@ -92,14 +90,14 @@ public void testContains() {
92
90
ObjectMap <Integer , Object > map = populateMap (values );
93
91
94
92
for (int i = 0 ; i < MAXIMUM ; i ++) {
95
- assertTrue ( "2.0." + i , map .containsKey (Integer .valueOf (i ) ));
96
- assertTrue ( "2.1." + i , map .containsValue (values [i ]) );
93
+ assertThat ( map ) .containsKey (Integer .valueOf (i ));
94
+ assertThat ( map ) .containsValue (values [i ]);
97
95
}
98
96
99
- assertFalse ( "3.0" , map . containsKey (Integer .valueOf (MAXIMUM + 1 ) ));
100
- assertFalse ( "3.1" , map . containsKey (Integer .valueOf (-1 ) ));
101
- assertFalse ( "3.2" , map . containsValue (null ) );
102
- assertFalse ( "3.3" , map . containsValue (createRandomString () ));
97
+ assertThat ( map ). doesNotContainKey (Integer .valueOf (MAXIMUM + 1 ));
98
+ assertThat ( map ). doesNotContainKey (Integer .valueOf (-1 ));
99
+ assertThat ( map ). doesNotContainValue (null );
100
+ assertThat ( map ). doesNotContainValue (createRandomString ());
103
101
}
104
102
105
103
@ Test
@@ -109,7 +107,7 @@ public void testValues() {
109
107
110
108
Collection <Object > result = map .values ();
111
109
for (int i = 0 ; i < MAXIMUM ; i ++) {
112
- assertTrue ( "2.0." + i , result .contains (values [i ]) );
110
+ assertThat ( result ) .contains (values [i ]);
113
111
}
114
112
}
115
113
@@ -118,7 +116,7 @@ public void testKeySet() {
118
116
Object [] values = new Object [MAXIMUM ];
119
117
ObjectMap <Integer , Object > map = populateMap (values );
120
118
Set <Integer > keys = map .keySet ();
121
- assertEquals ( "1.0" , MAXIMUM , keys . size () );
119
+ assertThat ( keys ). hasSize ( MAXIMUM );
122
120
}
123
121
124
122
@ Test
@@ -127,7 +125,7 @@ public void testEntrySet() {
127
125
ObjectMap <Integer , Object > map = populateMap (values );
128
126
Set <Map .Entry <Integer , Object >> entries = map .entrySet ();
129
127
for (int i = 0 ; i < MAXIMUM ; i ++) {
130
- assertTrue ("1.0." + i , contains (entries , values [i ]));
128
+ assertTrue (contains (entries , values [i ]), "" + i );
131
129
}
132
130
}
133
131
0 commit comments