Skip to content

Commit 0b69e82

Browse files
committed
Migrate resources utils tests to JUnit 5 #903
Migrates the tests in org.eclipse.core.tests.internal.utils to JUnit 5. - Exchange JUnit 4 test annotations - Replace JUnit 4 assertions with JUnit 5 or AssertJ assertions Contributes to #903
1 parent b432795 commit 0b69e82

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/FileUtilTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.tests.internal.utils;
1515

16-
import static org.junit.Assert.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
1717

1818
import java.net.URI;
1919
import org.eclipse.core.filesystem.EFS;
2020
import org.eclipse.core.filesystem.URIUtil;
2121
import org.eclipse.core.internal.utils.FileUtil;
2222
import org.eclipse.core.runtime.IPath;
2323
import org.eclipse.core.tests.harness.FileSystemHelper;
24-
import org.junit.After;
25-
import org.junit.Before;
26-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

2828
/**
2929
* Tests for {@link FileUtil} class.
3030
*/
3131
public class FileUtilTest {
3232
private IPath baseTestDir;
3333

34-
@Before
34+
@BeforeEach
3535
public void setUp() throws Exception {
3636
baseTestDir = FileSystemHelper.getRandomLocation();
3737
baseTestDir.toFile().mkdirs();
3838
}
3939

40-
@After
40+
@AfterEach
4141
public void tearDown() throws Exception {
4242
FileSystemHelper.clear(baseTestDir.toFile());
4343
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java

+23-25
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
1818
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;
2321

2422
import java.util.Collection;
2523
import java.util.HashMap;
2624
import java.util.Map;
2725
import java.util.Set;
2826
import org.eclipse.core.internal.utils.ObjectMap;
29-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
3028

3129
public class ObjectMapTest {
3230
private static final int MAXIMUM = 100;
@@ -44,17 +42,17 @@ public void testPut() {
4442
for (int i = 0; i < values.length; i++) {
4543
Integer key = Integer.valueOf(i);
4644
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);
5048
}
5149

5250
// make sure they are all still there
53-
assertEquals("3.0", MAXIMUM, map.size());
51+
assertThat(map).hasSize(MAXIMUM);
5452
for (int i = 0; i < values.length; i++) {
5553
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);
5856
}
5957
}
6058

@@ -72,18 +70,18 @@ public void testRemove() {
7270

7371
// remove each element
7472
for (int i = MAXIMUM - 1; i >= 0; i--) {
75-
Object key = Integer.valueOf(i);
73+
Integer key = Integer.valueOf(i);
7674
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);
7977
// check that the others still exist
8078
for (int j = 0; j < i; j++) {
81-
assertTrue("2.2." + j, map.containsKey(Integer.valueOf(j)));
79+
assertThat(map).containsKey(Integer.valueOf(j));
8280
}
8381
}
8482

8583
// all gone?
86-
assertEquals("3.0", 0, map.size());
84+
assertThat(map).isEmpty();
8785
}
8886

8987
@Test
@@ -92,14 +90,14 @@ public void testContains() {
9290
ObjectMap<Integer, Object> map = populateMap(values);
9391

9492
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]);
9795
}
9896

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());
103101
}
104102

105103
@Test
@@ -109,7 +107,7 @@ public void testValues() {
109107

110108
Collection<Object> result = map.values();
111109
for (int i = 0; i < MAXIMUM; i++) {
112-
assertTrue("2.0." + i, result.contains(values[i]));
110+
assertThat(result).contains(values[i]);
113111
}
114112
}
115113

@@ -118,7 +116,7 @@ public void testKeySet() {
118116
Object[] values = new Object[MAXIMUM];
119117
ObjectMap<Integer, Object> map = populateMap(values);
120118
Set<Integer> keys = map.keySet();
121-
assertEquals("1.0", MAXIMUM, keys.size());
119+
assertThat(keys).hasSize(MAXIMUM);
122120
}
123121

124122
@Test
@@ -127,7 +125,7 @@ public void testEntrySet() {
127125
ObjectMap<Integer, Object> map = populateMap(values);
128126
Set<Map.Entry<Integer, Object>> entries = map.entrySet();
129127
for (int i = 0; i < MAXIMUM; i++) {
130-
assertTrue("1.0." + i, contains(entries, values[i]));
128+
assertTrue(contains(entries, values[i]), "" + i);
131129
}
132130
}
133131

0 commit comments

Comments
 (0)