diff --git a/README.md b/README.md index 02f765b055c..77f715eb2f7 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,11 @@ For a complete guide, see the [CONTRIBUTING](https://github.com/eclipse-platform https://www.eclipse.org/setups/installer/?url=https://raw.githubusercontent.com/eclipse-platform/eclipse.platform/master/releng/org.eclipse.platform.setup/PlatformConfiguration.setup&show=true "Click to open Eclipse-Installer Auto Launch or drag into your running installer") +## Documentation + +For additional documentation, please refer to the [docs directory](./docs) and [The Official Eclipse FAQs](./docs/FAQ/The_Official_Eclipse_FAQs.md). + + ## Issue Tracking This project uses Github to track ongoing development and issues. In case you have an issue, please read the information about Eclipse being a [community project](https://github.com/eclipse-platform#community) and bear in mind that this project is almost entirely developed by volunteers. So the contributors may not be able to look into every reported issue. You will also find the information about [how to find and report issues](https://github.com/eclipse-platform#reporting-issues) in repositories of the `eclipse-platform` organization there. Be sure to search for existing issues before you create another one. diff --git a/docs/FAQ/The_Official_Eclipse_FAQs.md b/docs/FAQ/The_Official_Eclipse_FAQs.md index 00d16d781c1..4fe12c4d8fa 100644 --- a/docs/FAQ/The_Official_Eclipse_FAQs.md +++ b/docs/FAQ/The_Official_Eclipse_FAQs.md @@ -16,7 +16,7 @@ Contents * [2 Part II -- The Rich Client Platform](#Part-II----The-Rich-Client-Platform) * [2.1 All about Plug-ins](#All-about-Plug-ins) * [2.2 Runtime Facilities](#Runtime-Facilities) - * [2.3 Standard Widget Toolkit (SWT)](#Standard-Widget-Toolkit-.28SWT.29) + * [2.3 Standard Widget Toolkit (SWT)](#standard-widget-toolkit-swt) * [2.4 JFace](#JFace) * [2.5 Generic Workbench](#Generic-Workbench) * [2.6 Perspectives and Views](#Perspectives-and-Views) @@ -34,7 +34,7 @@ Contents * [3.5.2 This is a DSL of your own](#This-is-a-DSL-of-your-own) * [3.5.3 Legacy](#Legacy) * [3.6 Java Development Tool API](#Java-Development-Tool-API) -* [4 Where to buy the original book](#Where-to-buy-the-original-book) +* [4 This content is based on](#This-content-is-based-on) Part I -- The Eclipse Ecosystem ------------------------------- @@ -602,12 +602,10 @@ Finally, the JDT is a useful set of plug-ins in its own right, but it has also b * [FAQ How do I participate in a refactoring?](./FAQ_How_do_I_participate_in_a_refactoring.md "FAQ How do I participate in a refactoring?") * [FAQ What is LTK?](./FAQ_What_is_LTK.md "FAQ What is LTK?") -Where to buy the original book ------------------------------- -The initial contents for these FAQ pages has come from The Offical Eclipse 3.0 FAQs written by John Arthorne and Chris Laffra. +### Acknowledgement -Permission to publish the FAQ book contents here has been graciously offered by Addison-Wesley, publishers of the official Eclipse Series which wouldn't be possible without the great help from Greg Doench. +The initial contents for these FAQ pages has come from [The Offical Eclipse 3.0 FAQs](https://www.amazon.com/exec/obidos/ASIN/0321268385) written by John Arthorne and Chris Laffra. -The book can be purchased from [Amazon.com](http://www.amazon.com/exec/obidos/ASIN/0321268385) +Permission to publish the FAQ book contents here has been graciously offered by Addison-Wesley, publishers of the official Eclipse Series which wouldn't be possible without the great help from Greg Doench. 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 8ac6b7ed881..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.assertTrue; -import static org.junit.Assert.fail; +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,9 +26,9 @@ 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 extends ContentTypeTest { +public class ContentDescriptionTest { private static final String CT_VOID = PI_RESOURCES_TESTS + '.' + "void"; private static final QualifiedName ZOO_PROPERTY = new QualifiedName(PI_RESOURCES_TESTS, "zoo"); private static final QualifiedName BAR_PROPERTY = new QualifiedName(PI_RESOURCES_TESTS, "bar"); @@ -42,89 +42,69 @@ private ContentType getContentType() { @Test public void testAllProperties() { ContentDescription description = new ContentDescription(IContentDescription.ALL, getContentType()); - assertTrue("1.0", description.isRequested(FOO_PROPERTY)); - assertNull("1.1", description.getProperty(FOO_PROPERTY)); + assertTrue(description.isRequested(FOO_PROPERTY)); + assertNull(description.getProperty(FOO_PROPERTY)); description.setProperty(FOO_PROPERTY, "value1"); - assertEquals("1.2", "value1", description.getProperty(FOO_PROPERTY)); + assertEquals("value1", description.getProperty(FOO_PROPERTY)); description.setProperty(FOO_PROPERTY, "value1b"); - assertEquals("1.3", "value1b", description.getProperty(FOO_PROPERTY)); - assertTrue("2.0", description.isRequested(BAR_PROPERTY)); + assertEquals("value1b", description.getProperty(FOO_PROPERTY)); + assertTrue(description.isRequested(BAR_PROPERTY)); description.setProperty(BAR_PROPERTY, "value2"); - assertEquals("2.1", "value2", description.getProperty(BAR_PROPERTY)); + assertEquals("value2", description.getProperty(BAR_PROPERTY)); description.setProperty(ZOO_PROPERTY, "value3"); - assertEquals("2.2", "value3", description.getProperty(ZOO_PROPERTY)); + assertEquals("value3", description.getProperty(ZOO_PROPERTY)); description.markImmutable(); - try { - description.setProperty(FOO_PROPERTY, "value1c"); - fail("3.0 - should have failed"); - } catch (IllegalStateException e) { - // success - the object was marked as immutable - } + assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1c")); } @Test public void testOneProperty() { ContentDescription description = new ContentDescription(new QualifiedName[] {FOO_PROPERTY}, getContentType()); - assertTrue("1.0", description.isRequested(FOO_PROPERTY)); - assertNull("1.1", description.getProperty(FOO_PROPERTY)); + assertTrue(description.isRequested(FOO_PROPERTY)); + assertNull(description.getProperty(FOO_PROPERTY)); description.setProperty(FOO_PROPERTY, "value1"); - assertEquals("1.2", "value1", description.getProperty(FOO_PROPERTY)); + assertEquals("value1", description.getProperty(FOO_PROPERTY)); description.setProperty(FOO_PROPERTY, "value1b"); - assertEquals("1.3", "value1b", description.getProperty(FOO_PROPERTY)); + assertEquals("value1b", description.getProperty(FOO_PROPERTY)); description.setProperty(BAR_PROPERTY, "value2"); - assertFalse("2.0", description.isRequested(BAR_PROPERTY)); + assertFalse(description.isRequested(BAR_PROPERTY)); description.setProperty(BAR_PROPERTY, "value2"); - assertNull("2.1", description.getProperty(BAR_PROPERTY)); + assertNull(description.getProperty(BAR_PROPERTY)); description.markImmutable(); - try { - description.setProperty(FOO_PROPERTY, "value1c"); - fail("3.0 - should have failed"); - } catch (IllegalStateException e) { - // success - the object was marked as immutable - } + assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1c")); } @Test public void testZeroProperties() { ContentDescription description = new ContentDescription(new QualifiedName[0], getContentType()); - assertFalse("1.0", description.isRequested(FOO_PROPERTY)); - assertNull("1.1", description.getProperty(FOO_PROPERTY)); + assertFalse(description.isRequested(FOO_PROPERTY)); + assertNull(description.getProperty(FOO_PROPERTY)); description.setProperty(FOO_PROPERTY, "value1"); - assertNull("1.2", description.getProperty(FOO_PROPERTY)); + assertNull(description.getProperty(FOO_PROPERTY)); description.markImmutable(); - try { - description.setProperty(FOO_PROPERTY, "value1b"); - fail("2.0 - should have failed"); - } catch (IllegalStateException e) { - // success - the object was marked as immutable - } + assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1b")); } @Test public void testMultipleProperties() { ContentDescription description = new ContentDescription(new QualifiedName[] {FOO_PROPERTY, BAR_PROPERTY, ZOO_PROPERTY}, getContentType()); - assertTrue("1.0", description.isRequested(FOO_PROPERTY)); - assertNull("1.1", description.getProperty(FOO_PROPERTY)); + assertTrue(description.isRequested(FOO_PROPERTY)); + assertNull(description.getProperty(FOO_PROPERTY)); description.setProperty(FOO_PROPERTY, "value1"); - assertEquals("1.2", "value1", description.getProperty(FOO_PROPERTY)); + assertEquals("value1", description.getProperty(FOO_PROPERTY)); description.setProperty(FOO_PROPERTY, "value1b"); - assertEquals("1.3", "value1b", description.getProperty(FOO_PROPERTY)); + assertEquals("value1b", description.getProperty(FOO_PROPERTY)); description.setProperty(BAR_PROPERTY, "value2"); - assertTrue("2.0", description.isRequested(BAR_PROPERTY)); + assertTrue(description.isRequested(BAR_PROPERTY)); description.setProperty(BAR_PROPERTY, "value2"); - assertEquals("2.1", "value2", description.getProperty(BAR_PROPERTY)); - assertTrue("2.2", description.isRequested(ZOO_PROPERTY)); + assertEquals("value2", description.getProperty(BAR_PROPERTY)); + assertTrue(description.isRequested(ZOO_PROPERTY)); description.setProperty(ZOO_PROPERTY, "value3"); - assertEquals("2.3", "value3", description.getProperty(ZOO_PROPERTY)); - assertFalse("3.0", description.isRequested(FRED_PROPERTY)); + assertEquals("value3", description.getProperty(ZOO_PROPERTY)); + assertFalse(description.isRequested(FRED_PROPERTY)); description.setProperty(FRED_PROPERTY, "value3"); - assertNull("3.1", description.getProperty(FRED_PROPERTY)); + assertNull(description.getProperty(FRED_PROPERTY)); description.markImmutable(); - try { - description.setProperty(FOO_PROPERTY, "value1c"); - fail("4.0 - should have failed"); - } catch (IllegalStateException e) { - // success - the object was marked as immutable - } + assertThrows(IllegalStateException.class, () -> description.setProperty(FOO_PROPERTY, "value1c")); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentTypeTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentTypeTest.java deleted file mode 100644 index 11692f25c9e..00000000000 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/ContentTypeTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2012 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.core.tests.resources.content; - -import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.BundleContext; - -/** - * Common superclass for all content type tests. - */ -public abstract class ContentTypeTest { - public static final String TEST_FILES_ROOT = "Plugin_Testing/"; - - public BundleContext getContext() { - return Platform.getBundle(PI_RESOURCES_TESTS).getBundleContext(); - } - - /** - * Return an input stream with some random text to use as contents for a file - * resource. - */ - public InputStream getRandomContents() { - return new ByteArrayInputStream(getRandomString().getBytes()); - } - - /** - * Return String with some random text to use as contents for a file resource. - */ - public String getRandomString() { - switch ((int) Math.round(Math.random() * 10)) { - case 0: - return "este e' o meu conteudo (portuguese)"; - case 1: - return "ho ho ho"; - case 2: - return "I'll be back"; - case 3: - return "don't worry, be happy"; - case 4: - return "there is no imagination for more sentences"; - case 5: - return "Alexandre Bilodeau, Canada's first home gold. 14/02/2010"; - case 6: - return "foo"; - case 7: - return "bar"; - case 8: - return "foobar"; - case 9: - return "case 9"; - default: - return "these are my contents"; - } - } - -} 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 c7a196b0ba9..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 @@ -17,14 +17,16 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.atIndex; 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.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.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; +import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; +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; @@ -58,12 +60,16 @@ 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; -public class IContentTypeManagerTest extends ContentTypeTest { +public class IContentTypeManagerTest { + private static final String TEST_FILES_ROOT = "Plugin_Testing/"; private static class ContentTypeChangeTracer implements IContentTypeManager.IContentTypeChangeListener { private final Set changed = new HashSet<>(); @@ -170,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) @@ -183,41 +189,38 @@ public void tearDown() throws Exception { * This test shows how we deal with aliases. */ @Test - public void testAlias() throws IOException { + public void testAlias() throws Exception { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); IContentType alias = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".alias"); - assertNotNull("0.7", alias); + assertNotNull(alias); IContentType derived = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".derived-from-alias"); - assertNotNull("0.8", derived); + assertNotNull(derived); IContentType target = contentTypeManager.getContentType("org.eclipse.bundle02.missing-target"); - assertNull("0.9", target); + assertNull(target); IContentType[] selected; selected = contentTypeManager.findContentTypesFor("foo.missing-target"); assertThat(selected).containsExactly(alias, derived); - selected = contentTypeManager.findContentTypesFor(getRandomContents(), "foo.missing-target"); + selected = contentTypeManager.findContentTypesFor(createRandomContentsStream(), "foo.missing-target"); assertThat(selected).containsExactly(alias, derived); // test late addition of content type TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); - BundleTestingHelper.runWithBundles("2", () -> { + BundleTestingHelper.runWithBundles(() -> { IContentType alias1 = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".alias"); - assertNull("2.1.1", alias1); + assertNull(alias1); IContentType derived1 = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".derived-from-alias"); - assertNotNull("2.1.2", derived1); + assertNotNull(derived1); IContentType target1 = contentTypeManager.getContentType("org.eclipse.bundle02.missing-target"); - assertNotNull("2.1.3", target1); + assertNotNull(target1); // checks associations IContentType[] selected1 = contentTypeManager.findContentTypesFor("foo.missing-target"); assertThat(selected1).containsExactly(target1, derived1); IContentType[] selected2; - try { - selected2 = contentTypeManager.findContentTypesFor(getRandomContents(), "foo.missing-target"); - } catch (IOException e) { - throw new AssertionError(e); - } + selected2 = contentTypeManager.findContentTypesFor(createRandomContentsStream(), "foo.missing-target"); assertThat(selected2).containsExactly(target1, derived1); - }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle02" }, listener); + return null; + }, getContext(), new String[] { TEST_FILES_ROOT + "content/bundle02" }, listener); } @Test @@ -234,18 +237,18 @@ public void testAssociationInheritance() throws CoreException { assoc2.addFileSpec("txt_assoc2useradded", IContentType.FILE_EXTENSION_SPEC); // test associations - assertTrue("1.1", assoc1.isAssociatedWith(changeCase("text.txt"))); - assertTrue("1.2", assoc1.isAssociatedWith(changeCase("text.txt_useradded"))); - assertTrue("1.3", assoc1.isAssociatedWith(changeCase("text.txt_pluginadded"))); - assertTrue("1.4", assoc1.isAssociatedWith(changeCase("text.txt_assoc1pluginadded"))); - assertTrue("1.5", assoc1.isAssociatedWith(changeCase("text.txt_assoc1useradded"))); - - assertFalse("2.1", assoc2.isAssociatedWith(changeCase("text.txt"))); - assertFalse("2.2", assoc2.isAssociatedWith(changeCase("text.txt_useradded"))); - assertFalse("2.3", assoc2.isAssociatedWith(changeCase("text.txt_pluginadded"))); - assertTrue("2.4", assoc2.isAssociatedWith(changeCase("text.txt_assoc2pluginadded"))); - assertTrue("2.5", assoc2.isAssociatedWith(changeCase("text.txt_assoc2builtin"))); - assertTrue("2.6", assoc2.isAssociatedWith(changeCase("text.txt_assoc2useradded"))); + assertTrue(assoc1.isAssociatedWith(changeCase("text.txt"))); + assertTrue(assoc1.isAssociatedWith(changeCase("text.txt_useradded"))); + assertTrue(assoc1.isAssociatedWith(changeCase("text.txt_pluginadded"))); + assertTrue(assoc1.isAssociatedWith(changeCase("text.txt_assoc1pluginadded"))); + assertTrue(assoc1.isAssociatedWith(changeCase("text.txt_assoc1useradded"))); + + assertFalse(assoc2.isAssociatedWith(changeCase("text.txt"))); + assertFalse(assoc2.isAssociatedWith(changeCase("text.txt_useradded"))); + assertFalse(assoc2.isAssociatedWith(changeCase("text.txt_pluginadded"))); + assertTrue(assoc2.isAssociatedWith(changeCase("text.txt_assoc2pluginadded"))); + assertTrue(assoc2.isAssociatedWith(changeCase("text.txt_assoc2builtin"))); + assertTrue(assoc2.isAssociatedWith(changeCase("text.txt_assoc2useradded"))); IContentType[] selected; // text built-in associations @@ -284,9 +287,9 @@ public void testAssociations() throws CoreException { text.addFileSpec("txt_useradded", IContentType.FILE_EXTENSION_SPEC); // test associations - assertTrue("0.1", text.isAssociatedWith(changeCase("text.txt"))); - assertTrue("0.2", text.isAssociatedWith(changeCase("text.txt_useradded"))); - assertTrue("0.3", text.isAssociatedWith(changeCase("text.txt_pluginadded"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt_useradded"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt_pluginadded"))); // check provider defined settings String[] providerDefinedExtensions = text @@ -306,17 +309,17 @@ public void testAssociations() throws CoreException { text.removeFileSpec("txt", IContentType.FILE_EXTENSION_SPEC); assertThat(text.getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_USER_DEFINED)) .contains("txt"); - assertTrue("3.1", text.isAssociatedWith(changeCase("text.txt"))); - assertTrue("3.2", text.isAssociatedWith(changeCase("text.txt_useradded"))); - assertTrue("3.3", text.isAssociatedWith(changeCase("text.txt_pluginadded"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt_useradded"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt_pluginadded"))); // removing user file specs is the normal case and has to work as expected text.removeFileSpec("txt_useradded", IContentType.FILE_EXTENSION_SPEC); assertThat(text.getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_PRE_DEFINED)) .doesNotContain("ini"); - assertTrue("4.1", text.isAssociatedWith(changeCase("text.txt"))); - assertFalse("4.2", text.isAssociatedWith(changeCase("text.txt_useradded"))); - assertTrue("4.3", text.isAssociatedWith(changeCase("text.txt_pluginadded"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt"))); + assertFalse(text.isAssociatedWith(changeCase("text.txt_useradded"))); + assertTrue(text.isAssociatedWith(changeCase("text.txt_pluginadded"))); } @Test @@ -329,14 +332,14 @@ public void testBinaryTypes() throws IOException { contents = getInputStream( new byte[][] { SAMPLE_BIN1_OFFSET.getBytes(), SAMPLE_BIN1_SIGNATURE, " extra contents".getBytes() }); IContentDescription description = contentTypeManager.getDescriptionFor(contents, null, IContentDescription.ALL); - assertNotNull("6.0", description); - assertEquals("6.1", sampleBinary1, description.getContentType()); + assertNotNull(description); + assertEquals(sampleBinary1, description.getContentType()); contents = getInputStream( new byte[][] { SAMPLE_BIN2_OFFSET.getBytes(), SAMPLE_BIN2_SIGNATURE, " extra contents".getBytes() }); description = contentTypeManager.getDescriptionFor(contents, null, IContentDescription.ALL); - assertNotNull("7.0", description); - assertEquals("7.1", sampleBinary2, description.getContentType()); + assertNotNull(description); + assertEquals(sampleBinary2, description.getContentType()); // make sure we ignore that content type when contents are text // (see bug 100032) @@ -345,9 +348,9 @@ public void testBinaryTypes() throws IOException { assertThat(selected).hasSize(1) .allSatisfy(element -> assertThat(element.getId()).isEqualTo(sampleBinary2.getId())); // (we used to blow up here) - description = contentTypeManager.getDescriptionFor(getReader(getRandomString()), "test.samplebin2", + description = contentTypeManager.getDescriptionFor(getReader(createRandomString()), "test.samplebin2", IContentDescription.ALL); - assertNull("8.3", description); + assertNull(description); } @Test @@ -359,27 +362,27 @@ public void testByteOrderMark() throws IOException { String UTF8_BOM = new String(IContentDescription.BOM_UTF_8, StandardCharsets.ISO_8859_1); description = text.getDescriptionFor( new ByteArrayInputStream((UTF8_BOM + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNotNull("1.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); - assertEquals("1.1", IContentDescription.BOM_UTF_8, + assertNotNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertEquals(IContentDescription.BOM_UTF_8, description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // tests with UTF-16 Little Endian BOM String UTF16_LE_BOM = new String(IContentDescription.BOM_UTF_16LE, StandardCharsets.ISO_8859_1); description = text.getDescriptionFor( new ByteArrayInputStream((UTF16_LE_BOM + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNotNull("2.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); - assertEquals("2.1", IContentDescription.BOM_UTF_16LE, + assertNotNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertEquals(IContentDescription.BOM_UTF_16LE, description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // tests with UTF-16 Big Endian BOM String UTF16_BE_BOM = new String(IContentDescription.BOM_UTF_16BE, StandardCharsets.ISO_8859_1); description = text.getDescriptionFor( new ByteArrayInputStream((UTF16_BE_BOM + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNotNull("3.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); - assertEquals("3.1", IContentDescription.BOM_UTF_16BE, + assertNotNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertEquals(IContentDescription.BOM_UTF_16BE, description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // test with no BOM description = text.getDescriptionFor( new ByteArrayInputStream(MINIMAL_XML.getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("4.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // tests for partial BOM // first byte of UTF-16 Big Endian + minimal xml @@ -387,45 +390,45 @@ public void testByteOrderMark() throws IOException { description = text.getDescriptionFor( new ByteArrayInputStream((UTF16_BE_BOM_1byte + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("5.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // first byte of UTF-16 Big Endian only (see // https://bugs.eclipse.org/bugs/show_bug.cgi?id=199252) description = text.getDescriptionFor( new ByteArrayInputStream((UTF16_BE_BOM_1byte).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("5.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // first byte of UTF-16 Little Endian + minimal xml String UTF16_LE_BOM_1byte = new String(new byte[] { (byte) 0xFF }, StandardCharsets.ISO_8859_1); description = text.getDescriptionFor( new ByteArrayInputStream((UTF16_LE_BOM_1byte + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("6.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // first byte of UTF-16 Little Endian only description = text.getDescriptionFor( new ByteArrayInputStream((UTF16_LE_BOM_1byte).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("6.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // first byte of UTF-8 + minimal xml String UTF8_BOM_1byte = new String(new byte[] { (byte) 0xEF }, StandardCharsets.ISO_8859_1); description = text.getDescriptionFor( new ByteArrayInputStream((UTF8_BOM_1byte + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("7.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // first byte of UTF-8 only description = text.getDescriptionFor( new ByteArrayInputStream((UTF8_BOM_1byte).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("7.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // two first bytes of UTF-8 + minimal xml String UTF8_BOM_2bytes = new String(new byte[] { (byte) 0xEF, (byte) 0xBB }, StandardCharsets.ISO_8859_1); description = text.getDescriptionFor( new ByteArrayInputStream((UTF8_BOM_2bytes + MINIMAL_XML).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("8.0", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // two first bytes of UTF-8 only description = text.getDescriptionFor( new ByteArrayInputStream((UTF8_BOM_2bytes).getBytes(StandardCharsets.ISO_8859_1)), options); - assertNull("8.1", description.getProperty(IContentDescription.BYTE_ORDER_MARK)); + assertNull(description.getProperty(IContentDescription.BYTE_ORDER_MARK)); } /** @@ -454,45 +457,47 @@ public void testContentAndNameMatching() throws IOException /* not really */ { selected = manager.findContentTypesFor(getInputStream(contents0), "anything.mybinary"); assertThat(selected).hasSize(3); // all we know is the first one is the base type (only one with a VALID match) - assertEquals("1.1", base, selected[0]); + assertEquals(base, selected[0]); selected = manager.findContentTypesFor(getInputStream(contents0), "foo.mybinary"); // we know also that the second one will be derived1, because it has a full name // matching assertThat(selected).hasSize(3); - assertEquals("2.1", base, selected[0]); - assertEquals("2.2", derived1, selected[1]); + assertEquals(base, selected[0]); + assertEquals(derived1, selected[1]); selected = manager.findContentTypesFor(getInputStream(contents1), "foo.mybinary"); // derived1 will be first because both base and derived1 have a strong content // matching, so more specific wins assertThat(selected).hasSize(3); - assertEquals("3.1", derived1, selected[0]); - assertEquals("3.2", base, selected[1]); + assertEquals(derived1, selected[0]); + assertEquals(base, selected[1]); selected = manager.findContentTypesFor(getInputStream(contents2), "foo.mybinary"); // same as 3.* - derived1 is last because content matching is weak, althoug name // matching is strong assertThat(selected).hasSize(3); - assertEquals("4.1", derived2, selected[0]); - assertEquals("4.2", base, selected[1]); + assertEquals(derived2, selected[0]); + assertEquals(base, selected[1]); selected = manager.findContentTypesFor(getInputStream(invalidContents), "foo.mybinary"); // all types have weak content matching only - derived1 has strong name matching assertThat(selected).hasSize(3); - assertEquals("5.1", derived1, selected[0]); - assertEquals("5.2", base, selected[1]); + assertEquals(derived1, selected[0]); + assertEquals(base, selected[1]); selected = manager.findContentTypesFor(getInputStream(invalidContents), "anything.mybinary"); // all types have weak content/name matching only - most general wins assertThat(selected).hasSize(3); - assertEquals("6.1", base, selected[0]); + assertEquals(base, selected[0]); } /* * 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); @@ -501,108 +506,104 @@ 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) { - String sufix = text ? "-text" : "-binary"; - IContentDescription description; - - description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", - IContentDescription.ALL, text); - assertNotNull("1.0" + sufix, description); - assertEquals("1.1" + sufix, xmlType, description.getContentType()); - assertSame("1.2", xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull("2.0" + sufix, description); - assertEquals("2.1" + sufix, xmlType, description.getContentType()); - // the default charset should have been filled by the content type manager - assertEquals("2.2" + sufix, "UTF-8", description.getProperty(IContentDescription.CHARSET)); - assertSame("2.3", xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_ISO_8859_1, StandardCharsets.ISO_8859_1, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull("2.3a" + sufix, description); - assertEquals("2.3b" + sufix, xmlType, description.getContentType()); - assertEquals("2.3c" + sufix, "ISO-8859-1", description.getProperty(IContentDescription.CHARSET)); - assertNotSame("2.3d", 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("2.3e" + sufix, description); - assertEquals("2.3f" + sufix, xmlType, description.getContentType()); - assertEquals("2.3g" + sufix, "ISO-8859-1", description.getProperty(IContentDescription.CHARSET)); - assertNotSame("2.3h", xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_UTF_16, StandardCharsets.UTF_16, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK }, text); - assertNotNull("2.4a" + sufix, description); - assertEquals("2.4b" + sufix, xmlType, description.getContentType()); - assertEquals("2.4c" + sufix, "UTF-16", description.getProperty(IContentDescription.CHARSET)); - assertTrue("2.4d" + sufix, text || IContentDescription.BOM_UTF_16BE == description - .getProperty(IContentDescription.BYTE_ORDER_MARK)); - assertNotSame("2.4e", xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_UTF_16BE, StandardCharsets.UTF_8, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull("2.5a" + sufix, description); - assertEquals("2.5b" + sufix, xmlType, description.getContentType()); - assertEquals("2.5c" + sufix, "UTF-16BE", description.getProperty(IContentDescription.CHARSET)); - assertNotSame("2.5d", xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, XML_UTF_16LE, StandardCharsets.UTF_8, "foo.xml", - new QualifiedName[] { IContentDescription.CHARSET }, text); - assertNotNull("2.6a" + sufix, description); - assertEquals("2.6b" + sufix, xmlType, description.getContentType()); - // the default charset should have been filled by the content type manager - assertEquals("2.6c" + sufix, "UTF-16LE", description.getProperty(IContentDescription.CHARSET)); - assertNotSame("2.6d", xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, MINIMAL_XML, StandardCharsets.UTF_8, "foo.xml", - IContentDescription.ALL, text); - assertNotNull("4.0" + sufix, description); - assertEquals("4.1" + sufix, xmlType, description.getContentType()); - assertEquals("4.2" + sufix, "UTF-8", description.getProperty(IContentDescription.CHARSET)); - assertNotNull("5.0" + sufix, mytext); - assertEquals("5.0b" + sufix, "BAR", mytext.getDefaultCharset()); - assertSame("5.0c", xmlType.getDefaultDescription(), description); - - description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); - assertNotNull("5.1" + sufix, description); - assertEquals("5.2" + sufix, mytext, description.getContentType()); - assertEquals("5.3" + sufix, "BAR", description.getProperty(IContentDescription.CHARSET)); - assertSame("5.4", 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("5.5" + sufix, description); - assertEquals("5.6" + sufix, mytext, description.getContentType()); - assertEquals("5.7" + sufix, "FOO", description.getProperty(IContentDescription.CHARSET)); - assertSame("5.8", mytext.getDefaultDescription(), description); - mytext.setDefaultCharset(null); - - description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, text); - assertNotNull("5.10" + sufix, description); - assertEquals("5.11" + sufix, mytext, description.getContentType()); - assertEquals("5.12" + sufix, "BAR", description.getProperty(IContentDescription.CHARSET)); - assertSame("5.13", 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("5.14" + sufix, description); - assertEquals("5.15" + sufix, xmlType, description.getContentType()); - assertEquals("5.16" + sufix, "UTF-8", description.getProperty(IContentDescription.CHARSET)); - assertEquals("5.17", xmlType.getDefaultDescription().getCharset(), description.getCharset()); - } - assertNotNull("6.0", mytext1); - assertEquals("6.1", "BAR", mytext1.getDefaultCharset()); - assertNotNull("6.2", mytext2); - assertEquals("6.3", null, mytext2.getDefaultCharset()); + 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); + assertNull(mytext2.getDefaultCharset()); } @@ -622,23 +623,23 @@ public void testContentDetection() throws IOException { // if only inappropriate is provided, none will be selected finder = contentTypeManager.getMatcher(new SubsetSelectionPolicy(new IContentType[] { inappropriate }), null); - assertNull("1.0", finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); + assertNull(finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); // if inappropriate and appropriate are provided, appropriate will be selected finder = contentTypeManager .getMatcher(new SubsetSelectionPolicy(new IContentType[] { inappropriate, appropriate }), null); - assertEquals("2.0", appropriate, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); + assertEquals(appropriate, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); // if inappropriate, appropriate and a more specific appropriate type are // provided, the specific type will be selected finder = contentTypeManager.getMatcher( new SubsetSelectionPolicy(new IContentType[] { inappropriate, appropriate, appropriateSpecific1 }), null); - assertEquals("3.0", appropriateSpecific1, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); + assertEquals(appropriateSpecific1, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); finder = contentTypeManager.getMatcher( new SubsetSelectionPolicy(new IContentType[] { inappropriate, appropriate, appropriateSpecific2 }), null); - assertEquals("3.1", appropriateSpecific2, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); + assertEquals(appropriateSpecific2, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); // if all are provided, the more specific types will appear before the more // generic types @@ -657,7 +658,7 @@ public void testContentDetection() throws IOException { // are provided, the specific type will be selected finder = contentTypeManager.getMatcher( new SubsetSelectionPolicy(new IContentType[] { appropriate, appropriateSpecific1LowPriority }), null); - assertEquals("5.0", appropriateSpecific1LowPriority, + assertEquals(appropriateSpecific1LowPriority, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); // if appropriate and two specific appropriate types (but one with lower @@ -667,7 +668,7 @@ public void testContentDetection() throws IOException { new SubsetSelectionPolicy( new IContentType[] { appropriate, appropriateSpecific1, appropriateSpecific1LowPriority }), null); - assertEquals("5.1", appropriateSpecific1, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); + assertEquals(appropriateSpecific1, finder.findContentTypeFor(getInputStream(MINIMAL_XML), null)); } @Test @@ -677,9 +678,9 @@ public void testDefaultProperties() throws IOException /* never actually thrown IContentType mytext = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "mytext"); IContentType mytext1 = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "mytext1"); IContentType mytext2 = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "mytext2"); - assertNotNull("0.1", mytext); - assertNotNull("0.2", mytext1); - assertNotNull("0.3", mytext2); + assertNotNull(mytext); + assertNotNull(mytext1); + assertNotNull(mytext2); QualifiedName charset = IContentDescription.CHARSET; QualifiedName localCharset = new QualifiedName(PI_RESOURCES_TESTS, "charset"); @@ -692,31 +693,31 @@ public void testDefaultProperties() throws IOException /* never actually thrown IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null); description = getDescriptionFor(finder, "some contents", null, "abc.tzt", IContentDescription.ALL, true); - assertNotNull("1.0", description); - assertEquals("1.1", mytext, description.getContentType()); - assertEquals("1.2", "value1", description.getProperty(property1)); - assertNull("1.3", description.getProperty(property2)); - assertEquals("1.4", "value3", description.getProperty(property3)); - assertEquals("1.5", "BAR", description.getProperty(charset)); + assertNotNull(description); + assertEquals(mytext, description.getContentType()); + assertEquals("value1", description.getProperty(property1)); + assertNull(description.getProperty(property2)); + assertEquals("value3", description.getProperty(property3)); + assertEquals("BAR", description.getProperty(charset)); description = getDescriptionFor(finder, "some contents", null, "abc.tzt1", IContentDescription.ALL, true); - assertNotNull("2.0", description); - assertEquals("2.1", mytext1, description.getContentType()); - assertEquals("2.2", "value1", description.getProperty(property1)); - assertEquals("2.3", "value2", description.getProperty(property2)); - assertNull("2.4", description.getProperty(property3)); - assertEquals("2.5", "value4", description.getProperty(property4)); - assertEquals("2.6", "BAR", description.getProperty(charset)); + assertNotNull(description); + assertEquals(mytext1, description.getContentType()); + assertEquals("value1", description.getProperty(property1)); + assertEquals("value2", description.getProperty(property2)); + assertNull(description.getProperty(property3)); + assertEquals("value4", description.getProperty(property4)); + assertEquals("BAR", description.getProperty(charset)); description = getDescriptionFor(finder, "some contents", null, "abc.tzt2", IContentDescription.ALL, true); - assertNotNull("3.0", description); - assertEquals("3.1", mytext2, description.getContentType()); - assertNull("3.2", description.getProperty(property1)); - assertNull("3.3", description.getProperty(property2)); - assertNull("3.4", description.getProperty(property3)); - assertNull("3.5", description.getProperty(property4)); - assertNull("3.6", description.getProperty(charset)); - assertEquals("3.7", "mytext2", description.getProperty(localCharset)); + assertNotNull(description); + assertEquals(mytext2, description.getContentType()); + assertNull(description.getProperty(property1)); + assertNull(description.getProperty(property2)); + assertNull(description.getProperty(property3)); + assertNull(description.getProperty(property4)); + assertNull(description.getProperty(charset)); + assertEquals("mytext2", description.getProperty(localCharset)); } /** @@ -730,9 +731,9 @@ public void testDoubleAssociation() { IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); IContentType fooBarType = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "fooBar"); - assertNotNull("1.0", fooBarType); + assertNotNull(fooBarType); IContentType subFooBarType = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "subFooBar"); - assertNotNull("1.1", subFooBarType); + assertNotNull(subFooBarType); // ensure we don't get fooBar twice IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null); IContentType[] fooBarAssociated = finder.findContentTypesFor(changeCase("foo.bar")); @@ -748,39 +749,40 @@ public void testDoubleAssociation() { * content types are dynamicaly added/removed). */ @Test - public void testDynamicChanges() { + public void testDynamicChanges() throws Exception { final IContentType[] text = new IContentType[4]; final IContentTypeManager manager = Platform.getContentTypeManager(); text[0] = manager.getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("1.0", text[0]); + assertNotNull(text[0]); text[1] = manager.getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("1.1", text[1]); + assertNotNull(text[1]); text[0] = ((ContentTypeHandler) text[0]).getTarget(); text[1] = ((ContentTypeHandler) text[1]).getTarget(); - assertEquals("2.0", text[0], text[1]); - assertEquals("2.1", text[0], text[1]); + assertEquals(text[0], text[1]); + assertEquals(text[0], text[1]); // make arbitrary dynamic changes to the contentTypes extension point TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); - BundleTestingHelper.runWithBundles("3", () -> { + BundleTestingHelper.runWithBundles(() -> { IContentType missing = manager.getContentType("org.eclipse.bundle01.missing"); - assertNotNull("3.1", missing); + assertNotNull(missing); // ensure the content type instances are different text[2] = manager.getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("3.2", text[2]); + assertNotNull(text[2]); text[2] = ((ContentTypeHandler) text[2]).getTarget(); - assertEquals("3.3", text[0], text[2]); - assertNotSame("3.4", text[0], text[2]); - }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle01" }, listener); - assertNull("4.0", manager.getContentType("org.eclipse.bundle01.missing")); + assertEquals(text[0], text[2]); + assertNotSame(text[0], text[2]); + return null; + }, getContext(), new String[] { TEST_FILES_ROOT + "content/bundle01" }, listener); + assertNull(manager.getContentType("org.eclipse.bundle01.missing")); // ensure the content type instances are all different text[3] = manager.getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("5.0", text[3]); + assertNotNull(text[3]); text[3] = ((ContentTypeHandler) text[3]).getTarget(); - assertEquals("5.1", text[0], text[3]); - assertEquals("5.2", text[2], text[3]); - assertNotSame("5.3", text[0], text[3]); - assertNotSame("5.4", text[2], text[3]); + assertEquals(text[0], text[3]); + assertEquals(text[2], text[3]); + assertNotSame(text[0], text[3]); + assertNotSame(text[2], text[3]); } /** @@ -788,51 +790,51 @@ public void testDynamicChanges() { * org.eclipse.core.contenttype.contentTypes extension point. */ @Test - public void testDynamicChangesNewExtension() { + public void testDynamicChangesNewExtension() throws Exception { final IContentType[] text = new IContentType[4]; final IContentTypeManager manager = Platform.getContentTypeManager(); text[0] = manager.getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("1.0", text[0]); + assertNotNull(text[0]); text[1] = manager.getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("1.1", text[1]); + assertNotNull(text[1]); text[0] = ((ContentTypeHandler) text[0]).getTarget(); text[1] = ((ContentTypeHandler) text[1]).getTarget(); - assertEquals("2.0", text[0], text[1]); - assertSame("2.1", text[0], text[1]); + assertEquals(text[0], text[1]); + assertSame(text[0], text[1]); // make arbitrary dynamic changes to the contentTypes extension point TestRegistryChangeListener listener = new TestRegistryChangeListener(IContentConstants.CONTENT_NAME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); - BundleTestingHelper.runWithBundles("3", () -> { + BundleTestingHelper.runWithBundles(() -> { IContentType contentType = manager.getContentType("org.eclipse.bug485227.bug485227_contentType"); - assertNotNull("3.1 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("3.2 Text content type not modified", text[2]); + assertNotNull(text[2], "Text content type not modified"); text[2] = ((ContentTypeHandler) text[2]).getTarget(); - assertEquals("3.3", text[0], text[2]); - assertNotSame("3.4", text[0], text[2]); - assertEquals("3.5 default extension not associated", contentType, - manager.findContentTypeFor("file.bug485227")); - assertEquals("3.6 additional extension not associated", contentType, - manager.findContentTypeFor("file.bug485227_2")); - }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bug485227" }, listener); - assertNull("4.0 Content type not cleared after bundle uninstall", - manager.getContentType("org.eclipse.bug485227.bug485227_contentType")); + assertEquals(text[0], text[2]); + assertNotSame(text[0], text[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(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("5.0", text[3]); + assertNotNull(text[3]); text[3] = ((ContentTypeHandler) text[3]).getTarget(); - assertEquals("5.1", text[0], text[3]); - assertEquals("5.2", text[2], text[3]); - assertNotSame("5.3", text[0], text[3]); - assertNotSame("5.4", text[2], text[3]); + assertEquals(text[0], text[3]); + assertEquals(text[2], text[3]); + assertNotSame(text[0], text[3]); + assertNotSame(text[2], text[3]); } @Test public void testEvents() throws CoreException { IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); IContentType myType = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".myContent"); - assertNotNull("0.9", myType); + assertNotNull(myType); ContentTypeChangeTracer tracer; @@ -841,32 +843,32 @@ public void testEvents() throws CoreException { // add a file spec and check event myType.addFileSpec("another.file.name", IContentType.FILE_NAME_SPEC); - assertTrue("1.1", tracer.isOnlyChange(myType)); + assertTrue(tracer.isOnlyChange(myType)); // remove a non-existing file spec - should not cause an event to be fired tracer.reset(); myType.removeFileSpec("another.file.name", IContentType.FILE_EXTENSION_SPEC); - assertTrue("2.1", !tracer.isOnlyChange(myType)); + assertFalse(tracer.isOnlyChange(myType)); // add a file spec again and check no event is generated tracer.reset(); myType.addFileSpec("another.file.name", IContentType.FILE_NAME_SPEC); - assertTrue("3.1", !tracer.isOnlyChange(myType)); + assertFalse(tracer.isOnlyChange(myType)); // remove a file spec and check event tracer.reset(); myType.removeFileSpec("another.file.name", IContentType.FILE_NAME_SPEC); - assertTrue("4.1", tracer.isOnlyChange(myType)); + assertTrue(tracer.isOnlyChange(myType)); // change the default charset and check event tracer.reset(); myType.setDefaultCharset("FOO"); - assertTrue("5.1", tracer.isOnlyChange(myType)); + assertTrue(tracer.isOnlyChange(myType)); // set the default charset to the same - no event should be generated tracer.reset(); myType.setDefaultCharset("FOO"); - assertTrue("6.1", !tracer.isOnlyChange(myType)); + assertFalse(tracer.isOnlyChange(myType)); myType.setDefaultCharset("ABC"); } @@ -877,26 +879,26 @@ public void testFileSpecConflicts() throws IOException { // when not submitting contents, for related types, most general type prevails IContentType conflict1a = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict1"); IContentType conflict1b = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict1"); - assertNotNull("1.0", conflict1a); - assertNotNull("1.1", conflict1b); + assertNotNull(conflict1a); + assertNotNull(conflict1b); IContentType preferredConflict1 = manager.findContentTypeFor("test.conflict1"); - assertNotNull("1.2", preferredConflict1); - assertEquals("1.3", conflict1a, preferredConflict1); + assertNotNull(preferredConflict1); + assertEquals(conflict1a, preferredConflict1); IContentType conflict2base = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict2"); IContentType conflict2sub = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict2"); - assertNotNull("2.0", conflict2base); - assertNotNull("2.1", conflict2sub); + assertNotNull(conflict2base); + assertNotNull(conflict2sub); // when submitting contents, for related types with indeterminate match, general // comes first - IContentType[] selectedConflict2 = manager.findContentTypesFor(getRandomContents(), "test.conflict2"); + IContentType[] selectedConflict2 = manager.findContentTypesFor(createRandomContentsStream(), "test.conflict2"); assertThat(selectedConflict2).containsExactly(conflict2base, conflict2sub); IContentType conflict2abase = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict2a"); IContentType conflict2asub = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict2a"); - assertNotNull("2.5", conflict2abase); - assertNotNull("2.6", conflict2asub); + assertNotNull(conflict2abase); + assertNotNull(conflict2asub); // when submitting contents, for related types with valid match, specific // comes first @@ -911,42 +913,42 @@ public void testFileSpecConflicts() throws IOException { IContentType conflict3base = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict3"); IContentType conflict3sub = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict3"); IContentType conflict3unrelated = manager.getContentType(PI_RESOURCES_TESTS + ".unrelated_conflict3"); - assertNotNull("3.0.1", conflict3base); - assertNotNull("3.0.2", conflict3sub); - assertNotNull("3.0.3", conflict3unrelated); + assertNotNull(conflict3base); + assertNotNull(conflict3sub); + assertNotNull(conflict3unrelated); // Two unrelated types (sub_conflict3 and unrelated conflict3) are in conflict. // Order will be arbitrary (lexicographically). - IContentType[] selectedConflict3 = manager.findContentTypesFor(getRandomContents(), "test.conflict3"); + IContentType[] selectedConflict3 = manager.findContentTypesFor(createRandomContentsStream(), "test.conflict3"); assertThat(selectedConflict3).containsExactly(conflict3sub, conflict3unrelated); IContentType conflict4base = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict4"); IContentType conflict4sub = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict4"); IContentType conflict4unrelated_lowPriority = manager.getContentType(PI_RESOURCES_TESTS + ".unrelated_conflict4"); - assertNotNull("5.0.1", conflict4base); - assertNotNull("5.0.2", conflict4sub); - assertNotNull("5.0.4", conflict4unrelated_lowPriority); + assertNotNull(conflict4base); + assertNotNull(conflict4sub); + assertNotNull(conflict4unrelated_lowPriority); // Two unrelated types (sub_conflict4 and unrelated conflict4) are in conflict, // but with different priorities // Order will be based on priority - IContentType[] selectedConflict4 = manager.findContentTypesFor(getRandomContents(), "test.conflict4"); + IContentType[] selectedConflict4 = manager.findContentTypesFor(createRandomContentsStream(), "test.conflict4"); assertThat(selectedConflict4).containsExactly(conflict4sub, conflict4unrelated_lowPriority); IContentType conflict5base = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict5"); IContentType conflict5sub_lowPriority = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict5"); IContentType conflict5unrelated = manager.getContentType(PI_RESOURCES_TESTS + ".unrelated_conflict5"); - assertNotNull("6.0.1", conflict5base); - assertNotNull("6.0.2", conflict5sub_lowPriority); - assertNotNull("6.0.5", conflict5unrelated); + assertNotNull(conflict5base); + assertNotNull(conflict5sub_lowPriority); + assertNotNull(conflict5unrelated); // Two unrelated types (sub_conflict5 and unrelated conflict5) are in conflict, // but with different priorities // Order will be based on priority - IContentType[] selectedConflict5 = manager.findContentTypesFor(getRandomContents(), "test.conflict5"); + IContentType[] selectedConflict5 = manager.findContentTypesFor(createRandomContentsStream(), "test.conflict5"); assertThat(selectedConflict5).containsExactly(conflict5unrelated, conflict5sub_lowPriority); } @@ -961,12 +963,12 @@ public void testFindContentType() throws IOException { IContentType single; single = finder.findContentTypeFor(getInputStream("Just a test"), changeCase("file.txt")); - assertNotNull("1.0", single); - assertEquals("1.1", textContentType, single); + assertNotNull(single); + assertEquals(textContentType, single); single = finder.findContentTypeFor(getInputStream(XML_UTF_8, StandardCharsets.UTF_8), changeCase("foo.xml")); - assertNotNull("2.0", single); - assertEquals("2.1", xmlContentType, single); + assertNotNull(single); + assertEquals(xmlContentType, single); IContentType[] multiple = finder.findContentTypesFor(getInputStream(XML_UTF_8, StandardCharsets.UTF_8), null); assertThat(multiple).contains(xmlContentType); @@ -979,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"); @@ -998,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 @@ -1023,33 +1025,30 @@ public void testImportFileAssociation() throws CoreException { } @Test - public void testInvalidMarkup() { + public void testInvalidMarkup() throws Exception { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null); assertThat(finder.findContentTypesFor("invalid.missing.identifier")).isEmpty(); assertThat(finder.findContentTypesFor("invalid.missing.name")).isEmpty(); - assertNull("3.0", contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "invalid-missing-name")); + assertNull(contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "invalid-missing-name")); TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); - BundleTestingHelper.runWithBundles("1", () -> { + BundleTestingHelper.runWithBundles(() -> { // ensure the invalid content types are not available assertThat(contentTypeManager.findContentTypesFor("invalid.missing.identifier")).isEmpty(); assertThat(contentTypeManager.findContentTypesFor("invalid.missing.name")).isEmpty(); - assertNull("1.4", contentTypeManager.getContentType("org.eclipse.bundle03.invalid-missing-name")); + assertNull(contentTypeManager.getContentType("org.eclipse.bundle03.invalid-missing-name")); // this content type has good markup, but invalid describer class IContentType invalidDescriber = contentTypeManager.getContentType("org.eclipse.bundle03.invalid-describer"); - assertNotNull("1.5", invalidDescriber); + assertNotNull(invalidDescriber); // name based matching should work fine - assertEquals("1.6", invalidDescriber, contentTypeManager.findContentTypeFor("invalid.describer")); + assertEquals(invalidDescriber, contentTypeManager.findContentTypeFor("invalid.describer")); // the describer class is invalid, content matchong should fail IContentType nullContentType; - try { - nullContentType = contentTypeManager.findContentTypeFor(getRandomContents(), "invalid.describer"); - } catch (IOException e) { - throw new AssertionError(e); - } - assertNull("1.7", nullContentType); - }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle03" }, listener); + nullContentType = contentTypeManager.findContentTypeFor(createRandomContentsStream(), "invalid.describer"); + assertNull(nullContentType); + return null; + }, getContext(), new String[] { TEST_FILES_ROOT + "content/bundle03" }, listener); } /** @@ -1108,14 +1107,14 @@ public void testIsKindOf() { IContentType xmlBasedSpecificNameContentType = contentTypeManager .getContentType(PI_RESOURCES_TESTS + '.' + "xml-based-specific-name"); IContentType binaryContentType = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "sample-binary1"); - assertTrue("1.0", textContentType.isKindOf(textContentType)); - assertTrue("2.0", xmlContentType.isKindOf(textContentType)); - assertFalse("2.1", textContentType.isKindOf(xmlContentType)); - assertTrue("2.2", xmlContentType.isKindOf(xmlContentType)); - assertTrue("3.0", xmlBasedDifferentExtensionContentType.isKindOf(textContentType)); - assertTrue("3.1", xmlBasedDifferentExtensionContentType.isKindOf(xmlContentType)); - assertFalse("4.0", xmlBasedDifferentExtensionContentType.isKindOf(xmlBasedSpecificNameContentType)); - assertFalse("5.0", binaryContentType.isKindOf(textContentType)); + assertTrue(textContentType.isKindOf(textContentType)); + assertTrue(xmlContentType.isKindOf(textContentType)); + assertFalse(textContentType.isKindOf(xmlContentType)); + assertTrue(xmlContentType.isKindOf(xmlContentType)); + assertTrue(xmlBasedDifferentExtensionContentType.isKindOf(textContentType)); + assertTrue(xmlBasedDifferentExtensionContentType.isKindOf(xmlContentType)); + assertFalse(xmlBasedDifferentExtensionContentType.isKindOf(xmlBasedSpecificNameContentType)); + assertFalse(binaryContentType.isKindOf(textContentType)); } @Test @@ -1149,25 +1148,25 @@ public void testListParsing() { public void testMyContentDescriber() throws IOException { IContentTypeManager manager = Platform.getContentTypeManager(); IContentType myContent = manager.getContentType(PI_RESOURCES_TESTS + '.' + "myContent"); - assertNotNull("0.5", myContent); - assertEquals("0.6", myContent, manager.findContentTypeFor("myContent.mc1")); - assertEquals("0.7", myContent, manager.findContentTypeFor("myContent.mc2")); - assertEquals("0.8", myContent, manager.findContentTypeFor("foo.myContent1")); - assertEquals("0.9", myContent, manager.findContentTypeFor("bar.myContent2")); + assertNotNull(myContent); + assertEquals(myContent, manager.findContentTypeFor("myContent.mc1")); + assertEquals(myContent, manager.findContentTypeFor("myContent.mc2")); + assertEquals(myContent, manager.findContentTypeFor("foo.myContent1")); + assertEquals(myContent, manager.findContentTypeFor("bar.myContent2")); IContentDescription description = manager.getDescriptionFor( getInputStream(MyContentDescriber.SIGNATURE, StandardCharsets.US_ASCII), "myContent.mc1", IContentDescription.ALL); - assertNotNull("1.0", description); - assertEquals("1.1", myContent, description.getContentType()); - assertNotSame("1.2", myContent.getDefaultDescription(), description); + assertNotNull(description); + assertEquals(myContent, description.getContentType()); + assertNotSame(myContent.getDefaultDescription(), description); for (int i = 0; i < MyContentDescriber.MY_OPTIONS.length; i++) { - assertEquals("2." + 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 + ""); } } @Test - public void testNoExtensionAssociation() { + public void testNoExtensionAssociation() throws Exception { // TODO use a IContentTypeMatcher instead final IContentTypeManager manager = Platform.getContentTypeManager(); @@ -1176,7 +1175,7 @@ public void testNoExtensionAssociation() { TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); - BundleTestingHelper.runWithBundles("1", () -> { + BundleTestingHelper.runWithBundles(() -> { final String namespace = "org.eclipse.bundle04"; IContentType empty1 = manager.getContentType(namespace + ".empty_extension1"); @@ -1185,11 +1184,11 @@ public void testNoExtensionAssociation() { IContentType empty4 = manager.getContentType(namespace + ".empty_extension4"); IContentType nonEmpty = manager.getContentType(namespace + ".non_empty_extension"); - assertNotNull("1.1.1", empty1); - assertNotNull("1.1.2", empty2); - assertNotNull("1.1.3", empty3); - assertNotNull("1.1.4", empty4); - assertNotNull("1.1.5", nonEmpty); + assertNotNull(empty1); + assertNotNull(empty2); + assertNotNull(empty3); + assertNotNull(empty4); + assertNotNull(nonEmpty); IContentType[] selected1 = manager.findContentTypesFor("file_with_no_extension"); assertThat(selected1).containsExactlyInAnyOrder(empty1, empty2, empty3, empty4); @@ -1197,24 +1196,17 @@ public void testNoExtensionAssociation() { selected1 = manager.findContentTypesFor("file_with_extension.non-empty"); assertThat(selected1).containsExactly(nonEmpty); - try { - nonEmpty.addFileSpec("", IContentType.FILE_EXTENSION_SPEC); - } catch (CoreException e) { - throw new AssertionError(e); - } + nonEmpty.addFileSpec("", IContentType.FILE_EXTENSION_SPEC); try { selected1 = manager.findContentTypesFor("file_with_no_extension"); assertThat(selected1).hasSize(5).containsOnlyOnce(nonEmpty); } finally { - try { - nonEmpty.removeFileSpec("", IContentType.FILE_EXTENSION_SPEC); - } catch (CoreException e) { - throw new AssertionError(e); - } + nonEmpty.removeFileSpec("", IContentType.FILE_EXTENSION_SPEC); } selected1 = manager.findContentTypesFor("file_with_no_extension"); assertThat(selected1).hasSize(4).doesNotContain(nonEmpty); - }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle04" }, listener); + return null; + }, getContext(), new String[] { TEST_FILES_ROOT + "content/bundle04" }, listener); } @Test @@ -1227,9 +1219,9 @@ public void testOrderWithEmptyFiles() throws IOException { manager.getContentType(PI_RESOURCES_TESTS + ".dtd"); // for an empty file, the most generic content type should be returned IContentType selected = finder.findContentTypeFor(getInputStream(""), "foo.xml"); - assertEquals("1.0", xml, selected); + assertEquals(xml, selected); // it should be equivalent to omitting the contents - assertEquals("1.1", xml, finder.findContentTypeFor("foo.xml")); + assertEquals(xml, finder.findContentTypeFor("foo.xml")); } /** @@ -1237,12 +1229,12 @@ public void testOrderWithEmptyFiles() throws IOException { * content types are missing). */ @Test - public void testOrphanContentType() { + public void testOrphanContentType() throws Exception { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); IContentType orphan = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".orphan"); - assertNull("0.8", orphan); + assertNull(orphan); IContentType missing = contentTypeManager.getContentType("org.eclipse.bundle01.missing"); - assertNull("0.9", missing); + assertNull(missing); assertThat(contentTypeManager.findContentTypesFor("foo.orphan")).isEmpty(); assertThat(contentTypeManager.findContentTypesFor("orphan.orphan")).isEmpty(); assertThat(contentTypeManager.findContentTypesFor("foo.orphan2")).isEmpty(); @@ -1251,17 +1243,18 @@ public void testOrphanContentType() { TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); - BundleTestingHelper.runWithBundles("2", () -> { + BundleTestingHelper.runWithBundles(() -> { IContentType orphan1 = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".orphan"); - assertNotNull("2.1", orphan1); + assertNotNull(orphan1); IContentType missing1 = contentTypeManager.getContentType("org.eclipse.bundle01.missing"); - assertNotNull("2.2", missing1); + assertNotNull(missing1); // checks orphan's associations assertThat(contentTypeManager.findContentTypesFor("foo.orphan")).containsExactly(orphan1); assertThat(contentTypeManager.findContentTypesFor("orphan.orphan")).containsExactly(orphan1); // check whether an orphan association was added to the dynamically added bundle assertThat(contentTypeManager.findContentTypesFor("foo.orphan2")).containsExactly(missing1); - }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle01" }, listener); + return null; + }, getContext(), new String[] { TEST_FILES_ROOT + "content/bundle01" }, listener); } /** @@ -1273,57 +1266,57 @@ public void testPreferences() throws CoreException, BackingStoreException { IContentType text = manager.getContentType(IContentTypeManager.CT_TEXT); Preferences textPrefs = InstanceScope.INSTANCE.getNode(ContentTypeManager.CONTENT_TYPE_PREF_NODE) .node(text.getId()); - assertNotNull("0.1", text); + assertNotNull(text); // ensure the "default charset" preference is being properly used - assertNull("1.0", text.getDefaultCharset()); - assertNull("1.1", textPrefs.get(ContentType.PREF_DEFAULT_CHARSET, null)); + assertNull(text.getDefaultCharset()); + assertNull(textPrefs.get(ContentType.PREF_DEFAULT_CHARSET, null)); text.setDefaultCharset("UTF-8"); - assertEquals("1.2", "UTF-8", textPrefs.get(ContentType.PREF_DEFAULT_CHARSET, null)); + assertEquals("UTF-8", textPrefs.get(ContentType.PREF_DEFAULT_CHARSET, null)); text.setDefaultCharset(null); - assertNull("1.3", textPrefs.get(ContentType.PREF_DEFAULT_CHARSET, null)); + assertNull(textPrefs.get(ContentType.PREF_DEFAULT_CHARSET, null)); // ensure the file spec preferences are being properly used // some sanity checking - assertFalse("2.01", text.isAssociatedWith("xyz.foo")); - assertFalse("2.01", text.isAssociatedWith("xyz.bar")); - assertFalse("2.03", text.isAssociatedWith("foo.ext")); - assertFalse("2.04", text.isAssociatedWith("bar.ext")); + assertFalse(text.isAssociatedWith("xyz.foo")); + assertFalse(text.isAssociatedWith("xyz.bar")); + assertFalse(text.isAssociatedWith("foo.ext")); + assertFalse(text.isAssociatedWith("bar.ext")); // Null entries first to avoid interference from other tests textPrefs.remove(ContentType.PREF_FILE_NAMES); textPrefs.remove(ContentType.PREF_FILE_EXTENSIONS); // play with file name associations first... - assertNull("2.0a", textPrefs.get(ContentType.PREF_FILE_NAMES, null)); - assertNull("2.0b", textPrefs.get(ContentType.PREF_FILE_EXTENSIONS, null)); + assertNull(textPrefs.get(ContentType.PREF_FILE_NAMES, null)); + assertNull(textPrefs.get(ContentType.PREF_FILE_EXTENSIONS, null)); text.addFileSpec("foo.ext", IContentType.FILE_NAME_SPEC); - assertTrue("2.1", text.isAssociatedWith("foo.ext")); - assertEquals("2.2", "foo.ext", textPrefs.get(ContentType.PREF_FILE_NAMES, null)); + assertTrue(text.isAssociatedWith("foo.ext")); + assertEquals("foo.ext", textPrefs.get(ContentType.PREF_FILE_NAMES, null)); text.addFileSpec("bar.ext", IContentType.FILE_NAME_SPEC); - assertTrue("2.3", text.isAssociatedWith("bar.ext")); - assertEquals("2.4", "foo.ext,bar.ext", textPrefs.get(ContentType.PREF_FILE_NAMES, null)); + assertTrue(text.isAssociatedWith("bar.ext")); + assertEquals("foo.ext,bar.ext", textPrefs.get(ContentType.PREF_FILE_NAMES, null)); // ... and then with file extensions text.addFileSpec("foo", IContentType.FILE_EXTENSION_SPEC); - assertTrue("2.5", text.isAssociatedWith("xyz.foo")); - assertEquals("2.6", "foo", textPrefs.get(ContentType.PREF_FILE_EXTENSIONS, null)); + assertTrue(text.isAssociatedWith("xyz.foo")); + assertEquals("foo", textPrefs.get(ContentType.PREF_FILE_EXTENSIONS, null)); text.addFileSpec("bar", IContentType.FILE_EXTENSION_SPEC); - assertTrue("2.7", text.isAssociatedWith("xyz.bar")); - assertEquals("2.4", "foo,bar", textPrefs.get(ContentType.PREF_FILE_EXTENSIONS, null)); + assertTrue(text.isAssociatedWith("xyz.bar")); + assertEquals("foo,bar", textPrefs.get(ContentType.PREF_FILE_EXTENSIONS, null)); // remove all associations made text.removeFileSpec("foo.ext", IContentType.FILE_NAME_SPEC); text.removeFileSpec("bar.ext", IContentType.FILE_NAME_SPEC); text.removeFileSpec("foo", IContentType.FILE_EXTENSION_SPEC); text.removeFileSpec("bar", IContentType.FILE_EXTENSION_SPEC); // ensure all is as before - assertFalse("3.1", text.isAssociatedWith("xyz.foo")); - assertFalse("3.2", text.isAssociatedWith("xyz.bar")); - assertFalse("3.3", text.isAssociatedWith("foo.ext")); - assertFalse("3.4", text.isAssociatedWith("bar.ext")); + assertFalse(text.isAssociatedWith("xyz.foo")); + assertFalse(text.isAssociatedWith("xyz.bar")); + assertFalse(text.isAssociatedWith("foo.ext")); + assertFalse(text.isAssociatedWith("bar.ext")); // ensure the serialization format is correct try { text.addFileSpec("foo.bar", IContentType.FILE_NAME_SPEC); textPrefs.sync(); - assertEquals("4.0", "foo.bar", textPrefs.get(ContentType.PREF_FILE_NAMES, null)); + assertEquals("foo.bar", textPrefs.get(ContentType.PREF_FILE_NAMES, null)); } finally { // clean-up text.removeFileSpec("foo.bar", IContentType.FILE_NAME_SPEC); @@ -1336,52 +1329,52 @@ public void testRegistry() { IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null); IContentType textContentType = contentTypeManager.getContentType(Platform.PI_RUNTIME + '.' + "text"); - assertNotNull("1.0", textContentType); - assertTrue("1.1", isText(contentTypeManager, textContentType)); - assertNotNull("1.2", ((ContentTypeHandler) textContentType).getTarget().getDescriber()); + assertNotNull(textContentType); + assertTrue(isText(contentTypeManager, textContentType)); + assertNotNull(((ContentTypeHandler) textContentType).getTarget().getDescriber()); IContentType xmlContentType = contentTypeManager.getContentType(Platform.PI_RUNTIME + ".xml"); - assertNotNull("2.0", xmlContentType); - assertTrue("2.1", isText(contentTypeManager, xmlContentType)); - assertEquals("2.2", textContentType, xmlContentType.getBaseType()); + assertNotNull(xmlContentType); + assertTrue(isText(contentTypeManager, xmlContentType)); + assertEquals(textContentType, xmlContentType.getBaseType()); IContentDescriber xmlDescriber = ((ContentTypeHandler) xmlContentType).getTarget().getDescriber(); - assertNotNull("2.3", xmlDescriber); - assertTrue("2.4", xmlDescriber instanceof XMLContentDescriber); + assertNotNull(xmlDescriber); + assertThat(xmlDescriber).isInstanceOf(XMLContentDescriber.class); IContentType xmlBasedDifferentExtensionContentType = contentTypeManager .getContentType(PI_RESOURCES_TESTS + '.' + "xml-based-different-extension"); - assertNotNull("3.0", xmlBasedDifferentExtensionContentType); - assertTrue("3.1", isText(contentTypeManager, xmlBasedDifferentExtensionContentType)); - assertEquals("3.2", xmlContentType, xmlBasedDifferentExtensionContentType.getBaseType()); + assertNotNull(xmlBasedDifferentExtensionContentType); + assertTrue(isText(contentTypeManager, xmlBasedDifferentExtensionContentType)); + assertEquals(xmlContentType, xmlBasedDifferentExtensionContentType.getBaseType()); IContentType xmlBasedSpecificNameContentType = contentTypeManager .getContentType(PI_RESOURCES_TESTS + '.' + "xml-based-specific-name"); - assertNotNull("4.0", xmlBasedSpecificNameContentType); - assertTrue("4.1", isText(contentTypeManager, xmlBasedSpecificNameContentType)); - assertEquals("4.2", xmlContentType, xmlBasedSpecificNameContentType.getBaseType()); + assertNotNull(xmlBasedSpecificNameContentType); + assertTrue(isText(contentTypeManager, xmlBasedSpecificNameContentType)); + assertEquals(xmlContentType, xmlBasedSpecificNameContentType.getBaseType()); IContentType[] xmlTypes = finder.findContentTypesFor(changeCase("foo.xml")); assertThat(xmlTypes).contains(xmlContentType); IContentType binaryContentType = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "sample-binary1"); - assertNotNull("6.0", binaryContentType); - assertFalse("6.1", isText(contentTypeManager, binaryContentType)); - assertNull("6.2", binaryContentType.getBaseType()); + assertNotNull(binaryContentType); + assertFalse(isText(contentTypeManager, binaryContentType)); + assertNull(binaryContentType.getBaseType()); IContentType[] binaryTypes = finder.findContentTypesFor(changeCase("foo.samplebin1")); assertThat(binaryTypes).containsExactly(binaryContentType); IContentType myText = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".mytext"); - assertNotNull("8.0", myText); - assertEquals("8.1", "BAR", myText.getDefaultCharset()); + assertNotNull(myText); + assertEquals("BAR", myText.getDefaultCharset()); IContentType[] fooBarTypes = finder.findContentTypesFor(changeCase("foo.bar")); assertThat(fooBarTypes).hasSize(2); IContentType fooBar = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".fooBar"); - assertNotNull("9.1", fooBar); + assertNotNull(fooBar); IContentType subFooBar = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".subFooBar"); - assertNotNull("9.2", subFooBar); + assertNotNull(subFooBar); assertThat(fooBarTypes).contains(fooBar, subFooBar); } @@ -1447,17 +1440,17 @@ public void testRootElementAndDTDDescriber() throws IOException { IContentDescription description = contentTypeManager.getDescriptionFor(getInputStream( new byte[][] { IContentDescription.BOM_UTF_16BE, XML_ROOT_ELEMENT_NO_DECL.getBytes("UTF-16BE") }), "fake.xml", IContentDescription.ALL); - assertNotNull("6.0", description); - assertEquals("6.1", rootElement, description.getContentType()); - assertEquals("6.2", IContentDescription.BOM_UTF_16BE, + assertNotNull(description); + assertEquals(rootElement, description.getContentType()); + assertEquals(IContentDescription.BOM_UTF_16BE, description.getProperty(IContentDescription.BYTE_ORDER_MARK)); description = contentTypeManager.getDescriptionFor(getInputStream( new byte[][] { IContentDescription.BOM_UTF_16LE, XML_ROOT_ELEMENT_NO_DECL.getBytes("UTF-16LE") }), "fake.xml", IContentDescription.ALL); - assertNotNull("7.0", description); - assertEquals("7.1", rootElement, description.getContentType()); - assertEquals("7.2", IContentDescription.BOM_UTF_16LE, + assertNotNull(description); + assertEquals(rootElement, description.getContentType()); + assertEquals(IContentDescription.BOM_UTF_16LE, description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // due to bug 67048, the test below fails with Crimson parser (does not handle @@ -1466,9 +1459,9 @@ public void testRootElementAndDTDDescriber() throws IOException { // byte[][] // {IContentDescription.BOM_UTF_8,XML_ROOT_ELEMENT_NO_DECL.getBytes("UTF-8")}), // "fake.xml", IContentDescription.ALL); - // assertTrue("7.0", description != null); - // assertEquals("7.1", rootElement, description.getContentType()); - // assertEquals("7.2", IContentDescription.BOM_UTF_8, + // assertTrue(description != null); + // assertEquals(rootElement, description.getContentType()); + // assertEquals(IContentDescription.BOM_UTF_8, // description.getProperty(IContentDescription.BYTE_ORDER_MARK)); // bug 84354 @@ -1494,8 +1487,8 @@ public void testSignatureBeyondBufferLimit() throws IOException { IContentType rootElement = manager.getContentType(PI_RESOURCES_TESTS + ".root-element"); IContentType selected = manager.findContentTypeFor( getInputStream(comment + XML_ROOT_ELEMENT_NO_DECL, StandardCharsets.US_ASCII), "fake.xml"); - assertNotNull("1.0", selected); - assertEquals("1.1", rootElement, selected); + assertNotNull(selected); + assertEquals(rootElement, selected); } /** @@ -1506,14 +1499,14 @@ public void testUserDefinedAssociations() throws CoreException { IContentTypeManager manager = Platform.getContentTypeManager(); IContentType text = manager.getContentType((Platform.PI_RUNTIME + ".text")); - assertNull("0.1", manager.findContentTypeFor("test.mytext")); + assertNull(manager.findContentTypeFor("test.mytext")); // associate a user-defined file spec text.addFileSpec("mytext", IContentType.FILE_EXTENSION_SPEC); boolean assertionFailed = false; try { IContentType result = manager.findContentTypeFor("test.mytext"); - assertNotNull("1.1", result); - assertEquals("1.2", text, result); + assertNotNull(result); + assertEquals(text, result); } catch (AssertionError afe) { assertionFailed = true; throw afe; @@ -1522,7 +1515,7 @@ public void testUserDefinedAssociations() throws CoreException { assertFalse(assertionFailed); } IContentType result = manager.findContentTypeFor("test.mytext"); - assertNull("3.0", result); + assertNull(result); } @Test @@ -1551,4 +1544,8 @@ public int read() { assertThat(contentTypes).isEmpty(); } + private BundleContext getContext() { + return Platform.getBundle(PI_RESOURCES_TESTS).getBundleContext(); + } + } 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 ca53e61a60e..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}. @@ -77,11 +77,11 @@ protected void setOffset(long offset) { public void testReadSingleByte() throws IOException { ByteArrayInputStream underlying = new ByteArrayInputStream(DATA.getBytes()); OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7); - assertEquals("1.0", '0', stream.read()); - assertEquals("1.1", '1', stream.read()); + assertEquals('0', stream.read()); + assertEquals('1', stream.read()); stream.skip(10); - assertEquals("1.2", '2', stream.read()); - assertEquals("1.3", 13, stream.getOffset()); + assertEquals('2', stream.read()); + assertEquals(13, stream.getOffset()); stream.close(); } @@ -93,34 +93,34 @@ public void testReadBlock() throws IOException { byte[] buffer = new byte[7]; int read = stream.read(buffer); assertThat(buffer).hasSize(read); - assertEquals("1.1", DATA.substring(4, 4 + buffer.length), new String(buffer)); - assertEquals("1.2", 11, stream.getOffset()); + assertEquals(DATA.substring(4, 4 + buffer.length), new String(buffer)); + assertEquals(11, stream.getOffset()); read = stream.read(buffer, 3, 4); - assertEquals("2.0", 4, read); - assertEquals("2.1", DATA.substring(11, 11 + read), new String(buffer, 3, read)); - assertEquals("2.2", 15, stream.getOffset()); + assertEquals(4, read); + assertEquals(DATA.substring(11, 11 + read), new String(buffer, 3, read)); + assertEquals(15, stream.getOffset()); stream.mark(0); buffer = new byte[100]; read = stream.read(buffer); - assertEquals("3.0", DATA.length() - 15, read); - assertEquals("3.1", DATA.substring(15, 15 + read), new String(buffer, 0, read)); - assertEquals("3.2", 0, stream.available()); + assertEquals(DATA.length() - 15, read); + assertEquals(DATA.substring(15, 15 + read), new String(buffer, 0, read)); + assertEquals(0, stream.available()); stream.reset(); - assertEquals("4.0", 15, stream.getOffset()); + assertEquals(15, stream.getOffset()); read = stream.read(buffer, 10, 14); - assertEquals("4.1", 29, stream.getOffset()); - assertEquals("4.2", 1, stream.available()); - assertEquals("4.3", 14, read); - assertEquals("4.4", DATA.substring(15, 15 + read), new String(buffer, 10, read)); + assertEquals(29, stream.getOffset()); + assertEquals(1, stream.available()); + assertEquals(14, read); + assertEquals(DATA.substring(15, 15 + read), new String(buffer, 10, read)); read = stream.read(buffer); - assertEquals("5.0", 30, stream.getOffset()); - assertEquals("5.1", 0, stream.available()); - assertEquals("5.2", 1, read); - assertEquals("5.3", (byte) DATA.charAt(29), buffer[0]); + assertEquals(30, stream.getOffset()); + assertEquals(0, stream.available()); + assertEquals(1, read); + assertEquals((byte) DATA.charAt(29), buffer[0]); read = stream.read(buffer); - assertEquals("6.0", 30, stream.getOffset()); - assertEquals("6.1", 0, stream.available()); - assertEquals("6.2", -1, read); + assertEquals(30, stream.getOffset()); + assertEquals(0, stream.available()); + assertEquals(-1, read); stream.close(); } @@ -128,23 +128,23 @@ public void testReadBlock() throws IOException { public void testMarkAndReset() throws IOException { ByteArrayInputStream underlying = new ByteArrayInputStream(DATA.getBytes()); OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7); - assertEquals("0.1", 30, stream.available()); + assertEquals(30, stream.available()); stream.skip(13); - assertEquals("0.2", 17, stream.available()); + assertEquals(17, stream.available()); stream.mark(0); - assertEquals("2.0", 13, stream.getMark()); - assertEquals("2.1", '3', stream.read()); - assertEquals("2.2", '4', stream.read()); - assertEquals("2.3", 15, stream.getOffset()); - assertEquals("2.4", 15, stream.available()); + assertEquals(13, stream.getMark()); + assertEquals('3', stream.read()); + assertEquals('4', stream.read()); + assertEquals(15, stream.getOffset()); + assertEquals(15, stream.available()); stream.reset(); - assertEquals("2.5", 17, stream.available()); - assertEquals("2.6", 13, stream.getOffset()); + assertEquals(17, stream.available()); + assertEquals(13, stream.getOffset()); stream.reset(); - assertEquals("2.7", 17, stream.available()); - assertEquals("2.8", 13, stream.getOffset()); + assertEquals(17, stream.available()); + assertEquals(13, stream.getOffset()); stream.rewind(); - assertEquals("3.0", 0, stream.getOffset()); + assertEquals(0, stream.getOffset()); stream.close(); } @@ -155,8 +155,8 @@ public void testContentHasEOF() throws IOException { ByteArrayInputStream underlying = new ByteArrayInputStream(changedData); OpenLazyInputStream stream = new OpenLazyInputStream(underlying, 7); int c = stream.read(); - assertNotEquals("1.0", -1, c); - assertEquals("2.0", 0xFF, c); + assertNotEquals(-1, c); + assertEquals(0xFF, c); stream.close(); } @@ -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("1.0." + 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 a005f494cb2..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}. @@ -76,11 +76,11 @@ protected void setOffset(long offset) { public void testReadSingleChar() throws IOException { CharArrayReader underlying = new CharArrayReader(DATA.toCharArray()); OpenLazyReader stream = new OpenLazyReader(underlying, 7); - assertEquals("1.0", '0', stream.read()); - assertEquals("1.1", '1', stream.read()); + assertEquals('0', stream.read()); + assertEquals('1', stream.read()); stream.skip(10); - assertEquals("1.2", '2', stream.read()); - assertEquals("1.3", 13, stream.getOffset()); + assertEquals('2', stream.read()); + assertEquals(13, stream.getOffset()); stream.close(); } @@ -92,34 +92,34 @@ public void testReadBlock() throws IOException { char[] buffer = new char[7]; int read = stream.read(buffer); assertThat(buffer).hasSize(read); - assertEquals("1.1", DATA.substring(4, 4 + buffer.length), new String(buffer)); - assertEquals("1.2", 11, stream.getOffset()); + assertEquals(DATA.substring(4, 4 + buffer.length), new String(buffer)); + assertEquals(11, stream.getOffset()); read = stream.read(buffer, 3, 4); - assertEquals("2.0", 4, read); - assertEquals("2.1", DATA.substring(11, 11 + read), new String(buffer, 3, read)); - assertEquals("2.2", 15, stream.getOffset()); + assertEquals(4, read); + assertEquals(DATA.substring(11, 11 + read), new String(buffer, 3, read)); + assertEquals(15, stream.getOffset()); stream.mark(0); buffer = new char[100]; read = stream.read(buffer); - assertEquals("3.0", DATA.length() - 15, read); - assertEquals("3.1", DATA.substring(15, 15 + read), new String(buffer, 0, read)); - assertFalse("3.2", stream.ready()); + assertEquals(DATA.length() - 15, read); + assertEquals(DATA.substring(15, 15 + read), new String(buffer, 0, read)); + assertFalse(stream.ready()); stream.reset(); - assertEquals("4.0", 15, stream.getOffset()); + assertEquals(15, stream.getOffset()); read = stream.read(buffer, 10, 14); - assertEquals("4.1", 29, stream.getOffset()); - assertTrue("4.2", stream.ready()); - assertEquals("4.3", 14, read); - assertEquals("4.4", DATA.substring(15, 15 + read), new String(buffer, 10, read)); + assertEquals(29, stream.getOffset()); + assertTrue(stream.ready()); + assertEquals(14, read); + assertEquals(DATA.substring(15, 15 + read), new String(buffer, 10, read)); read = stream.read(buffer); - assertEquals("5.0", 30, stream.getOffset()); - assertFalse("5.1", stream.ready()); - assertEquals("5.2", 1, read); - assertEquals("5.3", (byte) DATA.charAt(29), buffer[0]); + assertEquals(30, stream.getOffset()); + assertFalse(stream.ready()); + assertEquals(1, read); + assertEquals((byte) DATA.charAt(29), buffer[0]); read = stream.read(buffer); - assertEquals("6.0", 30, stream.getOffset()); - assertFalse("6.1", stream.ready()); - assertEquals("6.2", -1, read); + assertEquals(30, stream.getOffset()); + assertFalse(stream.ready()); + assertEquals(-1, read); stream.close(); } @@ -127,28 +127,28 @@ public void testReadBlock() throws IOException { public void testMarkAndReset() throws IOException { CharArrayReader underlying = new CharArrayReader(DATA.toCharArray()); OpenLazyReader stream = new OpenLazyReader(underlying, 7); - assertTrue("0.1", stream.ready()); + assertTrue(stream.ready()); stream.skip(13); - assertTrue("0.2", stream.ready()); + assertTrue(stream.ready()); stream.mark(0); - assertEquals("2.0", 13, stream.getMark()); - assertEquals("2.1", '3', stream.read()); - assertEquals("2.2", '4', stream.read()); - assertEquals("2.3", 15, stream.getOffset()); - assertTrue("2.4", stream.ready()); + assertEquals(13, stream.getMark()); + assertEquals('3', stream.read()); + assertEquals('4', stream.read()); + assertEquals(15, stream.getOffset()); + assertTrue(stream.ready()); stream.reset(); - assertTrue("2.5", stream.ready()); - assertEquals("2.6", 13, stream.getOffset()); - assertEquals("2.7", 17, stream.skip(1000)); - assertFalse("2.8", stream.ready()); + assertTrue(stream.ready()); + assertEquals(13, stream.getOffset()); + assertEquals(17, stream.skip(1000)); + assertFalse(stream.ready()); stream.reset(); - assertTrue("2.9", stream.ready()); - assertEquals("2.10", 13, stream.getOffset()); + assertTrue(stream.ready()); + assertEquals(13, stream.getOffset()); stream.reset(); - assertTrue("2.11", stream.ready()); - assertEquals("2.12", 13, stream.getOffset()); + assertTrue(stream.ready()); + assertEquals(13, stream.getOffset()); stream.rewind(); - assertEquals("3.0", 0, stream.getOffset()); + assertEquals(0, stream.getOffset()); stream.close(); } @@ -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 1ea29c7f613..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,9 +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.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; @@ -29,17 +30,13 @@ 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 extends ContentTypeTest { - - @Rule - public TestName name = new TestName(); +public class SpecificContextTest { /** * A minimal scope implementation. @@ -69,30 +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("1.0", textContentType, global.findContentTypeFor(name.getMethodName() + ".global")); - assertEquals("1.1", null, local.findContentTypeFor(name.getMethodName() + ".global")); - assertEquals("2.0", textContentType, local.findContentTypeFor(name.getMethodName() + ".local")); - assertEquals("2.1", null, 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")); - try { - textContentType.removeFileSpec(name.getMethodName() + ".global", IContentType.FILE_NAME_SPEC); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + textContentType.removeFileSpec(testName + ".global", IContentType.FILE_NAME_SPEC); } @Test @@ -103,8 +96,8 @@ public void testIsAssociatedWith() throws CoreException { IContentTypeSettings localSettings = null; localSettings = textContentType.getSettings(scope); // haven't added association yet - assertFalse("1.0", textContentType.isAssociatedWith("hello.foo", scope)); - assertFalse("1.1", textContentType.isAssociatedWith("hello.foo")); + assertFalse(textContentType.isAssociatedWith("hello.foo", scope)); + assertFalse(textContentType.isAssociatedWith("hello.foo")); // associate at the scope level localSettings.addFileSpec("foo", IContentType.FILE_EXTENSION_SPEC); localSettings = textContentType.getSettings(scope); @@ -112,9 +105,9 @@ public void testIsAssociatedWith() throws CoreException { String[] fileSpecs = localSettings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC); assertThat(fileSpecs).containsExactly("foo"); // now it is associated at the scope level... - assertTrue("2.5", textContentType.isAssociatedWith("hello.foo", scope)); + assertTrue(textContentType.isAssociatedWith("hello.foo", scope)); // ...but not at the global level - assertFalse("2.6", textContentType.isAssociatedWith("hello.foo")); + assertFalse(textContentType.isAssociatedWith("hello.foo")); } } 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 645ada51de8..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,21 +13,25 @@ *******************************************************************************/ 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 java.io.*; +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; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.UnsupportedEncodingException; import java.util.Arrays; 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. */ -public class XMLContentDescriberTest extends ContentTypeTest { +public class XMLContentDescriberTest { private final static String ENCODED_TEXT = "\u1000\u20001\u3000\u4000\u5000\u6000\u7000\u8000\u9000\uA000"; private final static String ENCODING_UTF16 = "UTF-16"; private final static String ENCODING_UTF8 = "UTF-8"; @@ -62,31 +66,31 @@ public void testEncodedContents3() throws Exception { IContentDescription description = null; for (boolean[] flag : flags) { description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF8, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); - assertNull("1.0", description); + assertNull(description); description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_INCORRECT, ENCODING_UTF16, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); - assertNull("2.0", description); + assertNull(description); description = Platform.getContentTypeManager().getDescriptionFor(getReader(ENCODING_INCORRECT, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); - assertNull("3.0", description); + assertNull(description); } for (boolean[] flag : flags) { description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_EMPTY, ENCODING_UTF8, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); - assertNull("1.0", description); + assertNull(description); description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_EMPTY, ENCODING_UTF16, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); - assertNull("2.0", description); + assertNull(description); description = Platform.getContentTypeManager().getDescriptionFor(getReader(ENCODING_EMPTY, flag[0], flag[1], flag[2]), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); - assertNull("3.0", description); + assertNull(description); } } @Test public void testBug258208() throws Exception { IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(getInputStream(ENCODING_EMPTY, ENCODING_UTF8, false, true, false), "fake.xml", new QualifiedName[] {IContentDescription.CHARSET}); - assertNull("1.0", description); + assertNull(description); // empty charset should not disable the xml content type checkEncodedContents(ENCODING_UTF16, ENCODING_UTF16, ENCODING_UTF16); @@ -98,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("1.0: " + flag[0] + " " + flag[1] + " " + flag[2], description); - assertEquals("1.1: " + flag[0] + " " + flag[1] + " " + flag[2], Platform.PI_RUNTIME + ".xml", description.getContentType().getId()); - assertEquals("1.2: " + flag[0] + " " + flag[1] + " " + flag[2], 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)); } } @@ -110,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("1.0: " + flag[0] + " " + flag[1] + " " + flag[2], description); - assertEquals("1.1: " + Arrays.toString(flag), Platform.PI_RUNTIME + ".xml", description.getContentType().getId()); - assertEquals("1.2: " + 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 426d5485c06..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 @@ -29,7 +29,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform; import org.eclipse.core.tests.harness.BundleTestingHelper; -import org.eclipse.core.tests.resources.content.ContentTypeTest; import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -143,7 +142,7 @@ public static void uninstall() throws BundleException { public static void install() throws Exception { bundle = BundleTestingHelper.installBundle("", getContext(), - ContentTypeTest.TEST_FILES_ROOT + 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/META-INF/MANIFEST.MF b/runtime/tests/org.eclipse.core.tests.harness/META-INF/MANIFEST.MF index 88086087ff2..d70afdf6ca1 100644 --- a/runtime/tests/org.eclipse.core.tests.harness/META-INF/MANIFEST.MF +++ b/runtime/tests/org.eclipse.core.tests.harness/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Eclipse Core Tests Harness Bundle-SymbolicName: org.eclipse.core.tests.harness;singleton:=true -Bundle-Version: 3.17.0.qualifier +Bundle-Version: 3.17.100.qualifier Bundle-Vendor: Eclipse.org Export-Package: org.eclipse.core.tests.harness;version="2.0", org.eclipse.core.tests.harness.session, 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 d1717ea2fa3..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,13 +14,16 @@ package org.eclipse.core.tests.harness; import static java.util.Arrays.asList; +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; @@ -45,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()); } @@ -94,50 +96,39 @@ public static boolean resolveBundles(BundleContext context, Bundle[] bundles) { return wiring.resolveBundles(asList(bundles)); } - public static void runWithBundles(String tag, Runnable runnable, BundleContext context, String[] locations, TestRegistryChangeListener listener) { + public static void runWithBundles(Callable runnable, BundleContext context, String[] locations, + TestRegistryChangeListener listener) throws Exception { if (listener != null) { listener.register(); } try { Bundle[] installed = new Bundle[locations.length]; for (int i = 0; i < locations.length; i++) { - try { - installed[i] = installBundle(tag + ".setup.0", context, locations[i]); - Assert.assertEquals(tag + ".setup.1." + locations[i], Bundle.INSTALLED, installed[i].getState()); - } catch (BundleException | IOException e) { - throw new IllegalStateException( - "Exception occurred when setting up bundle at location " + locations[i] + ": " + e); - } + installed[i] = installBundle(context, locations[i]); + assertEquals(Bundle.INSTALLED, installed[i].getState(), locations[i]); } if (listener != null) { listener.reset(); } - if (!BundleTestingHelper.resolveBundles(context, installed)) { - Assert.fail(tag + ".setup.resolveBundles"); - } + assertTrue(BundleTestingHelper.resolveBundles(context, installed)); if (listener != null) { // ensure the contributions were properly added - Assert.assertTrue(tag + ".setup.4", listener.eventReceived(installed.length * 10000)); + assertTrue(listener.eventReceived(installed.length * 10000)); } try { - runnable.run(); + runnable.call(); } finally { if (listener != null) { listener.reset(); } // remove installed bundles - for (int i = 0; i < installed.length; i++) { - try { - installed[i].uninstall(); - } catch (BundleException e) { - throw new IllegalStateException( - "Exception occurred when removing bundle at location " + locations[i] + ": " + e); - } + for (Bundle element : installed) { + element.uninstall(); } BundleTestingHelper.resolveBundles(context, installed); if (listener != null) { // ensure the contributions were properly added - Assert.assertTrue(tag + ".tearDown.2", listener.eventReceived(installed.length * 10000)); + assertTrue(listener.eventReceived(installed.length * 10000)); } } } finally {