Skip to content

Commit

Permalink
Migrate resources content tests to JUnit 5 eclipse-platform#903
Browse files Browse the repository at this point in the history
Migrates the tests in org.eclipse.core.tests.resources.content to JUnit
5 by replacing according JUnit annotations and migrating assertions.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Nov 3, 2024
1 parent 63e9db3 commit ea1f60c
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
package org.eclipse.core.tests.resources.content;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.internal.content.ContentDescription;
import org.eclipse.core.internal.content.ContentType;
import org.eclipse.core.internal.content.ContentTypeHandler;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.content.IContentDescription;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
package org.eclipse.core.tests.resources.content;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.internal.content.LazyInputStream;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Tests for {@link LazyInputStream}.
Expand Down Expand Up @@ -169,7 +169,7 @@ public void testVariedContent() throws IOException {
ByteArrayInputStream underlying = new ByteArrayInputStream(contents);
OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7);
for (int i = 0; i < VARIOUS_INTS.length; i++) {
assertEquals(i + "", VARIOUS_INTS[i], stream.read());
assertEquals(VARIOUS_INTS[i], stream.read(), i + "");
}
stream.close();
}
Expand All @@ -196,7 +196,7 @@ public int read(byte[] b, int off, int len) throws IOException {

objectUnderTest.skip(1);

assertTrue("The buffer size suffered an Overflow", objectUnderTest.getBufferSize() > Integer.MAX_VALUE);
assertTrue(objectUnderTest.getBufferSize() > Integer.MAX_VALUE, "The buffer size suffered an Overflow");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
package org.eclipse.core.tests.resources.content;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.CharArrayReader;
import java.io.IOException;
import java.io.Reader;
import org.eclipse.core.internal.content.LazyReader;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Tests for {@link LazyReader}.
Expand Down Expand Up @@ -179,7 +179,7 @@ public void close() throws IOException {

objectUnderTest.skip(1);

assertTrue("The buffer size suffered an Overflow", objectUnderTest.getBufferSize() > Integer.MAX_VALUE);
assertTrue(objectUnderTest.getBufferSize() > Integer.MAX_VALUE, "The buffer size suffered an Overflow");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
package org.eclipse.core.tests.resources.content;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.internal.content.ContentTypeManager;
import org.eclipse.core.internal.preferences.EclipsePreferences;
Expand All @@ -30,18 +30,14 @@
import org.eclipse.core.runtime.content.IContentTypeSettings;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

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

@Rule
public TestName name = new TestName();

/**
* A minimal scope implementation.
*/
Expand Down Expand Up @@ -70,25 +66,26 @@ public IEclipsePreferences getNode(String qualifier) {
}

@Test
public void testContentTypeLookup() throws CoreException {
public void testContentTypeLookup(TestInfo testInfo) throws CoreException {
String testName = testInfo.getDisplayName();
IContentTypeManager global = Platform.getContentTypeManager();
final SingleNodeScope scope = new SingleNodeScope();
IContentTypeMatcher local = global.getMatcher(new LocalSelectionPolicy(), scope);
IContentType textContentType = global.getContentType(Platform.PI_RUNTIME + '.' + "text");
// added "<test case name>.global" to the text content type as a global file
// spec
textContentType.addFileSpec(name.getMethodName() + ".global", IContentType.FILE_NAME_SPEC);
textContentType.addFileSpec(testName + ".global", IContentType.FILE_NAME_SPEC);
// added "<test case name>.local" to the text content type as a local
// (scope-specific) file spec
textContentType.getSettings(scope).addFileSpec(name.getMethodName() + ".local", IContentType.FILE_NAME_SPEC);
textContentType.getSettings(scope).addFileSpec(testName + ".local", IContentType.FILE_NAME_SPEC);
// make ensure associations are properly recognized when doing content type
// lookup
assertEquals(textContentType, global.findContentTypeFor(name.getMethodName() + ".global"));
assertNull(local.findContentTypeFor(name.getMethodName() + ".global"));
assertEquals(textContentType, local.findContentTypeFor(name.getMethodName() + ".local"));
assertNull(global.findContentTypeFor(name.getMethodName() + ".local"));
assertEquals(textContentType, global.findContentTypeFor(testName + ".global"));
assertNull(local.findContentTypeFor(testName + ".global"));
assertEquals(textContentType, local.findContentTypeFor(testName + ".local"));
assertNull(global.findContentTypeFor(testName + ".local"));

textContentType.removeFileSpec(name.getMethodName() + ".global", IContentType.FILE_NAME_SPEC);
textContentType.removeFileSpec(testName + ".global", IContentType.FILE_NAME_SPEC);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.content;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -26,7 +26,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.content.IContentDescription;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
package org.eclipse.core.tests.harness;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.Callable;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.junit.Assert;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
Expand All @@ -48,9 +48,8 @@ public static Bundle installBundle(BundleContext context, String location) throw

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

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

0 comments on commit ea1f60c

Please sign in to comment.