Skip to content

Commit 4dc1212

Browse files
committed
Migrate resources content tests to JUnit 5 #903
Migrates the tests in org.eclipse.core.tests.resources.content to JUnit 5 by replacing according JUnit annotations and migrating assertions. Contributes to #903
1 parent 30240f7 commit 4dc1212

File tree

8 files changed

+173
-177
lines changed

8 files changed

+173
-177
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentDescriptionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
package org.eclipse.core.tests.resources.content;
1515

1616
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertNull;
20-
import static org.junit.Assert.assertThrows;
21-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import org.eclipse.core.internal.content.ContentDescription;
2424
import org.eclipse.core.internal.content.ContentType;
2525
import org.eclipse.core.internal.content.ContentTypeHandler;
2626
import org.eclipse.core.runtime.Platform;
2727
import org.eclipse.core.runtime.QualifiedName;
2828
import org.eclipse.core.runtime.content.IContentDescription;
29-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3030

3131
public class ContentDescriptionTest {
3232
private static final String CT_VOID = PI_RESOURCES_TESTS + '.' + "void";

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java

Lines changed: 124 additions & 124 deletions
Large diffs are not rendered by default.

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
package org.eclipse.core.tests.resources.content;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertNotEquals;
19-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.io.ByteArrayInputStream;
2222
import java.io.IOException;
2323
import java.io.InputStream;
2424
import org.eclipse.core.internal.content.LazyInputStream;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
/**
2828
* Tests for {@link LazyInputStream}.
@@ -169,7 +169,7 @@ public void testVariedContent() throws IOException {
169169
ByteArrayInputStream underlying = new ByteArrayInputStream(contents);
170170
OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7);
171171
for (int i = 0; i < VARIOUS_INTS.length; i++) {
172-
assertEquals(i + "", VARIOUS_INTS[i], stream.read());
172+
assertEquals(VARIOUS_INTS[i], stream.read(), i + "");
173173
}
174174
stream.close();
175175
}
@@ -196,7 +196,7 @@ public int read(byte[] b, int off, int len) throws IOException {
196196

197197
objectUnderTest.skip(1);
198198

199-
assertTrue("The buffer size suffered an Overflow", objectUnderTest.getBufferSize() > Integer.MAX_VALUE);
199+
assertTrue(objectUnderTest.getBufferSize() > Integer.MAX_VALUE, "The buffer size suffered an Overflow");
200200
}
201201

202202
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
package org.eclipse.core.tests.resources.content;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.io.CharArrayReader;
2222
import java.io.IOException;
2323
import java.io.Reader;
2424
import org.eclipse.core.internal.content.LazyReader;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
/**
2828
* Tests for {@link LazyReader}.
@@ -179,7 +179,7 @@ public void close() throws IOException {
179179

180180
objectUnderTest.skip(1);
181181

182-
assertTrue("The buffer size suffered an Overflow", objectUnderTest.getBufferSize() > Integer.MAX_VALUE);
182+
assertTrue(objectUnderTest.getBufferSize() > Integer.MAX_VALUE, "The buffer size suffered an Overflow");
183183
}
184184
}
185185
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
package org.eclipse.core.tests.resources.content;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertNull;
20-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import org.eclipse.core.internal.content.ContentTypeManager;
2323
import org.eclipse.core.internal.preferences.EclipsePreferences;
@@ -30,18 +30,14 @@
3030
import org.eclipse.core.runtime.content.IContentTypeSettings;
3131
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
3232
import org.eclipse.core.runtime.preferences.IScopeContext;
33-
import org.junit.Rule;
34-
import org.junit.Test;
35-
import org.junit.rules.TestName;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.TestInfo;
3635

3736
/**
3837
* Tests content type matcher with a non-default context for user preferences.
3938
*/
4039
public class SpecificContextTest {
4140

42-
@Rule
43-
public TestName name = new TestName();
44-
4541
/**
4642
* A minimal scope implementation.
4743
*/
@@ -70,25 +66,26 @@ public IEclipsePreferences getNode(String qualifier) {
7066
}
7167

7268
@Test
73-
public void testContentTypeLookup() throws CoreException {
69+
public void testContentTypeLookup(TestInfo testInfo) throws CoreException {
70+
String testName = testInfo.getDisplayName();
7471
IContentTypeManager global = Platform.getContentTypeManager();
7572
final SingleNodeScope scope = new SingleNodeScope();
7673
IContentTypeMatcher local = global.getMatcher(new LocalSelectionPolicy(), scope);
7774
IContentType textContentType = global.getContentType(Platform.PI_RUNTIME + '.' + "text");
7875
// added "<test case name>.global" to the text content type as a global file
7976
// spec
80-
textContentType.addFileSpec(name.getMethodName() + ".global", IContentType.FILE_NAME_SPEC);
77+
textContentType.addFileSpec(testName + ".global", IContentType.FILE_NAME_SPEC);
8178
// added "<test case name>.local" to the text content type as a local
8279
// (scope-specific) file spec
83-
textContentType.getSettings(scope).addFileSpec(name.getMethodName() + ".local", IContentType.FILE_NAME_SPEC);
80+
textContentType.getSettings(scope).addFileSpec(testName + ".local", IContentType.FILE_NAME_SPEC);
8481
// make ensure associations are properly recognized when doing content type
8582
// lookup
86-
assertEquals(textContentType, global.findContentTypeFor(name.getMethodName() + ".global"));
87-
assertNull(local.findContentTypeFor(name.getMethodName() + ".global"));
88-
assertEquals(textContentType, local.findContentTypeFor(name.getMethodName() + ".local"));
89-
assertNull(global.findContentTypeFor(name.getMethodName() + ".local"));
83+
assertEquals(textContentType, global.findContentTypeFor(testName + ".global"));
84+
assertNull(local.findContentTypeFor(testName + ".global"));
85+
assertEquals(textContentType, local.findContentTypeFor(testName + ".local"));
86+
assertNull(global.findContentTypeFor(testName + ".local"));
9087

91-
textContentType.removeFileSpec(name.getMethodName() + ".global", IContentType.FILE_NAME_SPEC);
88+
textContentType.removeFileSpec(testName + ".global", IContentType.FILE_NAME_SPEC);
9289
}
9390

9491
@Test

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/XMLContentDescriberTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.tests.resources.content;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertNotNull;
18-
import static org.junit.Assert.assertNull;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
1919

2020
import java.io.ByteArrayInputStream;
2121
import java.io.InputStream;
@@ -26,7 +26,7 @@
2626
import org.eclipse.core.runtime.Platform;
2727
import org.eclipse.core.runtime.QualifiedName;
2828
import org.eclipse.core.runtime.content.IContentDescription;
29-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3030

3131
/**
3232
* Ensures the XMLContentDescriber is able to handle encodings properly.
@@ -102,9 +102,9 @@ private void checkEncodedContents(String expectedEncoding, String encodingInCont
102102
IContentDescription description = null;
103103
for (boolean[] flag : flags) {
104104
description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(encodingInContent, encoding, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET});
105-
assertNotNull(Arrays.toString(flag), description);
106-
assertEquals(Arrays.toString(flag), Platform.PI_RUNTIME + ".xml", description.getContentType().getId());
107-
assertEquals(Arrays.toString(flag), expectedEncoding, description.getProperty(IContentDescription.CHARSET));
105+
assertNotNull(description, Arrays.toString(flag));
106+
assertEquals(Platform.PI_RUNTIME + ".xml", description.getContentType().getId(), Arrays.toString(flag));
107+
assertEquals(expectedEncoding, description.getProperty(IContentDescription.CHARSET), Arrays.toString(flag));
108108
}
109109
}
110110

@@ -114,9 +114,9 @@ private void checkEncodedContents2(String expectedEncoding, String encodingInCon
114114
IContentDescription description = null;
115115
for (boolean[] flag : flags) {
116116
description = Platform.getContentTypeManager().getDescriptionFor(getReader(encodingInContent, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET});
117-
assertNotNull(Arrays.toString(flag), description);
118-
assertEquals(Arrays.toString(flag), Platform.PI_RUNTIME + ".xml", description.getContentType().getId());
119-
assertEquals(Arrays.toString(flag), expectedEncoding, description.getProperty(IContentDescription.CHARSET));
117+
assertNotNull(description, Arrays.toString(flag));
118+
assertEquals(Platform.PI_RUNTIME + ".xml", description.getContentType().getId(), Arrays.toString(flag));
119+
assertEquals(expectedEncoding, description.getProperty(IContentDescription.CHARSET), Arrays.toString(flag));
120120
}
121121
}
122122

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static void uninstall() throws BundleException {
142142

143143
public static void install() throws Exception {
144144
bundle = BundleTestingHelper.installBundle("", getContext(),
145-
"Plugin_Testing" + TEST_BUNDLE_LOCATION);
145+
"Plugin_Testing/" + TEST_BUNDLE_LOCATION);
146146
BundleTestingHelper.resolveBundles(getContext(), new Bundle[] { bundle });
147147
bundle.start(Bundle.START_TRANSIENT);
148148
registerSaveParticipant(bundle);

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/BundleTestingHelper.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
package org.eclipse.core.tests.harness;
1515

1616
import static java.util.Arrays.asList;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
1920

2021
import java.io.IOException;
2122
import java.net.MalformedURLException;
2223
import java.net.URL;
2324
import java.util.concurrent.Callable;
2425
import org.eclipse.core.runtime.FileLocator;
2526
import org.eclipse.core.runtime.Platform;
26-
import org.junit.Assert;
2727
import org.osgi.framework.Bundle;
2828
import org.osgi.framework.BundleContext;
2929
import org.osgi.framework.BundleException;
@@ -48,9 +48,8 @@ public static Bundle installBundle(BundleContext context, String location) throw
4848

4949
public static Bundle installBundle(String tag, BundleContext context, String location) throws BundleException, MalformedURLException, IOException {
5050
URL entry = context.getBundle().getEntry(location);
51-
if (entry == null) {
52-
Assert.fail(tag + " entry " + location + " could not be found in " + context.getBundle().getSymbolicName());
53-
}
51+
assertNotNull(entry,
52+
tag + " entry " + location + " could not be found in " + context.getBundle().getSymbolicName());
5453
return context.installBundle(FileLocator.toFileURL(entry).toExternalForm());
5554
}
5655

@@ -106,7 +105,7 @@ public static void runWithBundles(Callable<Void> runnable, BundleContext context
106105
Bundle[] installed = new Bundle[locations.length];
107106
for (int i = 0; i < locations.length; i++) {
108107
installed[i] = installBundle(context, locations[i]);
109-
assertEquals(locations[i], Bundle.INSTALLED, installed[i].getState());
108+
assertEquals(Bundle.INSTALLED, installed[i].getState(), locations[i]);
110109
}
111110
if (listener != null) {
112111
listener.reset();

0 commit comments

Comments
 (0)