diff options
Diffstat (limited to 'bundles/org.eclipse.osgi.tests/src/org/eclipse')
31 files changed, 442 insertions, 465 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllExtendedLogServiceTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllExtendedLogServiceTests.java index 7f796ed6d..e9f4c1b0b 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllExtendedLogServiceTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllExtendedLogServiceTests.java @@ -10,14 +10,10 @@ ******************************************************************************/ package org.eclipse.equinox.log.test; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +@RunWith(Suite.class) +@Suite.SuiteClasses({ ExtendedLogServiceTest.class, ExtendedLogReaderServiceTest.class }) public class AllExtendedLogServiceTests { - public static Test suite() { - TestSuite suite = new TestSuite("Test extended log service"); //$NON-NLS-1$ - suite.addTestSuite(ExtendedLogServiceTest.class); - suite.addTestSuite(ExtendedLogReaderServiceTest.class); - return suite; - } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllLogServiceTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllLogServiceTests.java index 687defe94..f0e6e5332 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllLogServiceTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllLogServiceTests.java @@ -10,15 +10,10 @@ ******************************************************************************/ package org.eclipse.equinox.log.test; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +@RunWith(Suite.class) +@Suite.SuiteClasses({ LogServiceTest.class, LogReaderServiceTest.class, LogPermissionCollectionTest.class }) public class AllLogServiceTests { - public static Test suite() { - TestSuite suite = new TestSuite("Test log service"); //$NON-NLS-1$ - suite.addTestSuite(LogServiceTest.class); - suite.addTestSuite(LogReaderServiceTest.class); - suite.addTestSuite(LogPermissionCollectionTest.class); - return suite; - } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllTests.java index 5f95abd31..c2cf5937c 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/AllTests.java @@ -1,27 +1,22 @@ /******************************************************************************* -s -s 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 + * Copyright (c) 2007, 2016 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 + * Contributors: + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.equinox.log.test; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +@RunWith(Suite.class) +@Suite.SuiteClasses({AllLogServiceTests.class, AllExtendedLogServiceTests.class}) public class AllTests { - - public static Test suite() { - TestSuite suite = new TestSuite("Test for org.eclipse.equinox.log.test"); //$NON-NLS-1$ - suite.addTest(AllLogServiceTests.suite()); - suite.addTest(AllExtendedLogServiceTests.suite()); - return suite; - } - } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java index ee57016f5..179e0317f 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java @@ -10,16 +10,21 @@ ******************************************************************************/ package org.eclipse.equinox.log.test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; import org.eclipse.equinox.log.ExtendedLogEntry; import org.eclipse.equinox.log.ExtendedLogReaderService; import org.eclipse.equinox.log.ExtendedLogService; import org.eclipse.equinox.log.LogFilter; import org.eclipse.equinox.log.SynchronousLogListener; import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogEntry; @@ -30,7 +35,7 @@ import org.osgi.service.log.Logger; import org.osgi.service.log.admin.LoggerAdmin; import org.osgi.service.log.admin.LoggerContext; -public class ExtendedLogReaderServiceTest extends TestCase { +public class ExtendedLogReaderServiceTest { private ExtendedLogService log; private ServiceReference logReference; @@ -42,11 +47,8 @@ public class ExtendedLogReaderServiceTest extends TestCase { Map<String, LogLevel> rootLogLevels; boolean called; - public ExtendedLogReaderServiceTest(String name) { - super(name); - } - - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { logReference = OSGiTestsActivator.getContext().getServiceReference(ExtendedLogService.class.getName()); readerReference = OSGiTestsActivator.getContext().getServiceReference(ExtendedLogReaderService.class.getName()); loggerAdminReference = OSGiTestsActivator.getContext().getServiceReference(LoggerAdmin.class); @@ -63,13 +65,15 @@ public class ExtendedLogReaderServiceTest extends TestCase { rootLoggerContext.setLogLevels(copyLogLevels); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { rootLoggerContext.setLogLevels(rootLogLevels); OSGiTestsActivator.getContext().ungetService(loggerAdminReference); OSGiTestsActivator.getContext().ungetService(logReference); OSGiTestsActivator.getContext().ungetService(readerReference); } + @Test public void testaddFilteredListener() throws Exception { TestListener listener = new TestListener(); reader.addLogListener(listener, new LogFilter() { @@ -81,6 +85,7 @@ public class ExtendedLogReaderServiceTest extends TestCase { assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO); } + @Test public void testaddNullFilterr() throws Exception { TestListener listener = new TestListener(); @@ -92,6 +97,7 @@ public class ExtendedLogReaderServiceTest extends TestCase { fail(); } + @Test public void testaddFilteredListenerTwice() throws Exception { TestListener listener = new TestListener(); reader.addLogListener(listener, new LogFilter() { @@ -112,6 +118,7 @@ public class ExtendedLogReaderServiceTest extends TestCase { assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO); } + @Test public void testaddNullListener() throws Exception { try { reader.addLogListener(null); @@ -121,6 +128,7 @@ public class ExtendedLogReaderServiceTest extends TestCase { fail(); } + @Test public void testBadFilter() throws Exception { TestListener listener = new TestListener(); reader.addLogListener(listener, new LogFilter() { @@ -133,6 +141,7 @@ public class ExtendedLogReaderServiceTest extends TestCase { fail(); } + @Test public void testSynchronousLogListener() throws Exception { final Thread loggerThread = Thread.currentThread(); called = false; @@ -147,6 +156,7 @@ public class ExtendedLogReaderServiceTest extends TestCase { assertTrue(called); } + @Test public void testExtendedLogEntry() throws Exception { TestListener listener = new TestListener(); reader.addLogListener(listener); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java index 4e8c52268..116b8c43f 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java @@ -12,14 +12,20 @@ s This *******************************************************************************/ package org.eclipse.equinox.log.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; import org.eclipse.equinox.log.ExtendedLogEntry; import org.eclipse.equinox.log.ExtendedLogReaderService; import org.eclipse.equinox.log.ExtendedLogService; import org.eclipse.equinox.log.LogFilter; import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogLevel; @@ -28,7 +34,7 @@ import org.osgi.service.log.Logger; import org.osgi.service.log.admin.LoggerAdmin; import org.osgi.service.log.admin.LoggerContext; -public class ExtendedLogServiceTest extends TestCase { +public class ExtendedLogServiceTest { private Bundle bundle; private ExtendedLogService log; @@ -42,11 +48,8 @@ public class ExtendedLogServiceTest extends TestCase { private TestListener listener; - public ExtendedLogServiceTest(String name) { - super(name); - } - - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { bundle = OSGiTestsActivator.getContext().getBundle(); logReference = OSGiTestsActivator.getContext().getServiceReference(ExtendedLogService.class.getName()); readerReference = OSGiTestsActivator.getContext().getServiceReference(ExtendedLogReaderService.class.getName()); @@ -67,7 +70,8 @@ public class ExtendedLogServiceTest extends TestCase { rootLoggerContext.setLogLevels(copyLogLevels); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { rootLoggerContext.setLogLevels(rootLogLevels); reader.removeLogListener(listener); OSGiTestsActivator.getContext().ungetService(loggerAdminReference); @@ -75,32 +79,38 @@ public class ExtendedLogServiceTest extends TestCase { OSGiTestsActivator.getContext().ungetService(readerReference); } + @Test public void testLogContext() throws Exception { log.log(this, LogService.LOG_INFO, null); assertTrue(listener.getEntryX().getContext() == this); } + @Test public void testNullLogContext() throws Exception { log.log(null, LogService.LOG_INFO, null); assertTrue(listener.getEntryX().getContext() == null); } + @Test public void testLogContextWithNullThrowable() throws Exception { log.log(this, LogService.LOG_INFO, null, null); assertTrue(listener.getEntryX().getContext() == this); } + @Test public void testIsLoggableTrue() throws Exception { if (!log.isLoggable(LogService.LOG_INFO)) fail(); } + @Test public void testNotIsLoggableWithNoListener() throws Exception { reader.removeLogListener(listener); if (log.isLoggable(LogService.LOG_INFO)) fail(); } + @Test public void testNotIsLoggableWithListener() throws Exception { reader.addLogListener(listener, new LogFilter() { @@ -112,6 +122,7 @@ public class ExtendedLogServiceTest extends TestCase { fail(); } + @Test public void testNamedLoggerLogNull() throws Exception { log.getLogger("test").log(null, 0, null, null); ExtendedLogEntry entry = listener.getEntryX(); @@ -122,6 +133,7 @@ public class ExtendedLogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testNullLoggerLogNull() throws Exception { log.getLogger((String) null).log(null, 0, null, null); ExtendedLogEntry entry = listener.getEntryX(); @@ -132,6 +144,7 @@ public class ExtendedLogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testNamedLoggerLogFull() throws Exception { String message = "test"; Throwable t = new Throwable("test"); @@ -145,6 +158,7 @@ public class ExtendedLogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == logReference); } + @Test public void testNamedLoggerLogFullWithNullBundle() throws Exception { String message = "test"; Throwable t = new Throwable("test"); @@ -158,6 +172,7 @@ public class ExtendedLogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == logReference); } + @Test public void testNamedLoggerLogFullWithBundle() throws Exception { String message = "test"; Throwable t = new Throwable("test"); @@ -171,6 +186,7 @@ public class ExtendedLogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == logReference); } + @Test public void testLoggerIsLoggableTrue() throws Exception { reader.addLogListener(listener, new LogFilter() { @@ -184,6 +200,7 @@ public class ExtendedLogServiceTest extends TestCase { fail(); } + @Test public void testLoggerNotIsLoggableWithListener() throws Exception { reader.addLogListener(listener, new LogFilter() { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogPermissionCollectionTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogPermissionCollectionTest.java index 9550636f3..ca177f212 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogPermissionCollectionTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogPermissionCollectionTest.java @@ -10,12 +10,15 @@ ******************************************************************************/ package org.eclipse.equinox.log.test; -import junit.framework.TestCase; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.eclipse.equinox.log.LogPermission; import org.eclipse.equinox.log.LogPermissionCollection; +import org.junit.Test; -public class LogPermissionCollectionTest extends TestCase { - +public class LogPermissionCollectionTest { + @Test public void testImplies() { LogPermission permission = new LogPermission("*", "*"); //$NON-NLS-1$//$NON-NLS-2$ diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java index 497cfbeb1..f7c5cc7d7 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java @@ -1,23 +1,27 @@ /******************************************************************************* -s -s 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 + * Copyright (c) 20107, 2020 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.equinox.log.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; -import junit.framework.TestCase; import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; @@ -30,7 +34,7 @@ import org.osgi.service.log.admin.LoggerAdmin; import org.osgi.service.log.admin.LoggerContext; @SuppressWarnings("deprecation") -public class LogServiceTest extends TestCase { +public class LogServiceTest { private LogService log; private ServiceReference logReference; @@ -42,11 +46,8 @@ public class LogServiceTest extends TestCase { LoggerContext rootLoggerContext; Map<String, LogLevel> rootLogLevels; - public LogServiceTest(String name) { - super(name); - } - - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { logReference = OSGiTestsActivator.getContext().getServiceReference(LogService.class.getName()); readerReference = OSGiTestsActivator.getContext().getServiceReference(LogReaderService.class.getName()); loggerAdminReference = OSGiTestsActivator.getContext().getServiceReference(LoggerAdmin.class); @@ -66,7 +67,8 @@ public class LogServiceTest extends TestCase { rootLoggerContext.setLogLevels(copyLogLevels); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { rootLoggerContext.setLogLevels(rootLogLevels); reader.removeLogListener(listener); OSGiTestsActivator.getContext().ungetService(loggerAdminReference); @@ -74,21 +76,25 @@ public class LogServiceTest extends TestCase { OSGiTestsActivator.getContext().ungetService(readerReference); } + @Test public void testLogDebug() throws Exception { log.log(LogService.LOG_DEBUG, "debug"); //$NON-NLS-1$ assertTrue(listener.getEntryX().getLevel() == LogService.LOG_DEBUG); } + @Test public void testLogError() throws Exception { log.log(LogService.LOG_ERROR, "error"); //$NON-NLS-1$ assertTrue(listener.getEntryX().getLevel() == LogService.LOG_ERROR); } + @Test public void testLogInfo() throws Exception { log.log(LogService.LOG_INFO, "info"); //$NON-NLS-1$ assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO); } + @Test public void testLogWarning() throws Exception { log.log(LogService.LOG_WARNING, "warning"); //$NON-NLS-1$ assertTrue(listener.getEntryX().getLevel() == LogService.LOG_WARNING); @@ -99,47 +105,56 @@ public class LogServiceTest extends TestCase { assertTrue(listener.getEntryX().getLevel() == 0); } + @Test public void testLogNegativeLevel() throws Exception { log.log(-1, "negative"); //$NON-NLS-1$ assertTrue(listener.getEntryX().getLevel() == -1); } + @Test public void testLogMessage() throws Exception { log.log(LogService.LOG_INFO, "message"); //$NON-NLS-1$ assertTrue(listener.getEntryX().getMessage().equals("message")); //$NON-NLS-1$ } + @Test public void testLogNullMessage() throws Exception { log.log(LogService.LOG_INFO, null); assertTrue(listener.getEntryX().getMessage() == null); } + @Test public void testLogThrowable() throws Exception { Throwable t = new Throwable("throwable"); //$NON-NLS-1$ log.log(LogService.LOG_INFO, null, t); assertTrue(listener.getEntryX().getException().getMessage().equals(t.getMessage())); } + @Test public void testLogNullThrowable() throws Exception { log.log(LogService.LOG_INFO, null, null); assertTrue(listener.getEntryX().getException() == null); } + @Test public void testLogServiceReference() throws Exception { log.log(logReference, LogService.LOG_INFO, null); assertTrue(listener.getEntryX().getServiceReference().equals(logReference)); } + @Test public void testNullLogServiceReference() throws Exception { log.log(null, LogService.LOG_INFO, null); assertTrue(listener.getEntryX().getServiceReference() == null); } + @Test public void testLogServiceReferenceWithNullThrowable() throws Exception { log.log(logReference, LogService.LOG_INFO, null, null); assertTrue(listener.getEntryX().getServiceReference().equals(logReference)); } + @Test public void testLogNull1() throws Exception { log.log(0, null); LogEntry entry = listener.getEntryX(); @@ -149,6 +164,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testLogNull2() throws Exception { log.log(0, null, null); LogEntry entry = listener.getEntryX(); @@ -158,6 +174,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testLogNull3() throws Exception { log.log(null, 0, null); LogEntry entry = listener.getEntryX(); @@ -167,6 +184,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testLogNull4() throws Exception { log.log(null, 0, null, null); LogEntry entry = listener.getEntryX(); @@ -176,6 +194,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testLogFull1() throws Exception { String message = "test"; //$NON-NLS-1$ log.log(LogService.LOG_INFO, message); @@ -186,6 +205,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testLogFull2() throws Exception { String message = "test"; //$NON-NLS-1$ Throwable t = new Throwable("test"); //$NON-NLS-1$ @@ -197,6 +217,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == null); } + @Test public void testLogFull3() throws Exception { String message = "test"; //$NON-NLS-1$ log.log(logReference, LogService.LOG_INFO, message); @@ -207,6 +228,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == logReference); } + @Test public void testLogFull4() throws Exception { String message = "test"; //$NON-NLS-1$ Throwable t = new Throwable("test"); //$NON-NLS-1$ @@ -218,6 +240,7 @@ public class LogServiceTest extends TestCase { assertTrue(entry.getServiceReference() == logReference); } + @Test public void testServiceEventLog() throws InterruptedException { BundleContext context = OSGiTestsActivator.getContext(); ServiceRegistration<Object> reg = context.registerService(Object.class, new Object(), null); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener2.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener2.java index dfd038b70..dc04e7b9c 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener2.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener2.java @@ -10,16 +10,17 @@ ******************************************************************************/ package org.eclipse.equinox.log.test; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; -import junit.framework.TestCase; import org.osgi.service.log.LogEntry; import org.osgi.service.log.LogListener; -public class TestListener2 extends TestCase implements LogListener { +public class TestListener2 implements LogListener { private List<String> list; private AtomicInteger flag = new AtomicInteger(0); CountDownLatch latch; @@ -31,7 +32,8 @@ public class TestListener2 extends TestCase implements LogListener { @Override public void logged(LogEntry entry) { - //logged is never called in parallel. Added a check to see if two threads are accessing the logged method at the same time. + // logged is never called in parallel. Added a check to see if two threads are + // accessing the logged method at the same time. assertTrue(flag.compareAndSet(0, 1)); if (entry.getBundle().getSymbolicName().equals("org.eclipse.osgi")) { list.add(entry.getMessage()); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/AutomatedTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/AutomatedTests.java index 24b855203..4e4bbfe86 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/AutomatedTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/AutomatedTests.java @@ -13,60 +13,34 @@ *******************************************************************************/ package org.eclipse.osgi.tests; -import junit.framework.*; import org.eclipse.osgi.tests.bundles.BundleTests; import org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase; import org.eclipse.osgi.tests.eventmgr.EventManagerTests; -import org.eclipse.osgi.tests.filter.FilterTests; +import org.eclipse.osgi.tests.filter.BundleContextFilterTests; +import org.eclipse.osgi.tests.filter.FrameworkUtilFilterTests; import org.eclipse.osgi.tests.hooks.framework.AllFrameworkHookTests; import org.eclipse.osgi.tests.internal.plugins.InstallTests; import org.eclipse.osgi.tests.listeners.ExceptionHandlerTests; import org.eclipse.osgi.tests.misc.MiscTests; -import org.eclipse.osgi.tests.permissions.PermissionTests; +import org.eclipse.osgi.tests.permissions.AdminPermissionTests; +import org.eclipse.osgi.tests.permissions.PackagePermissionTests; +import org.eclipse.osgi.tests.permissions.ServicePermissionTests; import org.eclipse.osgi.tests.serviceregistry.ServiceRegistryTests; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; -public class AutomatedTests extends TestCase { - public final static String PI_OSGI_TESTS = "org.eclipse.osgi.tests"; //$NON-NLS-1$ +@RunWith(Suite.class) +@Suite.SuiteClasses({ org.eclipse.osgi.tests.container.AllTests.class, AllFrameworkHookTests.class, InstallTests.class, + org.eclipse.osgi.tests.eclipseadaptor.AllTests.class, org.eclipse.osgi.tests.services.resolver.AllTests.class, + DebugOptionsTestCase.class, org.eclipse.equinox.log.test.AllTests.class, + org.eclipse.osgi.tests.security.SecurityTestSuite.class, org.eclipse.osgi.tests.appadmin.AllTests.class, + ExceptionHandlerTests.class, org.eclipse.osgi.tests.configuration.AllTests.class, + org.eclipse.osgi.tests.services.datalocation.AllTests.class, org.eclipse.osgi.tests.util.AllTests.class, + MiscTests.class, BundleTests.class, ServiceRegistryTests.class, EventManagerTests.class, + BundleContextFilterTests.class, FrameworkUtilFilterTests.class, AdminPermissionTests.class, + ServicePermissionTests.class, PackagePermissionTests.class, + org.eclipse.osgi.tests.securityadmin.AllSecurityAdminTests.class, + org.eclipse.osgi.tests.resource.AllTests.class }) - /** - * AllTests constructor. - */ - public AutomatedTests() { - super(null); - } - - /** - * AllTests constructor comment. - * @param name java.lang.String - */ - public AutomatedTests(String name) { - super(name); - } - - public static Test suite() { - TestSuite suite = new TestSuite(AutomatedTests.class.getName()); - // suite.addTest(new TestSuite(SimpleTests.class)); - suite.addTest(org.eclipse.osgi.tests.container.AllTests.suite()); - suite.addTest(AllFrameworkHookTests.suite()); - suite.addTest(new TestSuite(InstallTests.class)); - suite.addTest(org.eclipse.osgi.tests.eclipseadaptor.AllTests.suite()); - suite.addTest(org.eclipse.osgi.tests.services.resolver.AllTests.suite()); - suite.addTest(DebugOptionsTestCase.suite()); - suite.addTest(org.eclipse.equinox.log.test.AllTests.suite()); - suite.addTest(org.eclipse.osgi.tests.security.SecurityTestSuite.suite()); - suite.addTest(org.eclipse.osgi.tests.appadmin.AllTests.suite()); - suite.addTest(new TestSuite(ExceptionHandlerTests.class)); - suite.addTest(org.eclipse.osgi.tests.configuration.AllTests.suite()); - suite.addTest(org.eclipse.osgi.tests.services.datalocation.AllTests.suite()); - suite.addTest(org.eclipse.osgi.tests.util.AllTests.suite()); - suite.addTest(MiscTests.suite()); - suite.addTest(BundleTests.suite()); - suite.addTest(ServiceRegistryTests.suite()); - suite.addTest(EventManagerTests.suite()); - suite.addTest(FilterTests.suite()); - suite.addTest(PermissionTests.suite()); - suite.addTest(org.eclipse.osgi.tests.securityadmin.AllSecurityAdminTests.suite()); - suite.addTest(org.eclipse.osgi.tests.resource.AllTests.suite()); - return suite; - } +public class AutomatedTests { } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java index f37b5beac..4c0beeb53 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/AllTests.java @@ -13,14 +13,10 @@ *******************************************************************************/ package org.eclipse.osgi.tests.eclipseadaptor; -import junit.framework.*; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +@RunWith(Suite.class) +@Suite.SuiteClasses({ EnvironmentInfoTest.class, FilePathTest.class, LocaleTransformationTest.class }) public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite(AllTests.class.getName()); - suite.addTest(EnvironmentInfoTest.suite()); - suite.addTest(FilePathTest.suite()); - suite.addTest(new JUnit4TestAdapter(LocaleTransformationTest.class)); - return suite; - } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/EnvironmentInfoTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/EnvironmentInfoTest.java index a2eeadc45..ff7e4952b 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/EnvironmentInfoTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eclipseadaptor/EnvironmentInfoTest.java @@ -13,21 +13,15 @@ *******************************************************************************/ package org.eclipse.osgi.tests.eclipseadaptor; -import org.eclipse.osgi.internal.framework.EquinoxConfiguration; +import static org.junit.Assert.assertEquals; -import junit.framework.*; +import org.eclipse.osgi.internal.framework.EquinoxConfiguration; import org.eclipse.osgi.service.environment.Constants; +import org.junit.Test; -public class EnvironmentInfoTest extends TestCase { - - public static Test suite() { - return new TestSuite(EnvironmentInfoTest.class); - } - - public EnvironmentInfoTest(String name) { - super(name); - } +public class EnvironmentInfoTest { + @Test public void testAIX() { assertEquals("1.0", Constants.OS_AIX, EquinoxConfiguration.guessOS("AIX")); assertEquals("1.1", Constants.OS_AIX, EquinoxConfiguration.guessOS("aix")); @@ -35,6 +29,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_MOTIF, EquinoxConfiguration.guessWS(Constants.OS_AIX)); } + @Test public void testHPUX() { assertEquals("1.0", Constants.OS_HPUX, EquinoxConfiguration.guessOS("HP-UX")); assertEquals("1.1", Constants.OS_HPUX, EquinoxConfiguration.guessOS("hp-ux")); @@ -42,6 +37,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_MOTIF, EquinoxConfiguration.guessWS(Constants.OS_HPUX)); } + @Test public void testLinux() { assertEquals("1.0", Constants.OS_LINUX, EquinoxConfiguration.guessOS("Linux")); assertEquals("1.1", Constants.OS_LINUX, EquinoxConfiguration.guessOS("linux")); @@ -49,6 +45,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_GTK, EquinoxConfiguration.guessWS(Constants.OS_LINUX)); } + @Test public void testMacOSX() { assertEquals("1.0", Constants.OS_MACOSX, EquinoxConfiguration.guessOS("Mac OS")); assertEquals("1.1", Constants.OS_MACOSX, EquinoxConfiguration.guessOS("Mac OS X")); @@ -56,6 +53,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_COCOA, EquinoxConfiguration.guessWS(Constants.OS_MACOSX)); } + @Test public void testQNX() { assertEquals("1.0", Constants.OS_QNX, EquinoxConfiguration.guessOS("QNX")); assertEquals("1.1", Constants.OS_QNX, EquinoxConfiguration.guessOS("qnx")); @@ -63,6 +61,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_PHOTON, EquinoxConfiguration.guessWS(Constants.OS_QNX)); } + @Test public void testSolaris() { assertEquals("1.0", Constants.OS_UNKNOWN, EquinoxConfiguration.guessOS("Solaris")); assertEquals("1.1", Constants.OS_UNKNOWN, EquinoxConfiguration.guessOS("solaris")); @@ -73,6 +72,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_GTK, EquinoxConfiguration.guessWS(Constants.OS_SOLARIS)); } + @Test public void testWindows() { assertEquals("1.0", Constants.OS_WIN32, EquinoxConfiguration.guessOS("Windows XP")); assertEquals("1.1", Constants.OS_WIN32, EquinoxConfiguration.guessOS("Windows 98")); @@ -82,6 +82,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_WIN32, EquinoxConfiguration.guessWS(Constants.OS_WIN32)); } + @Test public void testISeries() { assertEquals("1.0", Constants.OS_OS400, EquinoxConfiguration.guessOS("OS/400")); assertEquals("1.1", Constants.OS_OS400, EquinoxConfiguration.guessOS("os/400")); @@ -89,6 +90,7 @@ public class EnvironmentInfoTest extends TestCase { assertEquals("2.0", Constants.WS_UNKNOWN, EquinoxConfiguration.guessWS(Constants.OS_OS400)); } + @Test public void testZSeries() { assertEquals("1.0", Constants.OS_OS390, EquinoxConfiguration.guessOS("OS/390")); assertEquals("1.1", Constants.OS_OS390, EquinoxConfiguration.guessOS("os/390")); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eventmgr/EventManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eventmgr/EventManagerTests.java index dfd25022d..53baadfc2 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eventmgr/EventManagerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/eventmgr/EventManagerTests.java @@ -13,15 +13,25 @@ *******************************************************************************/ package org.eclipse.osgi.tests.eventmgr; -import java.util.*; -import junit.framework.*; +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 java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap; +import org.junit.Test; -public class EventManagerTests extends TestCase { - public static Test suite() { - return new TestSuite(EventManagerTests.class); - } +public class EventManagerTests { + @Test public void testCopyOnWriteIdentityMap() { Object l1 = new Object(); Object l2 = new Object(); @@ -162,9 +172,9 @@ public class EventManagerTests extends TestCase { assertTrue("missed key", k1.contains(l2)); //$NON-NLS-1$ assertTrue("missed key", k1.contains(l3)); //$NON-NLS-1$ assertTrue("missed key", k1.contains(l4)); //$NON-NLS-1$ - assertTrue("missed key", k1.containsAll(Arrays.asList(new Object[] {l1, l2, l3, l4}))); //$NON-NLS-1$ - assertTrue("array unequal", Arrays.equals(new Object[] {l1, l3, l2, l4}, k1.toArray())); //$NON-NLS-1$ - assertTrue("array unequal", Arrays.equals(new Object[] {l1, l3, l2, l4}, k1.toArray(new Object[4]))); //$NON-NLS-1$ + assertTrue("missed key", k1.containsAll(Arrays.asList(new Object[] { l1, l2, l3, l4 }))); //$NON-NLS-1$ + assertTrue("array unequal", Arrays.equals(new Object[] { l1, l3, l2, l4 }, k1.toArray())); //$NON-NLS-1$ + assertTrue("array unequal", Arrays.equals(new Object[] { l1, l3, l2, l4 }, k1.toArray(new Object[4]))); //$NON-NLS-1$ Iterator i1 = k1.iterator(); assertTrue("missing next", i1.hasNext()); //$NON-NLS-1$ @@ -192,7 +202,7 @@ public class EventManagerTests extends TestCase { i1.next(); fail("next did not throw exception"); //$NON-NLS-1$ } catch (NoSuchElementException e) { - //expected + // expected } assertTrue("not empty", k2.isEmpty()); //$NON-NLS-1$ @@ -204,28 +214,28 @@ public class EventManagerTests extends TestCase { i2.next(); fail("next did not throw exception"); //$NON-NLS-1$ } catch (NoSuchElementException e) { - //expected + // expected } try { k2.add(l1); fail("add did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } try { - k2.addAll(Arrays.asList(new Object[] {l1, l2})); + k2.addAll(Arrays.asList(new Object[] { l1, l2 })); fail("addAll did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } k3.remove(l3); assertFalse("not removed", k3.contains(l3)); //$NON-NLS-1$ - k3.removeAll(Arrays.asList(new Object[] {l1, l2})); + k3.removeAll(Arrays.asList(new Object[] { l1, l2 })); assertFalse("not removed", k3.contains(l1)); //$NON-NLS-1$ assertFalse("not removed", k3.contains(l2)); //$NON-NLS-1$ - k4.retainAll(Arrays.asList(new Object[] {l1, l2})); + k4.retainAll(Arrays.asList(new Object[] { l1, l2 })); assertTrue("missing", k4.contains(l1)); //$NON-NLS-1$ assertTrue("missing", k4.contains(l2)); //$NON-NLS-1$ assertFalse("not removed", k4.contains(l3)); //$NON-NLS-1$ @@ -239,9 +249,9 @@ public class EventManagerTests extends TestCase { assertTrue("missed key", v1.contains(c2)); //$NON-NLS-1$ assertTrue("missed key", v1.contains(c3)); //$NON-NLS-1$ assertTrue("missed key", v1.contains(c4)); //$NON-NLS-1$ - assertTrue("missed key", v1.containsAll(Arrays.asList(new Object[] {c1, c2, c3, c4}))); //$NON-NLS-1$ - assertTrue("array unequal", Arrays.equals(new Object[] {c1, c3, c2, c4}, v1.toArray())); //$NON-NLS-1$ - assertTrue("array unequal", Arrays.equals(new Object[] {c1, c3, c2, c4}, v1.toArray(new Object[4]))); //$NON-NLS-1$ + assertTrue("missed key", v1.containsAll(Arrays.asList(new Object[] { c1, c2, c3, c4 }))); //$NON-NLS-1$ + assertTrue("array unequal", Arrays.equals(new Object[] { c1, c3, c2, c4 }, v1.toArray())); //$NON-NLS-1$ + assertTrue("array unequal", Arrays.equals(new Object[] { c1, c3, c2, c4 }, v1.toArray(new Object[4]))); //$NON-NLS-1$ Iterator i3 = v1.iterator(); assertTrue("missing next", i3.hasNext()); //$NON-NLS-1$ @@ -269,7 +279,7 @@ public class EventManagerTests extends TestCase { i3.next(); fail("next did not throw exception"); //$NON-NLS-1$ } catch (NoSuchElementException e) { - //expected + // expected } assertTrue("not empty", v2.isEmpty()); //$NON-NLS-1$ @@ -281,28 +291,28 @@ public class EventManagerTests extends TestCase { i4.next(); fail("next did not throw exception"); //$NON-NLS-1$ } catch (NoSuchElementException e) { - //expected + // expected } try { v2.add(c1); fail("add did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } try { - v2.addAll(Arrays.asList(new Object[] {c1, c2})); + v2.addAll(Arrays.asList(new Object[] { c1, c2 })); fail("addAll did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } v3.remove(c3); assertFalse("not removed", v3.contains(c3)); //$NON-NLS-1$ - v3.removeAll(Arrays.asList(new Object[] {c1, c2})); + v3.removeAll(Arrays.asList(new Object[] { c1, c2 })); assertFalse("not removed", v3.contains(c1)); //$NON-NLS-1$ assertFalse("not removed", v3.contains(c2)); //$NON-NLS-1$ - v4.retainAll(Arrays.asList(new Object[] {c1, c2})); + v4.retainAll(Arrays.asList(new Object[] { c1, c2 })); assertTrue("missing", v4.contains(c1)); //$NON-NLS-1$ assertTrue("missing", v4.contains(c2)); //$NON-NLS-1$ assertFalse("not removed", v4.contains(c3)); //$NON-NLS-1$ @@ -322,7 +332,7 @@ public class EventManagerTests extends TestCase { me1.setValue(c2); fail("remove did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } i5.remove(); assertEquals("wrong size", 3, e1.size()); //$NON-NLS-1$ @@ -335,7 +345,7 @@ public class EventManagerTests extends TestCase { me3.setValue(c2); fail("remove did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } i5.remove(); assertEquals("wrong size", 2, e1.size()); //$NON-NLS-1$ @@ -348,7 +358,7 @@ public class EventManagerTests extends TestCase { me2.setValue(c3); fail("remove did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } i5.remove(); assertEquals("wrong size", 1, e1.size()); //$NON-NLS-1$ @@ -361,7 +371,7 @@ public class EventManagerTests extends TestCase { me4.setValue(c2); fail("remove did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } i5.remove(); assertEquals("wrong size", 0, e1.size()); //$NON-NLS-1$ @@ -371,7 +381,7 @@ public class EventManagerTests extends TestCase { i1.next(); fail("next did not throw exception"); //$NON-NLS-1$ } catch (NoSuchElementException e) { - //expected + // expected } assertTrue("not empty", e2.isEmpty()); //$NON-NLS-1$ @@ -383,27 +393,27 @@ public class EventManagerTests extends TestCase { i6.next(); fail("next did not throw exception"); //$NON-NLS-1$ } catch (NoSuchElementException e) { - //expected + // expected } try { e2.add(me1); fail("add did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } try { - e2.addAll(Arrays.asList(new Map.Entry[] {me2, me4})); + e2.addAll(Arrays.asList(new Map.Entry[] { me2, me4 })); fail("addAll did not throw exception"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { - //expected + // expected } e3.remove(me3); assertFalse("not removed", e3.contains(me3)); //$NON-NLS-1$ - e3.removeAll(Arrays.asList(new Object[] {me1, me2})); + e3.removeAll(Arrays.asList(new Object[] { me1, me2 })); assertFalse("not removed", e3.contains(me1)); //$NON-NLS-1$ assertFalse("not removed", e3.contains(me2)); //$NON-NLS-1$ - e4.retainAll(Arrays.asList(new Object[] {me1, me2})); + e4.retainAll(Arrays.asList(new Object[] { me1, me2 })); assertTrue("missing", e4.contains(me1)); //$NON-NLS-1$ assertTrue("missing", e4.contains(me2)); //$NON-NLS-1$ assertFalse("not removed", e4.contains(me3)); //$NON-NLS-1$ @@ -411,11 +421,12 @@ public class EventManagerTests extends TestCase { e4.clear(); assertTrue("not empty", e4.isEmpty()); //$NON-NLS-1$ - assertTrue("array unequal", Arrays.equals(new Map.Entry[] {me1, me3, me2, me4}, e5.toArray())); //$NON-NLS-1$ - assertTrue("array unequal", Arrays.equals(new Map.Entry[] {me1, me3, me2, me4}, e5.toArray(new Map.Entry[4]))); //$NON-NLS-1$ + assertTrue("array unequal", Arrays.equals(new Map.Entry[] { me1, me3, me2, me4 }, e5.toArray())); //$NON-NLS-1$ + assertTrue("array unequal", //$NON-NLS-1$ + Arrays.equals(new Map.Entry[] { me1, me3, me2, me4 }, e5.toArray(new Map.Entry[4]))); el2.clear(); - el2.putAll(new Object[] {l1, l3}); + el2.putAll(new Object[] { l1, l3 }); assertFalse("empty", el2.isEmpty()); //$NON-NLS-1$ assertEquals("wrong size", 2, el2.size()); //$NON-NLS-1$ assertTrue("missed key", el2.containsKey(l1)); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/BundleContextFilterTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/BundleContextFilterTests.java index 6c016740e..46a03da03 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/BundleContextFilterTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/BundleContextFilterTests.java @@ -13,16 +13,11 @@ *******************************************************************************/ package org.eclipse.osgi.tests.filter; -import junit.framework.Test; -import junit.framework.TestSuite; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.Filter; import org.osgi.framework.InvalidSyntaxException; public class BundleContextFilterTests extends FilterTests { - public static Test suite() { - return new TestSuite(BundleContextFilterTests.class); - } @Override public Filter createFilter(String filterString) throws InvalidSyntaxException { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java index 0fc2c8b44..f9fbd4097 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FilterTests.java @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.osgi.tests.filter; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; @@ -22,29 +26,22 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.List; import junit.framework.AssertionFailedError; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; import org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap; import org.eclipse.osgi.tests.util.MapDictionary; +import org.junit.Assert; +import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.framework.Filter; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; -public abstract class FilterTests extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(FilterTests.class.getName()); - suite.addTest(BundleContextFilterTests.suite()); - suite.addTest(FrameworkUtilFilterTests.suite()); - return suite; - } +public abstract class FilterTests { /** * Fail with cause t. * * @param message Failure message. - * @param t Cause of the failure. + * @param t Cause of the failure. */ public static void fail(String message, Throwable t) { AssertionFailedError e = new AssertionFailedError(message + ": " + t.getMessage()); @@ -61,7 +58,7 @@ public abstract class FilterTests extends TestCase { private Dictionary getProperties() { Dictionary props = new Hashtable(); props.put("room", "bedroom"); - props.put("channel", new Object[] {Integer.valueOf(34), "101"}); + props.put("channel", new Object[] { Integer.valueOf(34), "101" }); props.put("status", "(on\\)*"); List vec = new ArrayList(10); vec.add(Long.valueOf(150)); @@ -77,14 +74,14 @@ public abstract class FilterTests extends TestCase { props.put("charvalue", Character.valueOf('A')); props.put("booleanvalue", Boolean.TRUE); props.put("weirdvalue", new Hashtable()); - props.put("primintarrayvalue", new int[] {1, 2, 3}); - props.put("primlongarrayvalue", new long[] {1, 2, 3}); - props.put("primbytearrayvalue", new byte[] {(byte) 1, (byte) 2, (byte) 3}); - props.put("primshortarrayvalue", new short[] {(short) 1, (short) 2, (short) 3}); - props.put("primfloatarrayvalue", new float[] {(float) 1.1, (float) 2.2, (float) 3.3}); - props.put("primdoublearrayvalue", new double[] {1.1, 2.2, 3.3}); - props.put("primchararrayvalue", new char[] {'A', 'b', 'C', 'd'}); - props.put("primbooleanarrayvalue", new boolean[] {false}); + props.put("primintarrayvalue", new int[] { 1, 2, 3 }); + props.put("primlongarrayvalue", new long[] { 1, 2, 3 }); + props.put("primbytearrayvalue", new byte[] { (byte) 1, (byte) 2, (byte) 3 }); + props.put("primshortarrayvalue", new short[] { (short) 1, (short) 2, (short) 3 }); + props.put("primfloatarrayvalue", new float[] { (float) 1.1, (float) 2.2, (float) 3.3 }); + props.put("primdoublearrayvalue", new double[] { 1.1, 2.2, 3.3 }); + props.put("primchararrayvalue", new char[] { 'A', 'b', 'C', 'd' }); + props.put("primbooleanarrayvalue", new boolean[] { false }); props.put("bigintvalue", new BigInteger("4123456")); props.put("bigdecvalue", new BigDecimal("4.123456")); props.put("*", "foo"); @@ -99,6 +96,7 @@ public abstract class FilterTests extends TestCase { return props; } + @Test public void testFilter() { Dictionary props = getProperties(); testFilter("(room=*)", props, ISTRUE); @@ -158,6 +156,7 @@ public abstract class FilterTests extends TestCase { testFilter("(space=*)", props, ISTRUE); } + @Test public void testInvalidValues() { Dictionary props = getProperties(); testFilter("(intvalue=*)", props, ISTRUE); @@ -185,6 +184,7 @@ public abstract class FilterTests extends TestCase { testFilter("(booleanvalue=)", props, ISFALSE); } + @Test public void testIllegal() { Dictionary props = getProperties(); testFilter("", props, ISILLEGAL); @@ -199,6 +199,7 @@ public abstract class FilterTests extends TestCase { testFilter(" (room = =b**oo*m*) ) ", props, ISILLEGAL); } + @Test public void testScalarSubstring() { Dictionary props = getProperties(); testFilter("(shortValue =100*) ", props, ISFALSE); @@ -213,6 +214,7 @@ public abstract class FilterTests extends TestCase { testFilter("(booleanValue =t*ue) ", props, ISFALSE); } + @Test public void testNormalization() { try { Filter f1 = createFilter("( a = bedroom )"); @@ -235,7 +237,7 @@ public abstract class FilterTests extends TestCase { f1 = createFilter(query); if (expect == ISILLEGAL) { - fail("expected exception"); + Assert.fail("expected exception"); } } catch (InvalidSyntaxException e) { if (expect != ISILLEGAL) { @@ -269,6 +271,7 @@ public abstract class FilterTests extends TestCase { } + @Test public void testComparable() { Filter f1 = null; Object comp42 = new SampleComparable("42"); @@ -328,6 +331,7 @@ public abstract class FilterTests extends TestCase { assertFalse("does match filter", f1.match(new DictionaryServiceReference(hash))); } + @Test public void testObject() { Filter f1 = null; Object obj42 = new SampleObject("42"); @@ -359,6 +363,7 @@ public abstract class FilterTests extends TestCase { assertFalse("does match filter", f1.match(new DictionaryServiceReference(hash))); } + @Test public void testNullValueMatch() throws InvalidSyntaxException { Dictionary<String, Object> nullProps = new MapDictionary<>(); nullProps.put("test.null", null); @@ -367,6 +372,7 @@ public abstract class FilterTests extends TestCase { assertTrue(createFilter("(&(!(test.null=*))(test.non.null=v1))").match(nullProps)); } + @Test public void testNullKeyMatch() throws InvalidSyntaxException { Dictionary<String, Object> nullProps = new MapDictionary<>(); nullProps.put(null, "null.v1"); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FrameworkUtilFilterTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FrameworkUtilFilterTests.java index ef8818b7b..ec8b0d887 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FrameworkUtilFilterTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/filter/FrameworkUtilFilterTests.java @@ -13,17 +13,15 @@ *******************************************************************************/ package org.eclipse.osgi.tests.filter; -import junit.framework.Test; -import junit.framework.TestSuite; +import static org.junit.Assert.assertTrue; + import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.junit.Test; import org.osgi.framework.Filter; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; public class FrameworkUtilFilterTests extends FilterTests { - public static Test suite() { - return new TestSuite(FrameworkUtilFilterTests.class); - } @Override public Filter createFilter(String filterString) throws InvalidSyntaxException { @@ -32,9 +30,11 @@ public class FrameworkUtilFilterTests extends FilterTests { // Equinox specific test to make sure we continue to use the Equinox FilterImpl // from the FrameworkUtil createFilter method + @Test public void testFrameworkUtilCreateFilter() throws InvalidSyntaxException { Filter bundleContextFilter = OSGiTestsActivator.getContext().createFilter("(simplefilter=true)"); Filter frameworkUtilFilter = FrameworkUtil.createFilter("(simplefilter=true)"); - assertTrue("Wrong Fitler impl type: " + frameworkUtilFilter.getClass().getName(), bundleContextFilter.getClass().equals(frameworkUtilFilter.getClass())); + assertTrue("Wrong Fitler impl type: " + frameworkUtilFilter.getClass().getName(), + bundleContextFilter.getClass().equals(frameworkUtilFilter.getClass())); } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java index 8ca3854ff..74cff3232 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java @@ -15,14 +15,18 @@ package org.eclipse.osgi.tests.listeners; import java.io.IOException; import java.net.MalformedURLException; -import junit.framework.TestCase; import org.eclipse.core.tests.harness.BundleTestingHelper; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.junit.Assert; -import org.osgi.framework.*; +import org.junit.Test; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleException; +import org.osgi.framework.BundleListener; +import org.osgi.framework.FrameworkEvent; +import org.osgi.framework.FrameworkListener; -public class ExceptionHandlerTests extends TestCase { - //These tests exercise the code change for bug 73111. +public class ExceptionHandlerTests { + // These tests exercise the code change for bug 73111. class FrameworkEventListenerWithResult implements FrameworkListener { FrameworkEvent event = null; @@ -53,12 +57,7 @@ public class ExceptionHandlerTests extends TestCase { } } - - protected void setUp() throws Exception { - super.setUp(); - } - - + @Test public void testNonFatalException() { FrameworkEventListenerWithResult fwkListener = new FrameworkEventListenerWithResult(); OSGiTestsActivator.getContext().addFrameworkListener(fwkListener); @@ -71,12 +70,13 @@ public class ExceptionHandlerTests extends TestCase { OSGiTestsActivator.getContext().addBundleListener(npeGenerator); try { - BundleTestingHelper.installBundle(OSGiTestsActivator.getContext(), OSGiTestsActivator.TEST_FILES_ROOT + "internal/plugins/installTests/bundle09"); + BundleTestingHelper.installBundle(OSGiTestsActivator.getContext(), + OSGiTestsActivator.TEST_FILES_ROOT + "internal/plugins/installTests/bundle09"); FrameworkEvent eventReceived = fwkListener.getResult(60000); Assert.assertEquals(FrameworkEvent.ERROR, eventReceived.getType()); Assert.assertEquals(true, eventReceived.getThrowable() instanceof NullPointerException); } catch (MalformedURLException e) { - //Does not happen + // Does not happen } catch (BundleException e) { e.printStackTrace(); } catch (IOException e) { @@ -86,7 +86,7 @@ public class ExceptionHandlerTests extends TestCase { OSGiTestsActivator.getContext().removeBundleListener(npeGenerator); } - + @Test public void testFatalException() { FrameworkEventListenerWithResult fwkListener = new FrameworkEventListenerWithResult(); OSGiTestsActivator.getContext().addFrameworkListener(fwkListener); @@ -98,16 +98,17 @@ public class ExceptionHandlerTests extends TestCase { }; OSGiTestsActivator.getContext().addBundleListener(fatalException); - try { - System.setProperty("eclipse.exitOnError","false"); //Here we set the value to false, because otherwise we would simply exit - BundleTestingHelper.installBundle(OSGiTestsActivator.getContext(), OSGiTestsActivator.TEST_FILES_ROOT + "internal/plugins/installTests/bundle10"); + System.setProperty("eclipse.exitOnError", "false"); // Here we set the value to false, because otherwise we + // would simply exit + BundleTestingHelper.installBundle(OSGiTestsActivator.getContext(), + OSGiTestsActivator.TEST_FILES_ROOT + "internal/plugins/installTests/bundle10"); FrameworkEvent eventReceived = fwkListener.getResult(10000); Assert.assertEquals(FrameworkEvent.ERROR, eventReceived.getType()); Assert.assertEquals(true, eventReceived.getThrowable() instanceof VirtualMachineError); - System.setProperty("eclipse.exitOnError","true"); + System.setProperty("eclipse.exitOnError", "true"); } catch (MalformedURLException e) { - //Does not happen + // Does not happen } catch (BundleException e) { e.printStackTrace(); } catch (IOException e) { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/MiscTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/MiscTests.java index ff50b7b9a..88c8696bd 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/MiscTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/misc/MiscTests.java @@ -13,20 +13,21 @@ *******************************************************************************/ package org.eclipse.osgi.tests.misc; -import junit.framework.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + import org.eclipse.core.runtime.Platform; import org.eclipse.osgi.container.ModuleWiring; import org.eclipse.osgi.internal.loader.BundleLoader; import org.eclipse.osgi.internal.loader.sources.SingleSourcePackage; import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.framework.wiring.BundleWiring; -public class MiscTests extends TestCase { - public static Test suite() { - return new TestSuite(MiscTests.class); - } - +public class MiscTests { + @Test public void testBug251427() { Bundle testsBundle = OSGiTestsActivator.getContext().getBundle(); assertNotNull("tests bundle is null", testsBundle); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/perf/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/perf/AllTests.java index bf83368f8..a85f059d2 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/perf/AllTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/perf/AllTests.java @@ -13,24 +13,11 @@ *******************************************************************************/ package org.eclipse.osgi.tests.perf; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; -public class AllTests extends TestSuite { +@RunWith(Suite.class) +@Suite.SuiteClasses({ StatePerformanceTest.class, StateUsesPerformanceTest.class }) +public class AllTests { public static final String DEGRADATION_RESOLUTION = "Performance decrease caused by additional fuctionality required for ResovlerHooks in OSGi R4.3 specification. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=324753 for details."; - - public AllTests() { - super(); - } - - public AllTests(String name) { - super(name); - } - - public static Test suite() { - TestSuite suite = new TestSuite(AllTests.class.getName()); - suite.addTest(StatePerformanceTest.suite()); - suite.addTest(StateUsesPerformanceTest.suite()); - return suite; - } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/AdminPermissionTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/AdminPermissionTests.java index af101c30f..c32629c2f 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/AdminPermissionTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/AdminPermissionTests.java @@ -16,16 +16,12 @@ package org.eclipse.osgi.tests.permissions; import java.security.Permission; import java.security.PermissionCollection; import java.util.PropertyPermission; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.Test; import org.osgi.framework.AdminPermission; public class AdminPermissionTests extends PermissionTests { - public static Test suite() { - return new TestSuite(AdminPermissionTests.class); - } - + @Test public void testAdminPermission() { AdminPermission p1 = new AdminPermission(); AdminPermission p2 = new AdminPermission("*", "*"); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PackagePermissionTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PackagePermissionTests.java index 0313596d0..81e0ca1a9 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PackagePermissionTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PackagePermissionTests.java @@ -16,16 +16,12 @@ package org.eclipse.osgi.tests.permissions; import java.security.Permission; import java.security.PermissionCollection; import java.util.PropertyPermission; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.Test; import org.osgi.framework.PackagePermission; public class PackagePermissionTests extends PermissionTests { - public static Test suite() { - return new TestSuite(PackagePermissionTests.class); - } - + @Test public void testPackagePermission() { badPackagePermission("a.b.c", "x"); //$NON-NLS-1$ //$NON-NLS-2$ badPackagePermission("a.b.c", " get , x "); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PermissionTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PermissionTests.java index 7205ece97..e85267e27 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PermissionTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/PermissionTests.java @@ -13,23 +13,23 @@ *******************************************************************************/ package org.eclipse.osgi.tests.permissions; -import java.io.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.security.Permission; import java.security.PermissionCollection; import java.util.Enumeration; import java.util.NoSuchElementException; -import junit.framework.*; import org.osgi.framework.PackagePermission; import org.osgi.framework.ServicePermission; -public class PermissionTests extends TestCase { - public static Test suite() { - TestSuite suite = new TestSuite(PermissionTests.class.getName()); - suite.addTest(AdminPermissionTests.suite()); - suite.addTest(ServicePermissionTests.suite()); - suite.addTest(PackagePermissionTests.suite()); - return suite; - } +public class PermissionTests { protected void badServicePermission(String name, String actions) { try { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/ServicePermissionTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/ServicePermissionTests.java index 8b74fd5fc..1c8ef776b 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/ServicePermissionTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/permissions/ServicePermissionTests.java @@ -16,16 +16,11 @@ package org.eclipse.osgi.tests.permissions; import java.security.Permission; import java.security.PermissionCollection; import java.util.PropertyPermission; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.Test; import org.osgi.framework.ServicePermission; public class ServicePermissionTests extends PermissionTests { - - public static Test suite() { - return new TestSuite(ServicePermissionTests.class); - } - + @Test public void testServicePermission() { badServicePermission("a.b.c", "x"); //$NON-NLS-1$ //$NON-NLS-2$ badServicePermission("a.b.c", " get , x "); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/KeyStoreTrustEngineTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/KeyStoreTrustEngineTest.java index 7d37dbe52..0a6036961 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/KeyStoreTrustEngineTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/KeyStoreTrustEngineTest.java @@ -32,7 +32,7 @@ import org.eclipse.osgi.tests.OSGiTestsActivator; public class KeyStoreTrustEngineTest extends TestCase { - private static char[] PASSWORD_DEFAULT = {'c', 'h', 'a', 'n', 'g', 'e', 'i', 't'}; + private static char[] PASSWORD_DEFAULT = { 'c', 'h', 'a', 'n', 'g', 'e', 'i', 't' }; private static String TYPE_DEFAULT = "JKS"; //$NON-NLS-1$ private static TestCase[] s_tests = { @@ -79,11 +79,11 @@ public class KeyStoreTrustEngineTest extends TestCase { public void runTest() { testAddTrustAnchor0(); } - }, /*, new KeyStoreTrustEngineTest("addTrustAnchor positive test: add with autogenerated alias", null) { - public void runTest() { - testAddTrustAnchor1(); - } - }*/ + }, /* + * , new + * KeyStoreTrustEngineTest("addTrustAnchor positive test: add with autogenerated alias" + * , null) { public void runTest() { testAddTrustAnchor1(); } } + */ new KeyStoreTrustEngineTest("addTrustAnchor negative test: null cert specified") { //$NON-NLS-1$ public void runTest() { testAddTrustAnchor2(); @@ -123,7 +123,7 @@ public class KeyStoreTrustEngineTest extends TestCase { testRemoveTrustAnchor5(); } }, - /* getTrustAnchor tests*/ + /* getTrustAnchor tests */ new KeyStoreTrustEngineTest("getTrustAnchor positive test: get by alias", "ca1_root") { //$NON-NLS-1$ //$NON-NLS-2$ public void runTest() { testGetTrustAnchor0(); @@ -142,7 +142,7 @@ public class KeyStoreTrustEngineTest extends TestCase { public void runTest() { testGetAliases0(); } - }}; + } }; public static Test suite() { TestSuite suite = new TestSuite("Unit tests for TrustEngine"); //$NON-NLS-1$ @@ -169,7 +169,7 @@ public class KeyStoreTrustEngineTest extends TestCase { TrustEngine engine; public KeyStoreTrustEngineTest() { - //placeholder + // placeholder } public KeyStoreTrustEngineTest(String name, String... aliases) { @@ -200,16 +200,16 @@ public class KeyStoreTrustEngineTest extends TestCase { } /** - * Closes a stream and ignores any resulting exception. This is useful - * when doing stream cleanup in a finally block where secondary exceptions - * are not worth logging. + * Closes a stream and ignores any resulting exception. This is useful when + * doing stream cleanup in a finally block where secondary exceptions are not + * worth logging. */ protected static void safeClose(OutputStream out) { try { if (out != null) out.close(); } catch (IOException e) { - //ignore + // ignore } } @@ -231,10 +231,10 @@ public class KeyStoreTrustEngineTest extends TestCase { return certs.toArray(new Certificate[] {}); } - //findTrustAnchor positive test: self signed trusted + // findTrustAnchor positive test: self signed trusted public void testFindTrustAnchor0() { try { - Certificate cert = engine.findTrustAnchor(new Certificate[] {getTestCertificate("ca1_root")}); //$NON-NLS-1$ + Certificate cert = engine.findTrustAnchor(new Certificate[] { getTestCertificate("ca1_root") }); //$NON-NLS-1$ assertNotNull("Did not return a cert for self-signed case", cert); //$NON-NLS-1$ assertEquals("Input and output certs not equal for self-signed case", cert, getTestCertificate("ca1_root")); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Throwable t) { @@ -242,7 +242,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //findTrustAnchor positive test: chain with root trusted + // findTrustAnchor positive test: chain with root trusted public void testFindTrustAnchor1() { try { Certificate cert = engine.findTrustAnchor(getTestCertificateChain("ca1_leafb", "ca1_ou", "ca1_root")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -253,7 +253,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //findTrustAnchor positive test: chain with intermediate trusted + // findTrustAnchor positive test: chain with intermediate trusted public void testFindTrustAnchor2() { try { Certificate cert = engine.findTrustAnchor(getTestCertificateChain("ca1_leafb", "ca1_ou", "ca1_root")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -264,7 +264,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //findTrustAnchor positive test: chain with leaf trusted + // findTrustAnchor positive test: chain with leaf trusted public void testFindTrustAnchor3() { try { Certificate cert = engine.findTrustAnchor(getTestCertificateChain("ca1_leafb", "ca1_ou", "ca1_root")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -275,17 +275,17 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //findTrustAnchor negative test: untrusted self signed + // findTrustAnchor negative test: untrusted self signed public void testFindTrustAnchor4() { try { - Certificate cert = engine.findTrustAnchor(new Certificate[] {getTestCertificate("ca2_root")}); //$NON-NLS-1$ + Certificate cert = engine.findTrustAnchor(new Certificate[] { getTestCertificate("ca2_root") }); //$NON-NLS-1$ assertNull("Incorrectly returned a certificate for untrusted self-signed case", cert); //$NON-NLS-1$ } catch (Throwable t) { fail("Unexpected exception testing untrusted self-signed cert: " + t.getMessage()); //$NON-NLS-1$ } } - //findTrustAnchor negative test: untrusted chain + // findTrustAnchor negative test: untrusted chain public void testFindTrustAnchor5() { try { Certificate cert = engine.findTrustAnchor(getTestCertificateChain("ca2_leafb", "ca2_ou", "ca2_root")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -295,7 +295,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //findTrustAnchor negative test: invalid chain + // findTrustAnchor negative test: invalid chain public void testFindTrustAnchor6() { try { Certificate cert = engine.findTrustAnchor(getTestCertificateChain("ca2_leafa", "ca1_root")); //$NON-NLS-1$ //$NON-NLS-2$ @@ -305,7 +305,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //findTrustAnchor negative test: incomplete-able chain + // findTrustAnchor negative test: incomplete-able chain public void testFindTrustAnchor7() { try { Certificate cert = engine.findTrustAnchor(getTestCertificateChain("ca1_leafb", "ca1_root")); //$NON-NLS-1$ //$NON-NLS-2$ @@ -315,7 +315,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //findTrustAnchor negative test: null chain + // findTrustAnchor negative test: null chain public void testFindTrustAnchor8() { try { engine.findTrustAnchor(null); @@ -325,7 +325,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //testAddTrustAnchor positive test: add with alias + // testAddTrustAnchor positive test: add with alias public void testAddTrustAnchor0() { try { String alias = engine.addTrustAnchor(getTestCertificate("ca1_root"), "ca1_root"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -336,7 +336,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //testAddTrustAnchor positive test: add with autogenerated alias + // testAddTrustAnchor positive test: add with autogenerated alias public void testAddTrustAnchor1() { try { String alias = engine.addTrustAnchor(getTestCertificate("ca1_root"), null); //$NON-NLS-1$ @@ -346,7 +346,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //testAddTrustAnchor negative test: null cert specified + // testAddTrustAnchor negative test: null cert specified public void testAddTrustAnchor2() { try { engine.addTrustAnchor(null, "ca1_root"); //$NON-NLS-1$ @@ -356,7 +356,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //testAddTrustAnchor negative test: existing cert specified + // testAddTrustAnchor negative test: existing cert specified public void testAddTrustAnchor3() { try { engine.addTrustAnchor(getTestCertificate("ca1_root"), "new_root"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -368,7 +368,7 @@ public class KeyStoreTrustEngineTest extends TestCase { fail("Expected exception when adding trust anchor"); //$NON-NLS-1$ } - //testAddTrustAnchor negative test: existing alias specified + // testAddTrustAnchor negative test: existing alias specified public void testAddTrustAnchor4() { try { engine.addTrustAnchor(getTestCertificate("ca2_root"), "ca1_root"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -380,7 +380,7 @@ public class KeyStoreTrustEngineTest extends TestCase { fail("Expected exception when adding trust anchor"); //$NON-NLS-1$ } - //removeTrustAnchor positive test: remove by alias + // removeTrustAnchor positive test: remove by alias public void testRemoveTrustAnchor0() { try { engine.removeTrustAnchor("ca1_root"); //$NON-NLS-1$ @@ -389,7 +389,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //removeTrustAnchor positive test: remove by cert + // removeTrustAnchor positive test: remove by cert public void testRemoveTrustAnchor1() { try { engine.removeTrustAnchor(getTestCertificate("ca1_root")); //$NON-NLS-1$ @@ -398,7 +398,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //removeTrustAnchor negative test: cert not found + // removeTrustAnchor negative test: cert not found public void testRemoveTrustAnchor2() { try { engine.removeTrustAnchor(getTestCertificate("ca1_root")); //$NON-NLS-1$ @@ -408,7 +408,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //removeTrustAnchor negative test: by alias not found + // removeTrustAnchor negative test: by alias not found public void testRemoveTrustAnchor3() { try { engine.removeTrustAnchor("ca2_root"); //$NON-NLS-1$ @@ -420,7 +420,7 @@ public class KeyStoreTrustEngineTest extends TestCase { fail("Expected exception when removing trust anchor"); //$NON-NLS-1$ } - //removeTrustAnchor negative test: remove by null alias + // removeTrustAnchor negative test: remove by null alias public void testRemoveTrustAnchor4() { try { engine.removeTrustAnchor((String) null); @@ -430,7 +430,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //removeTrustAnchor negative test: remove by null certificate + // removeTrustAnchor negative test: remove by null certificate public void testRemoveTrustAnchor5() { try { engine.removeTrustAnchor((Certificate) null); @@ -440,7 +440,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //getTrustAnchor positive test: get by alias + // getTrustAnchor positive test: get by alias public void testGetTrustAnchor0() { try { Certificate cert = engine.getTrustAnchor("ca1_root"); //$NON-NLS-1$ @@ -450,7 +450,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //getTrustAnchor negative test: get by null alias + // getTrustAnchor negative test: get by null alias public void testGetTrustAnchor1() { try { engine.getTrustAnchor(null); @@ -460,7 +460,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //getTrustAnchor negative test: does not exist + // getTrustAnchor negative test: does not exist public void testGetTrustAnchor2() { try { Certificate cert = engine.getTrustAnchor("ca2_root"); //$NON-NLS-1$ @@ -471,7 +471,7 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //getAliases positive test: get the alias list + // getAliases positive test: get the alias list public void testGetAliases0() { try { engine.getAliases(); @@ -480,6 +480,6 @@ public class KeyStoreTrustEngineTest extends TestCase { } } - //TODO: thread safety tests - //TODO: performance tests + // TODO: thread safety tests + // TODO: performance tests } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/SecurityTestSuite.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/SecurityTestSuite.java index cec31c667..8bd1f9eb8 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/SecurityTestSuite.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/security/SecurityTestSuite.java @@ -13,14 +13,16 @@ *******************************************************************************/ package org.eclipse.osgi.tests.security; -import junit.framework.*; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; public class SecurityTestSuite extends TestCase { public static Test suite() { TestSuite suite = new TestSuite("Unit tests for Equinox security"); - //trust engine tests + // trust engine tests suite.addTest(KeyStoreTrustEngineTest.suite()); - //signed bundle tests - *uses* trust engine + // signed bundle tests - *uses* trust engine suite.addTest(SignedBundleTest.suite()); suite.addTest(SignedBundleTest.localSuite()); suite.addTest(OSGiAPICertificateTest.suite()); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/AllTests.java index 0ac39c4c9..9aa98b83f 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/AllTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/AllTests.java @@ -13,26 +13,11 @@ *******************************************************************************/ package org.eclipse.osgi.tests.services.datalocation; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; -public class AllTests extends TestSuite { - - public AllTests() { - super(); - } - - public AllTests(String name) { - super(name); - } - - public static Test suite() { - TestSuite suite = new TestSuite(AllTests.class.getName()); - suite.addTest(LocationAreaSessionTest.suite()); - suite.addTest(BasicLocationTests.suite()); - suite.addTest(SimpleTests.suite()); - suite.addTest(FileManagerTests.suite()); - suite.addTest(StreamManagerTests.suite()); - return suite; - } +@RunWith(Suite.class) +@Suite.SuiteClasses({ LocationAreaSessionTest.class, BasicLocationTests.class, SimpleTests.class, + FileManagerTests.class, StreamManagerTests.class }) +public class AllTests { } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/SimpleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/SimpleTests.java index b3b4b85e3..8771627cc 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/SimpleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/SimpleTests.java @@ -13,57 +13,43 @@ *******************************************************************************/ package org.eclipse.osgi.tests.services.datalocation; -import java.io.*; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; +import java.io.File; +import java.io.IOException; import org.eclipse.core.runtime.Platform; import org.eclipse.osgi.storagemanager.StorageManager; +import org.junit.Before; +import org.junit.Test; -public class SimpleTests extends TestCase { +public class SimpleTests { StorageManager manager1; StorageManager manager2; File base; static String TEST1 = "test.txt"; - /** - * Constructs a test case with the given name. - */ - public SimpleTests(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(SimpleTests.class); - } - - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { base = new File(Platform.getConfigurationLocation().getURL().getPath()); manager1 = new StorageManager(base, null); } - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testAddRemove() { try { - manager1.open(true); - assertEquals(null, manager1.lookup(TEST1, false)); - assertEquals(-1, manager1.getId(TEST1)); + manager1.open(true); + assertEquals(null, manager1.lookup(TEST1, false)); + assertEquals(-1, manager1.getId(TEST1)); - manager1.add(TEST1); - assertEquals(new File(base, TEST1 + ".0"), manager1.lookup(TEST1, false)); - assertEquals(0, manager1.getId(TEST1)); + manager1.add(TEST1); + assertEquals(new File(base, TEST1 + ".0"), manager1.lookup(TEST1, false)); + assertEquals(0, manager1.getId(TEST1)); - manager1.remove(TEST1); - assertEquals(null, manager1.lookup(TEST1, false)); - assertEquals(-1, manager1.getId(TEST1)); - } catch(IOException e) { - //No exception can occurs since all the lookup calls are done with false + manager1.remove(TEST1); + assertEquals(null, manager1.lookup(TEST1, false)); + assertEquals(-1, manager1.getId(TEST1)); + } catch (IOException e) { + // No exception can occurs since all the lookup calls are done with false e.printStackTrace(); } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/AllTests.java index 3a286a6c9..501f74c3e 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/AllTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/AllTests.java @@ -13,32 +13,13 @@ *******************************************************************************/ package org.eclipse.osgi.tests.services.resolver; -import junit.framework.*; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; -public class AllTests extends TestCase { - - public AllTests() { - super(null); - } - - public AllTests(String name) { - super(name); - } - - public static Test suite() { - TestSuite suite = new TestSuite(AllTests.class.getName()); - suite.addTest(SubstitutableExportsTest.suite()); - suite.addTest(DisabledInfoTest.suite()); - suite.addTest(PlatformAdminTest.suite()); - suite.addTest(StateResolverTest.suite()); - suite.addTest(StateCycleTest.suite()); - suite.addTest(StateComparisonTest.suite()); - suite.addTest(VersionRangeTests.suite()); - suite.addTest(R4ResolverTest.suite()); - suite.addTest(XFriendsInternalResolverTest.suite()); - suite.addTest(GenericCapabilityTest.suite()); - suite.addTest(OSGiCapabilityTest.suite()); - suite.addTest(DevModeTest.suite()); - return suite; - } +@RunWith(Suite.class) +@Suite.SuiteClasses({ SubstitutableExportsTest.class, DisabledInfoTest.class, PlatformAdminTest.class, + StateResolverTest.class, StateCycleTest.class, StateComparisonTest.class, VersionRangeTests.class, + R4ResolverTest.class, XFriendsInternalResolverTest.class, GenericCapabilityTest.class, OSGiCapabilityTest.class, + DevModeTest.class }) +public class AllTests { } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/R4ResolverTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/R4ResolverTest.java index 97aac139c..3fc63cd1d 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/R4ResolverTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/R4ResolverTest.java @@ -13,52 +13,51 @@ *******************************************************************************/ package org.eclipse.osgi.tests.services.resolver; -import junit.framework.*; -import org.eclipse.osgi.tests.resolver.*; - -public class R4ResolverTest extends TestCase { - - public R4ResolverTest(String testName) { - super(testName); - } - - public static Test suite() { - TestSuite suite = new TestSuite(R4ResolverTest.class.getName()); - suite.addTest(new TestSuite(TestAttributes_001.class)); - suite.addTest(new TestSuite(TestBSN_001.class)); - suite.addTest(new TestSuite(TestCycle_001.class)); - suite.addTest(new TestSuite(TestCycle_002.class)); - suite.addTest(new TestSuite(TestCycle_003.class)); - suite.addTest(new TestSuite(TestCycle_004.class)); - suite.addTest(new TestSuite(TestCycle_005.class)); - suite.addTest(new TestSuite(TestCycle_006.class)); - suite.addTest(new TestSuite(TestDynamic_001.class)); - suite.addTest(new TestSuite(TestDynamic_002.class)); - suite.addTest(new TestSuite(TestDynamic_003.class)); - suite.addTest(new TestSuite(TestDynamic_004.class)); - suite.addTest(new TestSuite(TestDynamic_005.class)); - suite.addTest(new TestSuite(TestDynamic_006.class)); - suite.addTest(new TestSuite(TestGenerated_001.class)); - suite.addTest(new TestSuite(TestGrouping_001.class)); - suite.addTest(new TestSuite(TestGrouping_002.class)); - suite.addTest(new TestSuite(TestGrouping_003.class)); - suite.addTest(new TestSuite(TestGrouping_006.class)); - suite.addTest(new TestSuite(TestGrouping_008.class)); - suite.addTest(new TestSuite(TestOptional_001.class)); - suite.addTest(new TestSuite(TestOptional_002.class)); - suite.addTest(new TestSuite(TestPropagation_001.class)); - suite.addTest(new TestSuite(TestPropagation_003.class)); - suite.addTest(new TestSuite(TestRFC79_001.class)); - suite.addTest(new TestSuite(TestRFC79_002.class)); - suite.addTest(new TestSuite(TestRFC79_003.class)); - suite.addTest(new TestSuite(TestRFC79_004.class)); - suite.addTest(new TestSuite(TestRFC79_005.class)); - suite.addTest(new TestSuite(TestRFC79_006.class)); - suite.addTest(new TestSuite(TestRFC79_007.class)); - suite.addTest(new TestSuite(TestVersion_001.class)); - suite.addTest(new TestSuite(TestVersion_002.class)); - suite.addTest(new TestSuite(TestVersion_003.class)); - return suite; - } +import org.eclipse.osgi.tests.resolver.TestAttributes_001; +import org.eclipse.osgi.tests.resolver.TestBSN_001; +import org.eclipse.osgi.tests.resolver.TestCycle_001; +import org.eclipse.osgi.tests.resolver.TestCycle_002; +import org.eclipse.osgi.tests.resolver.TestCycle_003; +import org.eclipse.osgi.tests.resolver.TestCycle_004; +import org.eclipse.osgi.tests.resolver.TestCycle_005; +import org.eclipse.osgi.tests.resolver.TestCycle_006; +import org.eclipse.osgi.tests.resolver.TestDynamic_001; +import org.eclipse.osgi.tests.resolver.TestDynamic_002; +import org.eclipse.osgi.tests.resolver.TestDynamic_003; +import org.eclipse.osgi.tests.resolver.TestDynamic_004; +import org.eclipse.osgi.tests.resolver.TestDynamic_005; +import org.eclipse.osgi.tests.resolver.TestDynamic_006; +import org.eclipse.osgi.tests.resolver.TestGenerated_001; +import org.eclipse.osgi.tests.resolver.TestGrouping_001; +import org.eclipse.osgi.tests.resolver.TestGrouping_002; +import org.eclipse.osgi.tests.resolver.TestGrouping_003; +import org.eclipse.osgi.tests.resolver.TestGrouping_006; +import org.eclipse.osgi.tests.resolver.TestGrouping_008; +import org.eclipse.osgi.tests.resolver.TestOptional_001; +import org.eclipse.osgi.tests.resolver.TestOptional_002; +import org.eclipse.osgi.tests.resolver.TestPropagation_001; +import org.eclipse.osgi.tests.resolver.TestPropagation_003; +import org.eclipse.osgi.tests.resolver.TestRFC79_001; +import org.eclipse.osgi.tests.resolver.TestRFC79_002; +import org.eclipse.osgi.tests.resolver.TestRFC79_003; +import org.eclipse.osgi.tests.resolver.TestRFC79_004; +import org.eclipse.osgi.tests.resolver.TestRFC79_005; +import org.eclipse.osgi.tests.resolver.TestRFC79_006; +import org.eclipse.osgi.tests.resolver.TestRFC79_007; +import org.eclipse.osgi.tests.resolver.TestVersion_001; +import org.eclipse.osgi.tests.resolver.TestVersion_002; +import org.eclipse.osgi.tests.resolver.TestVersion_003; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +@RunWith(Suite.class) +@Suite.SuiteClasses({ TestAttributes_001.class, TestBSN_001.class, TestCycle_001.class, TestCycle_002.class, + TestCycle_003.class, TestCycle_004.class, TestCycle_005.class, TestCycle_006.class, TestDynamic_001.class, + TestDynamic_002.class, TestDynamic_003.class, TestDynamic_004.class, TestDynamic_005.class, + TestDynamic_006.class, TestGenerated_001.class, TestGrouping_001.class, TestGrouping_002.class, + TestGrouping_003.class, TestGrouping_006.class, TestGrouping_008.class, TestOptional_001.class, + TestOptional_002.class, TestPropagation_001.class, TestPropagation_003.class, TestRFC79_001.class, + TestRFC79_002.class, TestRFC79_003.class, TestRFC79_004.class, TestRFC79_005.class, TestRFC79_006.class, + TestRFC79_007.class, TestVersion_001.class, TestVersion_002.class, TestVersion_003.class }) +public class R4ResolverTest { } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/VersionRangeTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/VersionRangeTests.java index 501e6b51a..88e6b00d3 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/VersionRangeTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/VersionRangeTests.java @@ -13,11 +13,17 @@ *******************************************************************************/ package org.eclipse.osgi.tests.services.resolver; -import junit.framework.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import org.eclipse.osgi.service.resolver.VersionRange; +import org.junit.Test; import org.osgi.framework.Version; -public class VersionRangeTests extends TestCase { +public class VersionRangeTests { + @Test public void testSingleVersionRange() { VersionRange range; range = new VersionRange("[1.0.0, 1.0.0.-)"); //$NON-NLS-1$ @@ -32,6 +38,7 @@ public class VersionRangeTests extends TestCase { assertTrue("2.4", !range.isIncluded(Version.parseVersion("2"))); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testInvertedRange() { VersionRange range; range = new VersionRange("[2.0.0, 1.0.0]"); //$NON-NLS-1$ @@ -42,6 +49,7 @@ public class VersionRangeTests extends TestCase { assertTrue("1.4", !range.isIncluded(Version.parseVersion("0.5"))); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testGreaterThan() { // any version equal or greater than 1.0 is ok VersionRange lowerBound = new VersionRange("1.0.0"); //$NON-NLS-1$ @@ -51,6 +59,7 @@ public class VersionRangeTests extends TestCase { assertTrue("1.3", lowerBound.isIncluded(Version.parseVersion("999.999.999.foo"))); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testLowerThan() { // any version lower than 2.0 is ok VersionRange upperBound = new VersionRange("[0,2.0)"); //$NON-NLS-1$ @@ -62,6 +71,7 @@ public class VersionRangeTests extends TestCase { assertTrue("1.5", !upperBound.isIncluded(Version.parseVersion("2.1"))); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testNullMin() { VersionRange nullMin = new VersionRange(null, true, new Version("1.0"), false); //$NON-NLS-1$ assertNotNull("0.1", nullMin.getMinimum()); //$NON-NLS-1$ @@ -74,6 +84,7 @@ public class VersionRangeTests extends TestCase { assertFalse("1.5", nullMin.isIncluded(Version.parseVersion("2.1"))); //$NON-NLS-1$ //$NON-NLS-2$ } + @Test public void testNullMax() { VersionRange nullMaxAny = new VersionRange(new Version("0"), true, null, true); //$NON-NLS-1$ assertTrue("1.0", nullMaxAny.isIncluded(Version.parseVersion("0.0"))); //$NON-NLS-1$ //$NON-NLS-2$ @@ -84,7 +95,4 @@ public class VersionRangeTests extends TestCase { assertTrue("1.5", nullMaxAny.isIncluded(new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE))); //$NON-NLS-1$ } - public static Test suite() { - return new TestSuite(VersionRangeTests.class); - } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java index d86b15c06..beaa87133 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/AllTests.java @@ -14,6 +14,7 @@ package org.eclipse.osgi.tests.util; +import junit.framework.JUnit4TestAdapter; import junit.framework.Test; import junit.framework.TestSuite; @@ -27,7 +28,7 @@ public class AllTests extends TestSuite { public AllTests() { addTest(new TestSuite(TestCaseinsensitiveMap.class)); addTest(new TestSuite(ObjectPoolTestCase.class)); - addTest(new TestSuite(ManifestElementTestCase.class)); + addTest(new JUnit4TestAdapter(ManifestElementTestCase.class)); addTest(new TestSuite(NLSTestCase.class)); addBidiTests(); addLatinTests(); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/ManifestElementTestCase.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/ManifestElementTestCase.java index 35ac26321..30cf01d4d 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/ManifestElementTestCase.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/util/ManifestElementTestCase.java @@ -14,22 +14,27 @@ package org.eclipse.osgi.tests.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.Map; -import junit.framework.TestCase; import org.eclipse.osgi.util.ManifestElement; import org.junit.Assert; +import org.junit.Test; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; -public class ManifestElementTestCase extends TestCase { +public class ManifestElementTestCase { + @Test public void testSpacesInValues() throws BundleException { - ManifestElement[] elements = ManifestElement.parseHeader("test-spaces", "\"comp 1\";\"comp 2\";\"comp 3\";attr=\"val 1\";dir:=\"val 2\""); + ManifestElement[] elements = ManifestElement.parseHeader("test-spaces", + "\"comp 1\";\"comp 2\";\"comp 3\";attr=\"val 1\";dir:=\"val 2\""); assertNotNull("1.0", elements); assertEquals("1.1", elements.length, 1); String[] components = elements[0].getValueComponents(); @@ -43,8 +48,10 @@ public class ManifestElementTestCase extends TestCase { assertEquals("3.1", elements[0].getDirective("dir"), "val 2"); } + @Test public void testBug238675_01() throws BundleException { - ManifestElement[] elements = ManifestElement.parseHeader("Bundle-NativeCode", "\"external:C:/tmp/x.dll\";\"external:C:/tmp/y.dll\"; osname =WindowsXP; osverison = 2.0; processor = x86"); //$NON-NLS-1$//$NON-NLS-2$ + ManifestElement[] elements = ManifestElement.parseHeader("Bundle-NativeCode", //$NON-NLS-1$ + "\"external:C:/tmp/x.dll\";\"external:C:/tmp/y.dll\"; osname =WindowsXP; osverison = 2.0; processor = x86"); //$NON-NLS-1$ assertNotNull("1.0", elements); assertEquals("1.1", 1, elements.length); String[] components = elements[0].getValueComponents(); @@ -54,8 +61,10 @@ public class ManifestElementTestCase extends TestCase { assertEquals("2.1", "external:C:/tmp/y.dll", components[1]); } + @Test public void testBug238675_02() throws BundleException { - ManifestElement[] elements = ManifestElement.parseHeader("Bundle-NativeCode", "\"external:test1:test2\";\"test3:test4:\"; osname =WindowsXP; osverison = 2.0; processor = x86"); //$NON-NLS-1$ //$NON-NLS-2$ + ManifestElement[] elements = ManifestElement.parseHeader("Bundle-NativeCode", //$NON-NLS-1$ + "\"external:test1:test2\";\"test3:test4:\"; osname =WindowsXP; osverison = 2.0; processor = x86"); //$NON-NLS-1$ assertNotNull("1.0", elements); assertEquals("1.1", 1, elements.length); String[] components = elements[0].getValueComponents(); @@ -75,14 +84,17 @@ public class ManifestElementTestCase extends TestCase { "" // ); + @Test public void testManifestWithCR() throws IOException, BundleException { doManifestTest("\r"); } + @Test public void testManifestWithLF() throws IOException, BundleException { doManifestTest("\n"); } + @Test public void testManifestWithCRLF() throws IOException, BundleException { doManifestTest("\r\n"); } @@ -93,11 +105,13 @@ public class ManifestElementTestCase extends TestCase { Assert.assertEquals("Wrong Import-Package.", "test1,test2,test3", manifest.get(Constants.IMPORT_PACKAGE)); } - private Map<String, String> getManifest(List<String> manifestLines, String newLine) throws IOException, BundleException { + private Map<String, String> getManifest(List<String> manifestLines, String newLine) + throws IOException, BundleException { StringBuilder manifestText = new StringBuilder(); for (String line : manifestLines) { manifestText.append(line).append(newLine); } - return ManifestElement.parseBundleManifest(new ByteArrayInputStream(manifestText.toString().getBytes(StandardCharsets.UTF_8)), null); + return ManifestElement.parseBundleManifest( + new ByteArrayInputStream(manifestText.toString().getBytes(StandardCharsets.UTF_8)), null); } } |