Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/org.eclipse.tests.urischeme/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Bundle-Version: 1.2.800.qualifier
Bundle-Localization: plugin
Fragment-Host: org.eclipse.urischeme;bundle-version="1.1.100"
Import-Package: org.junit.jupiter.api;version="[5.14.0,6.0.0)",
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
org.opentest4j;version="[1.2.0,2.0.0)"
Automatic-Module-Name: org.eclipse.urischeme.tests
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.junit;bundle-version="[4.12.0,5.0.0)"
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*******************************************************************************/
package org.eclipse.urischeme;

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

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -28,7 +28,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.urischeme.internal.registration.Scheme;
import org.eclipse.urischeme.internal.registration.SchemeInformation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.osgi.service.prefs.BackingStoreException;

@SuppressWarnings("restriction")
Expand All @@ -50,10 +50,10 @@ public void noSchemeDoesNothing() throws Exception {

job.run(new NullProgressMonitor());

assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
assertNull("No schemes should be registered", osRegistration.addedSchemes);
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");

}

Expand All @@ -64,10 +64,10 @@ public void noNewSchemeDoesNothing() throws Exception {

job.run(new NullProgressMonitor());

assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
assertNull("No schemes should be registered", osRegistration.addedSchemes);
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");

}

Expand All @@ -85,12 +85,12 @@ public void newSchemeRegistersNewScheme() throws Exception {

job.run(new NullProgressMonitor());

assertEquals("Wrong values written to preferences", helloScheme.getName() + "," + hello1Scheme.getName(),
preferenceNode.writtenValue);
assertTrue("Preferences not flushed", preferenceNode.flushed);
assertEquals("Wrong schemes have been registered", hello1SchemeInfo,
osRegistration.addedSchemes.iterator().next());
assertTrue("No schemes should be un-registered", osRegistration.removedSchemes.isEmpty());
assertEquals(helloScheme.getName() + "," + hello1Scheme.getName(),
preferenceNode.writtenValue, "Wrong values written to preferences");
assertTrue(preferenceNode.flushed, "Preferences not flushed");
assertEquals(hello1SchemeInfo,
osRegistration.addedSchemes.iterator().next(), "Wrong schemes have been registered");
assertTrue(osRegistration.removedSchemes.isEmpty(), "No schemes should be un-registered");
}

@Test
Expand All @@ -107,10 +107,10 @@ public void newAlreadyRegisteredSchemeDoesNoting() throws Exception {

job.run(new NullProgressMonitor());

assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
assertNull("No schemes should be registered", osRegistration.addedSchemes);
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");
}

@Test
Expand All @@ -127,17 +127,17 @@ public void unregisteredSchemeThatWasAutoregisterdOnceDoesNotAutoregisterAgain()

job.run(new NullProgressMonitor());

assertNull("Nothing should be written to preferences", preferenceNode.writtenValue);
assertFalse("Flush on preferences should not be called", preferenceNode.flushed);
assertNull("No schemes should be registered", osRegistration.addedSchemes);
assertNull("No schemes should be un-registered", osRegistration.removedSchemes);
assertNull(preferenceNode.writtenValue, "Nothing should be written to preferences");
assertFalse(preferenceNode.flushed, "Flush on preferences should not be called");
assertNull(osRegistration.addedSchemes, "No schemes should be registered");
assertNull(osRegistration.removedSchemes, "No schemes should be un-registered");
}

@Test
public void registrationOnUnsupportedRegistrationDoesNothing() throws Exception {
AutoRegisterSchemeHandlersJob job = createJob(new ArrayList<>(), "dontCare", new ArrayList<>(),
DOESNT_SUPPORT_REGISTRATION);
assertFalse("Job should not run on OSes that don't support registration", job.shouldSchedule());
assertFalse(job.shouldSchedule(), "Job should not run on OSes that don't support registration");
}

private AutoRegisterSchemeHandlersJob createJob(Collection<IScheme> installedSchemes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
*******************************************************************************/
package org.eclipse.urischeme.internal;

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

import java.util.Collection;

Expand All @@ -21,16 +22,16 @@
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.urischeme.IScheme;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class UriSchemeExtensionReaderUnitTest {

private UriSchemeHandlerSpy abcHandler;
private ConfigurationElementMock configElementForAbc;
private UriSchemeExtensionReader extensionReader;

@Before
@BeforeEach
public void setup() throws Exception {
abcHandler = new UriSchemeHandlerSpy();
configElementForAbc = new ConfigurationElementMock("abc", "abc Scheme", abcHandler);
Expand Down Expand Up @@ -58,12 +59,12 @@ public void callsFirstOfTwoHandlersForSameScheme() throws Exception {
assertEquals(abcHandler, extensionReader.getHandlerFromExtensionPoint("abc"));
}

@Test(expected = CoreException.class)
@Test
public void throwExceptionOnWrongRegisteredType() throws Exception {
ConfigurationElementMock element = new ConfigurationElementMock("abc", "abc Scheme", new Object());
setExtensionsInReader(element);

extensionReader.getHandlerFromExtensionPoint("abc");
assertThrows(CoreException.class, () -> extensionReader.getHandlerFromExtensionPoint("abc"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
*******************************************************************************/
package org.eclipse.urischeme.internal;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collection;
import java.util.HashMap;
Expand All @@ -25,16 +26,16 @@
import org.eclipse.urischeme.IScheme;
import org.eclipse.urischeme.IUriSchemeExtensionReader;
import org.eclipse.urischeme.IUriSchemeHandler;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class UriSchemeProcessorUnitTest {

private UriSchemeHandlerSpy abcHandler;
private UriSchemeProcessor schemeProcessor;
private UriSchemeExtensionReaderMock extensionReader;

@Before
@BeforeEach
public void setup() throws Exception {
abcHandler = new UriSchemeHandlerSpy();
extensionReader = new UriSchemeExtensionReaderMock();
Expand All @@ -49,7 +50,7 @@ public void callsRegisteredUriSchemeHandler() throws Exception {
schemeProcessor.handleUri("abc", "abc://test");

String errorMsg = "Registered handler was not called for '" + "abc://test" + "'";
assertTrue(errorMsg, abcHandler.uris.contains("abc://test"));
assertTrue(abcHandler.uris.contains("abc://test"), errorMsg);
}

@Test
Expand All @@ -65,13 +66,13 @@ public void buffersExtensionAndCreatesThemOnlyOnce() throws Exception {
schemeProcessor.handleUri("abc", "abc://test");

assertEquals(2, abcHandler.uris.size());
assertEquals("Extension created more than once", 1, (int) extensionReader.readCount.get("abc"));
assertEquals(1, (int) extensionReader.readCount.get("abc"), "Extension created more than once");
}

@Test(expected = CoreException.class)
@Test
public void passesException() throws Exception {
extensionReader.exception = new CoreException(Status.CANCEL_STATUS);
schemeProcessor.handleUri("abc", "abc://test");
assertThrows(CoreException.class, () -> schemeProcessor.handleUri("abc", "abc://test"));
}

private static class UriSchemeExtensionReaderMock implements IUriSchemeExtensionReader {
Expand Down
Loading
Loading