diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentDescriptionTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentDescriptionTest.java index 452829106d0..e4785e240fb 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentDescriptionTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentDescriptionTest.java @@ -14,11 +14,11 @@ 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; @@ -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; public class ContentDescriptionTest { private static final String CT_VOID = PI_RESOURCES_TESTS + '.' + "void"; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java index 5a0102773e9..aa1222a93bb 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java @@ -19,14 +19,14 @@ import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.CharArrayReader; @@ -60,8 +60,10 @@ import org.eclipse.core.tests.harness.BundleTestingHelper; import org.eclipse.core.tests.harness.FussyProgressMonitor; import org.eclipse.core.tests.harness.TestRegistryChangeListener; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.osgi.framework.BundleContext; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; @@ -174,7 +176,7 @@ private boolean isText(IContentTypeManager manager, IContentType candidate) { return candidate.isKindOf(text); } - @After + @AfterEach public void tearDown() throws Exception { // some tests here will trigger a charset delta job (any causing // ContentTypeChangeEvents to be broadcast) @@ -492,8 +494,10 @@ public void testContentAndNameMatching() throws IOException /* not really */ { /* * Tests both text and byte stream-based getDescriptionFor methods. - */@Test - public void testContentDescription() throws IOException, CoreException { + */ + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void testContentDescription(boolean text) throws IOException, CoreException { IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null); @@ -502,103 +506,100 @@ public void testContentDescription() throws IOException, CoreException { IContentType mytext1 = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "mytext1"); IContentType mytext2 = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "mytext2"); - boolean text = false; - - for (int i = 0; i < 2; i++, text = !text) { - IContentDescription description; - - description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", - IContentDescription.ALL, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - assertSame(xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - // the default charset should have been filled by the content type manager - assertEquals("UTF-8", description.getProperty(IContentDescription.CHARSET)); - assertSame(xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_ISO_8859_1, StandardCharsets.ISO_8859_1, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - assertEquals("ISO-8859-1", description.getProperty(IContentDescription.CHARSET)); - assertNotSame(xmlType.getDefaultDescription(), description); - - // ensure we handle single quotes properly (bug 65443) - description = getDescriptionFor(finder, XML_ISO_8859_1_SINGLE_QUOTES, StandardCharsets.ISO_8859_1, - "foo.xml", new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - assertEquals("ISO-8859-1", description.getProperty(IContentDescription.CHARSET)); - assertNotSame(xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_UTF_16, StandardCharsets.UTF_16, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK }, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - assertEquals("UTF-16", description.getProperty(IContentDescription.CHARSET)); - assertTrue(text || IContentDescription.BOM_UTF_16BE == description - .getProperty(IContentDescription.BYTE_ORDER_MARK)); - assertNotSame(xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_UTF_16BE, StandardCharsets.UTF_8, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - assertEquals("UTF-16BE", description.getProperty(IContentDescription.CHARSET)); - assertNotSame(xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_UTF_16LE, StandardCharsets.UTF_8, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - // the default charset should have been filled by the content type manager - assertEquals("UTF-16LE", description.getProperty(IContentDescription.CHARSET)); - assertNotSame(xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", - IContentDescription.ALL, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - assertEquals("UTF-8", description.getProperty(IContentDescription.CHARSET)); - assertNotNull(mytext); - assertEquals("BAR", mytext.getDefaultCharset()); - assertSame(xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); - assertNotNull(description); - assertEquals(mytext, description.getContentType()); - assertEquals("BAR", description.getProperty(IContentDescription.CHARSET)); - assertSame(mytext.getDefaultDescription(), description); - // now plays with setting a non-default default charset - mytext.setDefaultCharset("FOO"); - - description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); - assertNotNull(description); - assertEquals(mytext, description.getContentType()); - assertEquals("FOO", description.getProperty(IContentDescription.CHARSET)); - assertSame(mytext.getDefaultDescription(), description); - mytext.setDefaultCharset(null); - - description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); - assertNotNull(description); - assertEquals(mytext, description.getContentType()); - assertEquals("BAR", description.getProperty(IContentDescription.CHARSET)); - assertSame(mytext.getDefaultDescription(), description); - - // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=176354 - description = getDescriptionFor(finder, - "", - StandardCharsets.UTF_8, "foo.xml", new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull(description); - assertEquals(xmlType, description.getContentType()); - assertEquals("UTF-8", description.getProperty(IContentDescription.CHARSET)); - assertEquals(xmlType.getDefaultDescription().getCharset(), description.getCharset()); - } + IContentDescription description; + + description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", IContentDescription.ALL, + text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + assertSame(xmlType.getDefaultDescription(), description); + + description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", + new QualifiedName[] { IContentDescription.CHARSET }, text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + // the default charset should have been filled by the content type manager + assertEquals("UTF-8", description.getProperty(IContentDescription.CHARSET)); + assertSame(xmlType.getDefaultDescription(), description); + + description = getDescriptionFor(finder, XML_ISO_8859_1, StandardCharsets.ISO_8859_1, "foo.xml", + new QualifiedName[] { IContentDescription.CHARSET }, text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + assertEquals("ISO-8859-1", description.getProperty(IContentDescription.CHARSET)); + assertNotSame(xmlType.getDefaultDescription(), description); + + // ensure we handle single quotes properly (bug 65443) + description = getDescriptionFor(finder, XML_ISO_8859_1_SINGLE_QUOTES, StandardCharsets.ISO_8859_1, "foo.xml", + new QualifiedName[] { IContentDescription.CHARSET }, text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + assertEquals("ISO-8859-1", description.getProperty(IContentDescription.CHARSET)); + assertNotSame(xmlType.getDefaultDescription(), description); + + description = getDescriptionFor(finder, XML_UTF_16, StandardCharsets.UTF_16, "foo.xml", + new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK }, text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + assertEquals("UTF-16", description.getProperty(IContentDescription.CHARSET)); + assertTrue(text + || IContentDescription.BOM_UTF_16BE == description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNotSame(xmlType.getDefaultDescription(), description); + + description = getDescriptionFor(finder, XML_UTF_16BE, StandardCharsets.UTF_8, "foo.xml", + new QualifiedName[] { IContentDescription.CHARSET }, text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + assertEquals("UTF-16BE", description.getProperty(IContentDescription.CHARSET)); + assertNotSame(xmlType.getDefaultDescription(), description); + + description = getDescriptionFor(finder, XML_UTF_16LE, StandardCharsets.UTF_8, "foo.xml", + new QualifiedName[] { IContentDescription.CHARSET }, text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + // the default charset should have been filled by the content type manager + assertEquals("UTF-16LE", description.getProperty(IContentDescription.CHARSET)); + assertNotSame(xmlType.getDefaultDescription(), description); + + description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", IContentDescription.ALL, + text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + assertEquals("UTF-8", description.getProperty(IContentDescription.CHARSET)); + assertNotNull(mytext); + assertEquals("BAR", mytext.getDefaultCharset()); + assertSame(xmlType.getDefaultDescription(), description); + + description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); + assertNotNull(description); + assertEquals(mytext, description.getContentType()); + assertEquals("BAR", description.getProperty(IContentDescription.CHARSET)); + assertSame(mytext.getDefaultDescription(), description); + // now plays with setting a non-default default charset + mytext.setDefaultCharset("FOO"); + + description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); + assertNotNull(description); + assertEquals(mytext, description.getContentType()); + assertEquals("FOO", description.getProperty(IContentDescription.CHARSET)); + assertSame(mytext.getDefaultDescription(), description); + mytext.setDefaultCharset(null); + + description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); + assertNotNull(description); + assertEquals(mytext, description.getContentType()); + assertEquals("BAR", description.getProperty(IContentDescription.CHARSET)); + assertSame(mytext.getDefaultDescription(), description); + + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=176354 + description = getDescriptionFor(finder, + "", + StandardCharsets.UTF_8, "foo.xml", new QualifiedName[] { IContentDescription.CHARSET }, text); + assertNotNull(description); + assertEquals(xmlType, description.getContentType()); + assertEquals("UTF-8", description.getProperty(IContentDescription.CHARSET)); + assertEquals(xmlType.getDefaultDescription().getCharset(), description.getCharset()); + assertNotNull(mytext1); assertEquals("BAR", mytext1.getDefaultCharset()); assertNotNull(mytext2); @@ -805,21 +806,20 @@ public void testDynamicChangesNewExtension() throws Exception { ContentTypeBuilder.PT_CONTENTTYPES, null, null); BundleTestingHelper.runWithBundles(() -> { IContentType contentType = manager.getContentType("org.eclipse.bug485227.bug485227_contentType"); - assertNotNull("Contributed content type not found", contentType); + assertNotNull(contentType, "Contributed content type not found"); // ensure the content type instances are different text[2] = manager.getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("Text content type not modified", text[2]); + assertNotNull(text[2], "Text content type not modified"); text[2] = ((ContentTypeHandler) text[2]).getTarget(); assertEquals(text[0], text[2]); assertNotSame(text[0], text[2]); - assertEquals("default extension not associated", contentType, - manager.findContentTypeFor("file.bug485227")); - assertEquals("additional extension not associated", contentType, - manager.findContentTypeFor("file.bug485227_2")); + assertEquals(contentType, manager.findContentTypeFor("file.bug485227"), "default extension not associated"); + assertEquals(contentType, manager.findContentTypeFor("file.bug485227_2"), + "additional extension not associated"); return null; }, getContext(), new String[] { TEST_FILES_ROOT + "content/bug485227" }, listener); - assertNull("Content type not cleared after bundle uninstall", - manager.getContentType("org.eclipse.bug485227.bug485227_contentType")); + assertNull(manager.getContentType("org.eclipse.bug485227.bug485227_contentType"), + "Content type not cleared after bundle uninstall"); // ensure the content type instances are all different text[3] = manager.getContentType(IContentTypeManager.CT_TEXT); assertNotNull(text[3]); @@ -981,7 +981,7 @@ public void testFindContentTypPredefinedRegexp() throws IOException, CoreExcepti IContentType targetContentType = contentTypeManager .getContentType("org.eclipse.core.tests.resources.predefinedContentTypeWithRegexp"); - assertNotNull("Target content-type not found", targetContentType); + assertNotNull(targetContentType, "Target content-type not found"); IContentType single = finder.findContentTypeFor(getInputStream("Just a test"), "somepredefinedContentTypeWithRegexpFile"); @@ -1000,17 +1000,17 @@ public void testFindContentTypeUserRegexp() throws IOException, CoreException { IContentType textContentType = contentTypeManager.getContentType(Platform.PI_RUNTIME + '.' + "text"); IContentType single = finder.findContentTypeFor(getInputStream("Just a test"), "someText.unknown"); - assertNull("File pattern unknown at that point", single); + assertNull(single, "File pattern unknown at that point"); textContentType.addFileSpec("*Text*", IContentType.FILE_PATTERN_SPEC); try { single = finder.findContentTypeFor(getInputStream("Just a test"), "someText.unknown"); - assertEquals("Text content should now match *Text* files", textContentType, single); + assertEquals(textContentType, single, "Text content should now match *Text* files"); } finally { textContentType.removeFileSpec("*Text*", IContentType.FILE_PATTERN_SPEC); } single = finder.findContentTypeFor(getInputStream("Just a test"), "someText.unknown"); - assertNull("File pattern unknown at that point", single); + assertNull(single, "File pattern unknown at that point"); } @Test @@ -1160,8 +1160,8 @@ public void testMyContentDescriber() throws IOException { assertEquals(myContent, description.getContentType()); assertNotSame(myContent.getDefaultDescription(), description); for (int i = 0; i < MyContentDescriber.MY_OPTIONS.length; i++) { - assertEquals(i + "", MyContentDescriber.MY_OPTION_VALUES[i], - description.getProperty(MyContentDescriber.MY_OPTIONS[i])); + assertEquals(MyContentDescriber.MY_OPTION_VALUES[i], + description.getProperty(MyContentDescriber.MY_OPTIONS[i]), i + ""); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java index 8c56a346a5e..f6848dadf43 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java @@ -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}. @@ -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(); } @@ -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"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java index 1d27f802a4a..da22af7a892 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java @@ -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}. @@ -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"); } } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java index ed30dc7f909..a097b208e44 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java @@ -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; @@ -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. */ @@ -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 ".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 ".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 diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/XMLContentDescriberTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/XMLContentDescriberTest.java index 6a9e4ed220f..85cd38afffb 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/XMLContentDescriberTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/XMLContentDescriberTest.java @@ -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; @@ -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. @@ -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)); } } @@ -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)); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java index 4524051098c..9be35b8794e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java @@ -142,7 +142,7 @@ public static void uninstall() throws BundleException { public static void install() throws Exception { bundle = BundleTestingHelper.installBundle("", getContext(), - "Plugin_Testing" + TEST_BUNDLE_LOCATION); + "Plugin_Testing/" + TEST_BUNDLE_LOCATION); BundleTestingHelper.resolveBundles(getContext(), new Bundle[] { bundle }); bundle.start(Bundle.START_TRANSIENT); registerSaveParticipant(bundle); diff --git a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/BundleTestingHelper.java b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/BundleTestingHelper.java index 39f0581e5a6..59a42d2de95 100644 --- a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/BundleTestingHelper.java +++ b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/BundleTestingHelper.java @@ -14,8 +14,9 @@ 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; @@ -23,7 +24,6 @@ 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; @@ -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()); } @@ -106,7 +105,7 @@ public static void runWithBundles(Callable 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();