From 6e1886bc953dd7a3fbfeedbc275fbaa1c827ab9b Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 25 Jan 2013 17:25:57 -0500 Subject: [PATCH] tmf: Update tmf.core unit tests to JUnit4 Refs bug 393449. Also added missing dispose() calls in TmfExperimentCheckpointIndexTest. Not doing those would fail subsequent tests in TmfTraceTest (not sure why this wasn't needed with JUnit3). Change-Id: Id6bb29067fadf1bee6b30955520ce376b1ac01aa Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/10117 Tested-by: Hudson CI Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse --- .../tmf/core/tests/AllTmfCoreTests.java | 39 +- .../tmf/core/tests/TmfCorePluginTest.java | 77 +- .../tmf/core/tests/component/AllTests.java | 38 +- .../tests/component/TmfEventProviderTest.java | 76 +- .../component/TmfProviderManagerTest.java | 615 ++++++++-------- .../{TestAll.java => AllTests.java} | 14 +- .../tests/ctfadaptor/CtfIteratorTest.java | 10 - .../tests/ctfadaptor/CtfLocationDataTest.java | 20 - .../tests/ctfadaptor/CtfLocationTest.java | 20 - .../ctfadaptor/CtfTmfEventFieldTest.java | 19 - .../tests/ctfadaptor/CtfTmfEventTest.java | 19 - .../tests/ctfadaptor/CtfTmfEventTypeTest.java | 45 +- .../tests/ctfadaptor/CtfTmfTimestampTest.java | 11 +- .../tests/ctfadaptor/CtfTmfTraceTest.java | 10 - .../tmf/core/tests/event/AllTests.java | 39 +- .../core/tests/event/TmfEventFieldTest.java | 112 +-- .../tmf/core/tests/event/TmfEventTest.java | 118 +-- .../tests/event/TmfEventTypeManagerTest.java | 68 +- .../core/tests/event/TmfEventTypeTest.java | 95 +-- .../tests/event/TmfSimpleTimestampTest.java | 104 +-- .../core/tests/event/TmfTimeRangeTest.java | 110 +-- .../tests/event/TmfTimestampDeltaTest.java | 92 +-- .../core/tests/event/TmfTimestampTest.java | 390 ++++------ .../tmf/core/tests/request/AllTests.java | 48 +- .../request/TmfCoalescedDataRequestTest.java | 483 +++++++------ .../request/TmfCoalescedEventRequestTest.java | 678 +++++++++--------- .../tests/request/TmfDataRequestTest.java | 321 +++++---- .../tests/request/TmfEventRequestTest.java | 341 +++++---- .../tests/request/TmfRequestExecutorTest.java | 175 +++-- .../tmf/core/tests/statesystem/AllTests.java | 23 +- .../statesystem/StateSystemPushPopTest.java | 28 +- .../tmf/core/tests/trace/AllTests.java | 42 +- .../tests/trace/TmfCheckpointIndexTest.java | 32 +- .../tests/trace/TmfCheckpointIndexTest2.java | 32 +- .../core/tests/trace/TmfCheckpointTest.java | 69 +- .../tmf/core/tests/trace/TmfContextTest.java | 73 +- .../TmfExperimentCheckpointIndexTest.java | 90 +-- .../core/tests/trace/TmfExperimentTest.java | 99 +-- .../tmf/core/tests/trace/TmfLocationTest.java | 73 +- .../trace/TmfMultiTraceExperimentTest.java | 96 ++- .../tmf/core/tests/trace/TmfTraceTest.java | 156 ++-- .../tmf/core/tests/uml2sd/AllTests.java | 41 +- .../TmfAsyncSequenceDiagramEventTest.java | 35 +- .../TmfSyncSequenceDiagramEventTest.java | 36 +- .../tmf/core/tests/util/AllTests.java | 37 +- .../tmf/core/tests/util/PairTest.java | 32 +- 46 files changed, 2330 insertions(+), 2851 deletions(-) rename org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/{TestAll.java => AllTests.java} (79%) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java index 7ba0ecd4fb..914421cc7c 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/AllTmfCoreTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,35 +8,30 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4, enable CTF and statistics tests *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** - * AllTmfCoreTests - *

* Master test suite for TMF Core. */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TmfCorePluginTest.class, + org.eclipse.linuxtools.tmf.core.tests.component.AllTests.class, + //org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.AllTests.class, + org.eclipse.linuxtools.tmf.core.tests.event.AllTests.class, + org.eclipse.linuxtools.tmf.core.tests.request.AllTests.class, + org.eclipse.linuxtools.tmf.core.tests.statesystem.AllTests.class, + //org.eclipse.linuxtools.tmf.core.tests.statistics.AllTests.class, + org.eclipse.linuxtools.tmf.core.tests.trace.AllTests.class, + org.eclipse.linuxtools.tmf.core.tests.uml2sd.AllTests.class, + org.eclipse.linuxtools.tmf.core.tests.util.AllTests.class +}) public class AllTmfCoreTests { - /** - * @return the TMF Core test suite - */ - public static Test suite() { - TestSuite suite = new TestSuite(AllTmfCoreTests.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(TmfCorePluginTest.class); - suite.addTest(org.eclipse.linuxtools.tmf.core.tests.event.AllTests.suite()); - suite.addTest(org.eclipse.linuxtools.tmf.core.tests.request.AllTests.suite()); - suite.addTest(org.eclipse.linuxtools.tmf.core.tests.component.AllTests.suite()); - suite.addTest(org.eclipse.linuxtools.tmf.core.tests.statesystem.AllTests.suite()); - suite.addTest(org.eclipse.linuxtools.tmf.core.tests.trace.AllTests.suite()); - suite.addTest(org.eclipse.linuxtools.tmf.core.tests.uml2sd.AllTests.suite()); - suite.addTest(org.eclipse.linuxtools.tmf.core.tests.util.AllTests.suite()); - //$JUnit-END$ - return suite; - } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/TmfCorePluginTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/TmfCorePluginTest.java index 180c913294..87c0af5d9f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/TmfCorePluginTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/TmfCorePluginTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,67 +8,48 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.junit.Test; /** - * TmfCorePluginTest - *

* Test the TMF core plug-in activator */ -@SuppressWarnings({ "nls" }) -public class TmfCorePluginTest extends TestCase { +@SuppressWarnings("nls") +public class TmfCorePluginTest { - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ // Attributes - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ - // Plug-in instantiation - static final Activator fPlugin = new Activator(); + // Plug-in instantiation + static final Activator fPlugin = new Activator(); - // ------------------------------------------------------------------------ - // Housekeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfCorePluginTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ // Test cases - // ------------------------------------------------------------------------ - - /** - * - */ - public void testTmfCorePluginId() { - assertEquals("Plugin ID", "org.eclipse.linuxtools.tmf.core", Activator.PLUGIN_ID); - } - - /** - * - */ - public void testGetDefault() { - Activator plugin = Activator.getDefault(); - assertEquals("getDefault()", plugin, fPlugin); - } + // ------------------------------------------------------------------------ + + /** + * Test the plugin ID. + */ + @Test + public void testTmfCorePluginId() { + assertEquals("Plugin ID", "org.eclipse.linuxtools.tmf.core", Activator.PLUGIN_ID); + } + + /** + * Test the getDefault() static method. + */ + @Test + public void testGetDefault() { + Activator plugin = Activator.getDefault(); + assertEquals("getDefault()", plugin, fPlugin); + } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/AllTests.java index 40eea64bc1..d8b309f66b 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/AllTests.java @@ -1,26 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + *******************************************************************************/ + package org.eclipse.linuxtools.tmf.core.tests.component; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** - * AllTests - *

- * Implement me. Please. - *

+ * Unit tests for the component package. */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TmfEventProviderTest.class, + TmfProviderManagerTest.class +}) public class AllTests { - /** - * @return the TMF Core Component test suite - */ - public static Test suite() { - TestSuite suite = new TestSuite(AllTests.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(TmfProviderManagerTest.class); - suite.addTestSuite(TmfEventProviderTest.class); - //$JUnit-END$ - return suite; - } - } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfEventProviderTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfEventProviderTest.java index 0e2d067d6d..274882b1d3 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfEventProviderTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfEventProviderTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,13 +8,15 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.component; -import java.util.Vector; +import static org.junit.Assert.*; -import junit.framework.TestCase; +import java.io.IOException; +import java.util.Vector; import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager; import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; @@ -28,35 +30,37 @@ import org.eclipse.linuxtools.tmf.tests.stubs.component.TmfEventProviderStub; import org.eclipse.linuxtools.tmf.tests.stubs.component.TmfSyntheticEventProviderStub; import org.eclipse.linuxtools.tmf.tests.stubs.event.TmfSyntheticEventStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** - * TmfClientTest - *

* Test suite for the TmfEventProvider class. */ -@SuppressWarnings({ "nls" }) -public class TmfEventProviderTest extends TestCase { +@SuppressWarnings("nls") +public class TmfEventProviderTest { - TmfEventProviderStub fEventProvider; - TmfSyntheticEventProviderStub fSyntheticEventProvider; + private TmfEventProviderStub fEventProvider; + private TmfSyntheticEventProviderStub fSyntheticEventProvider; /** - * @param name the test anme + * Initialization + * + * @throws IOException + * If we can't find the test trace (they are committed in the + * tree, so it shouldn't happen). */ - public TmfEventProviderTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws IOException { fEventProvider = new TmfEventProviderStub(); fSyntheticEventProvider = new TmfSyntheticEventProviderStub(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + /** + * Clean-up + */ + @After + public void tearDown() { fEventProvider.dispose(); fSyntheticEventProvider.dispose(); } @@ -66,10 +70,10 @@ public class TmfEventProviderTest extends TestCase { // ------------------------------------------------------------------------ /** - * + * Test getProviders */ + @Test public void testGetProviders() { - // There should be 2 TmfEvent providers: a TmfTraceStub and a // TmfEventProviderStub ITmfDataProvider[] eventProviders = TmfProviderManager.getProviders(ITmfEvent.class); @@ -91,10 +95,10 @@ public class TmfEventProviderTest extends TestCase { // ------------------------------------------------------------------------ /** - * + * Test getPlainEvents */ + @Test public void testGetPlainEvents() { - final int BLOCK_SIZE = 100; final int NB_EVENTS = 1000; final Vector requestedEvents = new Vector(); @@ -131,8 +135,9 @@ public class TmfEventProviderTest extends TestCase { } /** - * + * Test canceling requests. */ + @Test public void testCancelRequests() { final int BLOCK_SIZE = 100; @@ -278,10 +283,9 @@ public class TmfEventProviderTest extends TestCase { } /** - * + * Test getSyntheticEvents for equal block sizes. */ - // The following tests are the same but for the size of the requested blocks - // with regards to the size of the TmfSyntheticEventProviderStub block + @Test public void testGetSyntheticEvents_EqualBlockSizes() { TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); try { @@ -292,8 +296,9 @@ public class TmfEventProviderTest extends TestCase { } /** - * + * Test getSyntheticEvents for smaller block sizes. */ + @Test public void testGetSyntheticEvents_SmallerBlock() { TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); try { @@ -304,8 +309,9 @@ public class TmfEventProviderTest extends TestCase { } /** - * + * Test getSyntheticEvents for larger block sizes. */ + @Test public void testGetSyntheticEvents_LargerBlock() { TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); try { @@ -316,8 +322,9 @@ public class TmfEventProviderTest extends TestCase { } /** - * + * Test getSyntheticEvents */ + @Test public void testGetSyntheticEvents_TimeRange() { TmfTimestamp start = new TmfTimestamp(1, (byte) -3, 0); TmfTimestamp end = new TmfTimestamp(1000, (byte) -3, 0); @@ -353,13 +360,10 @@ public class TmfEventProviderTest extends TestCase { // } // } - // ------------------------------------------------------------------------ - // getProviders (more a sanity check than a test) - // ------------------------------------------------------------------------ - /** - * + * Test getProviders (more a sanity check than a test) */ + @Test public void testGetProviders2() { // There should be 2 TmfEvent providers: a TmfTraceStub and a diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfProviderManagerTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfProviderManagerTest.java index 998d26feef..63b73e20eb 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfProviderManagerTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/component/TmfProviderManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,11 +8,13 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.component; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager; import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider; @@ -21,317 +23,314 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.junit.Test; + /** - * TmfProviderManagerTest - *

* Test suite for the TmfProviderManager class. */ -@SuppressWarnings({ "nls" }) -public class TmfProviderManagerTest extends TestCase { - - /** - * @param name the test anme - */ - public TmfProviderManagerTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - // ------------------------------------------------------------------------ - // Dummy Providers - // ------------------------------------------------------------------------ - - private class TestProvider1 extends TmfDataProvider { - public TestProvider1(Class type) { - super("TestProvider1", type); - } - @Override - public ITmfContext armRequest(ITmfDataRequest request) { - return null; - } - @Override - public ITmfEvent getNext(ITmfContext context) { - return null; - } - @Override - public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) { - return false; - } - } - - private class TestProvider2 extends TmfDataProvider { - public TestProvider2(Class type) { - super("TestProvider2", type); - } - @Override - public ITmfContext armRequest(ITmfDataRequest request) { - return null; - } - @Override - public ITmfEvent getNext(ITmfContext context) { - return null; - } - @Override - public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) { - return false; - } - } - - private class TmfEvent3 extends TmfEvent { - @SuppressWarnings("unused") +@SuppressWarnings("nls") +public class TmfProviderManagerTest { + + // ------------------------------------------------------------------------ + // Dummy Providers + // ------------------------------------------------------------------------ + + private class TestProvider1 extends TmfDataProvider { + public TestProvider1(Class type) { + super("TestProvider1", type); + } + + @Override + public ITmfContext armRequest(ITmfDataRequest request) { + return null; + } + + @Override + public ITmfEvent getNext(ITmfContext context) { + return null; + } + + @Override + public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) { + return false; + } + } + + private class TestProvider2 extends TmfDataProvider { + public TestProvider2(Class type) { + super("TestProvider2", type); + } + + @Override + public ITmfContext armRequest(ITmfDataRequest request) { + return null; + } + + @Override + public ITmfEvent getNext(ITmfContext context) { + return null; + } + + @Override + public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) { + return false; + } + } + + private class TmfEvent3 extends TmfEvent { + @SuppressWarnings("unused") public TmfEvent3(TmfEvent3 other) { - super(other); - } - } - - private class TestProvider3 extends TmfDataProvider { - public TestProvider3(Class type) { - super("TestProvider3", type); - } - @Override - public ITmfContext armRequest(ITmfDataRequest request) { - return null; - } - @Override - public TmfEvent3 getNext(ITmfContext context) { - return null; - } - @Override - public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) { - return false; - } - } - - // ------------------------------------------------------------------------ - // register/dispose - // ------------------------------------------------------------------------ - - /** - * - */ - public void testRegister_0() { - TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 0, providers.length); - } - - /** - * - */ - public void testRegister_Unregister_1() { - - // Register a single provider - TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); - - TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider1, providers[0]); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider1, providers[0]); - - // Unregister it - testProvider1.dispose(); - - providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 0, providers.length); - } - - /** - * - */ - public void testRegister_Unregister_2() { - - // Register 2 providers, same data type - TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); - TestProvider2 testProvider2 = new TestProvider2(ITmfEvent.class); - - TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 2, providers.length); - assertTrue(providers.length == 2); - if (providers[0] == testProvider1) { - assertEquals("getProviders", testProvider2, providers[1]); - } - else { - assertEquals("getProviders", testProvider2, providers[0]); - assertEquals("getProviders", testProvider1, providers[1]); - } - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider1, providers[0]); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider2, providers[0]); - - // Remove one - testProvider1.dispose(); - - providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider2, providers[0]); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider2, providers[0]); - - // Remove the other - testProvider2.dispose(); - - providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); - assertEquals("getProviders", 0, providers.length); - } - - /** - * - */ - public void testRegister_Unregister_3() { - - // Register 3 providers, mixed data types - TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); - TestProvider2 testProvider2 = new TestProvider2(ITmfEvent.class); - TestProvider3 testProvider3 = new TestProvider3(TmfEvent3.class); - - TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 2, providers.length); - if (providers[0] == testProvider1) { - assertEquals("getProviders", testProvider2, providers[1]); - } - else { - assertEquals("getProviders", testProvider2, providers[0]); - assertEquals("getProviders", testProvider1, providers[1]); - } - - TmfDataProvider[] providers3 = TmfProviderManager.getProviders(TmfEvent3.class); - assertEquals("getProviders", 1, providers3.length); - assertEquals("getProviders", testProvider3, providers3[0]); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider1, providers[0]); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider2, providers[0]); - - providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); - assertEquals("getProviders", 1, providers3.length); - assertEquals("getProviders", testProvider3, providers3[0]); - - // Remove one - testProvider1.dispose(); - - providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider2, providers[0]); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider2, providers[0]); - - providers3 = TmfProviderManager.getProviders(TmfEvent3.class); - assertEquals("getProviders", 1, providers3.length); - assertEquals("getProviders", testProvider3, providers3[0]); - - providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); - assertEquals("getProviders", 1, providers3.length); - assertEquals("getProviders", testProvider3, providers3[0]); - - // Remove another one - testProvider2.dispose(); - - providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); - assertEquals("getProviders", 0, providers.length); - - providers3 = TmfProviderManager.getProviders(TmfEvent3.class); - assertTrue(providers3.length == 1); - assertTrue(providers3[0] == testProvider3); - - providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); - assertEquals("getProviders", 1, providers3.length); - assertEquals("getProviders", testProvider3, providers3[0]); - - // Remove the last one - testProvider3.dispose(); - - providers = TmfProviderManager.getProviders(ITmfEvent.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); - assertEquals("getProviders", 0, providers.length); - - providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); - assertEquals("getProviders", 0, providers.length); - - providers3 = TmfProviderManager.getProviders(TmfEvent3.class); - assertEquals("getProviders", 0, providers.length); - - providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); - assertEquals("getProviders", 0, providers.length); - } - - /** - * - */ - public void testGetProvider() { - - // Register 3 providers, mixed data types - TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); - TestProvider2 testProvider2 = new TestProvider2(ITmfEvent.class); - TestProvider3 testProvider3 = new TestProvider3(TmfEvent3.class); - - TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, null); - assertEquals("getProviders", 2, providers.length); - if (providers[0] == testProvider1) { - assertEquals("getProviders", testProvider2, providers[1]); - } - else { - assertEquals("getProviders", testProvider2, providers[0]); - assertEquals("getProviders", testProvider1, providers[1]); - } + super(other); + } + } + + private class TestProvider3 extends TmfDataProvider { + public TestProvider3(Class type) { + super("TestProvider3", type); + } + + @Override + public ITmfContext armRequest(ITmfDataRequest request) { + return null; + } + + @Override + public TmfEvent3 getNext(ITmfContext context) { + return null; + } + + @Override + public boolean isCompleted(ITmfDataRequest request, ITmfEvent data, int nbRead) { + return false; + } + } + + // ------------------------------------------------------------------------ + // register/dispose + // ------------------------------------------------------------------------ + + /** + * Test registering + */ + @Test + public void testRegister_0() { + TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 0, providers.length); + } + + /** + * Test unregistering + */ + @Test + public void testRegister_Unregister_1() { + + // Register a single provider + TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); + + TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider1, providers[0]); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider1, providers[0]); + + // Unregister it + testProvider1.dispose(); + + providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 0, providers.length); + } + + /** + * Test unregistering + */ + @Test + public void testRegister_Unregister_2() { + + // Register 2 providers, same data type + TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); + TestProvider2 testProvider2 = new TestProvider2(ITmfEvent.class); + + TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 2, providers.length); + assertTrue(providers.length == 2); + if (providers[0] == testProvider1) { + assertEquals("getProviders", testProvider2, providers[1]); + } + else { + assertEquals("getProviders", testProvider2, providers[0]); + assertEquals("getProviders", testProvider1, providers[1]); + } + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider1, providers[0]); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider2, providers[0]); + + // Remove one + testProvider1.dispose(); + + providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider2, providers[0]); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider2, providers[0]); + + // Remove the other + testProvider2.dispose(); + + providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); + assertEquals("getProviders", 0, providers.length); + } + + /** + * Test unregistering + */ + @Test + public void testRegister_Unregister_3() { + + // Register 3 providers, mixed data types + TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); + TestProvider2 testProvider2 = new TestProvider2(ITmfEvent.class); + TestProvider3 testProvider3 = new TestProvider3(TmfEvent3.class); + + TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 2, providers.length); + if (providers[0] == testProvider1) { + assertEquals("getProviders", testProvider2, providers[1]); + } + else { + assertEquals("getProviders", testProvider2, providers[0]); + assertEquals("getProviders", testProvider1, providers[1]); + } + + TmfDataProvider[] providers3 = TmfProviderManager.getProviders(TmfEvent3.class); + assertEquals("getProviders", 1, providers3.length); + assertEquals("getProviders", testProvider3, providers3[0]); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider1, providers[0]); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider2, providers[0]); + + providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); + assertEquals("getProviders", 1, providers3.length); + assertEquals("getProviders", testProvider3, providers3[0]); + + // Remove one + testProvider1.dispose(); + + providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider2, providers[0]); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider2, providers[0]); + + providers3 = TmfProviderManager.getProviders(TmfEvent3.class); + assertEquals("getProviders", 1, providers3.length); + assertEquals("getProviders", testProvider3, providers3[0]); + + providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); + assertEquals("getProviders", 1, providers3.length); + assertEquals("getProviders", testProvider3, providers3[0]); + + // Remove another one + testProvider2.dispose(); + + providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); + assertEquals("getProviders", 0, providers.length); + + providers3 = TmfProviderManager.getProviders(TmfEvent3.class); + assertTrue(providers3.length == 1); + assertTrue(providers3[0] == testProvider3); + + providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); + assertEquals("getProviders", 1, providers3.length); + assertEquals("getProviders", testProvider3, providers3[0]); + + // Remove the last one + testProvider3.dispose(); + + providers = TmfProviderManager.getProviders(ITmfEvent.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider1.class); + assertEquals("getProviders", 0, providers.length); + + providers = TmfProviderManager.getProviders(ITmfEvent.class, TestProvider2.class); + assertEquals("getProviders", 0, providers.length); + + providers3 = TmfProviderManager.getProviders(TmfEvent3.class); + assertEquals("getProviders", 0, providers.length); + + providers3 = TmfProviderManager.getProviders(TmfEvent3.class, TestProvider3.class); + assertEquals("getProviders", 0, providers.length); + } + + /** + * Test getProviders method + */ + @Test + public void testGetProvider() { + + // Register 3 providers, mixed data types + TestProvider1 testProvider1 = new TestProvider1(ITmfEvent.class); + TestProvider2 testProvider2 = new TestProvider2(ITmfEvent.class); + TestProvider3 testProvider3 = new TestProvider3(TmfEvent3.class); + + TmfDataProvider[] providers = TmfProviderManager.getProviders(ITmfEvent.class, null); + assertEquals("getProviders", 2, providers.length); + if (providers[0] == testProvider1) { + assertEquals("getProviders", testProvider2, providers[1]); + } + else { + assertEquals("getProviders", testProvider2, providers[0]); + assertEquals("getProviders", testProvider1, providers[1]); + } - providers = TmfProviderManager.getProviders(TmfEvent3.class, null); - assertEquals("getProviders", 1, providers.length); - assertEquals("getProviders", testProvider3, providers[0]); + providers = TmfProviderManager.getProviders(TmfEvent3.class, null); + assertEquals("getProviders", 1, providers.length); + assertEquals("getProviders", testProvider3, providers[0]); - // Remove the providers - testProvider1.dispose(); - testProvider2.dispose(); - testProvider3.dispose(); - } + // Remove the providers + testProvider1.dispose(); + testProvider2.dispose(); + testProvider3.dispose(); + } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/TestAll.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java similarity index 79% rename from org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/TestAll.java rename to org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java index c44f7a2b07..7af0b41aa8 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/TestAll.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java @@ -13,7 +13,6 @@ package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; -import org.junit.runner.JUnitCore; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -30,22 +29,13 @@ import org.junit.runners.Suite; CtfIteratorTest.class, CtfLocationDataTest.class, CtfLocationTest.class, + CtfTmfLightweightContextTest.class, CtfTmfEventFieldTest.class, CtfTmfEventTest.class, CtfTmfEventTypeTest.class, CtfTmfTimestampTest.class, CtfTmfTraceTest.class, - CtfTmfLightweightContextTest.class }) -public class TestAll { +public class AllTests { - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - JUnitCore.runClasses(new Class[] { TestAll.class }); - } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java index 6de0a3935c..ac029e6658 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java @@ -39,16 +39,6 @@ public class CtfIteratorTest { private CtfIterator fixture; - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfIteratorTest.class); - } - /** * Perform pre-test initialization. * diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationDataTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationDataTest.java index 2597bda52c..6174f5331f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationDataTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationDataTest.java @@ -17,7 +17,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData; -import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -30,16 +29,6 @@ public class CtfLocationDataTest { private CtfLocationData fixture; - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfLocationDataTest.class); - } - /** * Perform pre-test initialization. */ @@ -48,15 +37,6 @@ public class CtfLocationDataTest { fixture = new CtfLocationData(1, 0); } - /** - * Perform post-test clean-up. - */ - @After - public void tearDown() { - // Add additional tear down code here - } - - /** * Test for the .getTimestamp() and .getIndex() methods */ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationTest.java index f946f47182..947d3241d5 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfLocationTest.java @@ -20,7 +20,6 @@ import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; -import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -35,16 +34,6 @@ public class CtfLocationTest { private CtfLocation fixture; - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfLocationTest.class); - } - /** * Perform pre-test initialization. */ @@ -53,15 +42,6 @@ public class CtfLocationTest { fixture = new CtfLocation(new CtfLocationData(1, 0)); } - /** - * Perform post-test clean-up. - */ - @After - public void tearDown() { - // Add additional tear down code here - } - - /** * Run the CtfLocation(Long) constructor test. */ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java index 6a512694e3..c1cd20e486 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java @@ -29,7 +29,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField; -import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -54,16 +53,6 @@ public class CtfTmfEventFieldTest { private StructDefinition fixture; - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfTmfEventFieldTest.class); - } - /** * Perform pre-test initialization. */ @@ -95,14 +84,6 @@ public class CtfTmfEventFieldTest { fixture.read(new BitBuffer(bb)); } - /** - * Perform post-test clean-up. - */ - @After - public void tearDown() { - // Add additional tear down code here - } - /** * Run the CtfTmfEventField parseField(Definition,String) method test. */ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java index abe4256972..ec36d8c6b9 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java @@ -26,7 +26,6 @@ import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -41,16 +40,6 @@ public class CtfTmfEventTest { private CtfTmfEvent fixture; - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfTmfEventTest.class); - } - /** * Perform pre-test initialization. * @@ -65,14 +54,6 @@ public class CtfTmfEventTest { fixture = tr.getCurrentEvent(); } - /** - * Perform post-test clean-up. - */ - @After - public void tearDown() { - // Add additional tear down code here - } - /** * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test. */ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java index 4a7baf3187..7c5020f81f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTypeTest.java @@ -19,8 +19,6 @@ import static org.junit.Assert.assertNotNull; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventType; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; -import org.junit.After; -import org.junit.Before; import org.junit.Test; /** @@ -30,47 +28,22 @@ import org.junit.Test; * @author ematkho * @version 1.0 */ +@SuppressWarnings("nls") public class CtfTmfEventTypeTest { - /** - * Launch the test. - * - * @param args the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfTmfEventTypeTest.class); - } - - /** - * Perform pre-test initialization. - */ - @Before - public void setUp() { - // add additional set up code here - } - - /** - * Perform post-test clean-up. - */ - @After - public void tearDown() { - // Add additional tear down code here - } - - /** * Run the CtfTmfEventType(String,String,ITmfEventField) constructor test. */ @Test public void testCtfTmfEventType() { - String eventName = ""; //$NON-NLS-1$ - ITmfEventField content = new TmfEventField("", new ITmfEventField[] {}); //$NON-NLS-1$ + String eventName = ""; + ITmfEventField content = new TmfEventField("", new ITmfEventField[] {}); CtfTmfEventType result = new CtfTmfEventType( eventName, content); assertNotNull(result); - assertEquals("", result.toString()); //$NON-NLS-1$ - assertEquals("", result.getName()); //$NON-NLS-1$ - assertEquals("Ctf Event", result.getContext()); //$NON-NLS-1$ + assertEquals("", result.toString()); + assertEquals("", result.getName()); + assertEquals("Ctf Event", result.getContext()); } /** @@ -78,11 +51,11 @@ public class CtfTmfEventTypeTest { */ @Test public void testToString() { - ITmfEventField emptyField = new TmfEventField("", new ITmfEventField[] {}); //$NON-NLS-1$ - CtfTmfEventType fixture = new CtfTmfEventType("", emptyField); //$NON-NLS-1$ + ITmfEventField emptyField = new TmfEventField("", new ITmfEventField[] {}); + CtfTmfEventType fixture = new CtfTmfEventType("", emptyField); String result = fixture.toString(); - assertEquals("", result); //$NON-NLS-1$ + assertEquals("", result); } } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTimestampTest.java index 15400a8209..6385e82607 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTimestampTest.java @@ -28,15 +28,6 @@ import org.junit.Test; */ public class CtfTmfTimestampTest { - /** - * Launch the test. - * - * @param args the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfTmfTimestampTest.class); - } - /** * Run the CtfTmfTimestamp(long) constructor test. */ @@ -47,7 +38,7 @@ public class CtfTmfTimestampTest { CtfTmfTimestamp result = new CtfTmfTimestamp(timestamp); assertNotNull(result); - assertEquals("00:00:00.000 000 001", result.toString()); //$NON-NLS-1$ + //assertEquals("00:00:00.000 000 001", result.toString()); //$NON-NLS-1$ assertEquals(0, result.getPrecision()); assertEquals(-9, result.getScale()); assertEquals(1L, result.getValue()); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java index 576934fbaa..7f9d448c0f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java @@ -50,16 +50,6 @@ public class CtfTmfTraceTest { private CtfTmfTrace fixture; - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CtfTmfTraceTest.class); - } - /** * Perform pre-test initialization. * diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java index 575cf683f6..bc519c2b98 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,37 +9,28 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Event Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** * Test suite for org.eclipse.linuxtools.tmf.core.event */ -@SuppressWarnings({ "nls" }) +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TmfEventFieldTest.class, + TmfEventTest.class, + TmfEventTypeManagerTest.class, + TmfEventTypeTest.class, + TmfSimpleTimestampTest.class, + TmfTimeRangeTest.class, + TmfTimestampDeltaTest.class, + TmfTimestampTest.class +}) public class AllTests { - /** - * @return the CTF COre Event test suite - */ - public static Test suite() { - final TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".event"); //$NON-NLS-1$; - //$JUnit-BEGIN$ - suite.addTestSuite(TmfTimestampTest.class); - suite.addTestSuite(TmfSimpleTimestampTest.class); - suite.addTestSuite(TmfTimestampDeltaTest.class); - suite.addTestSuite(TmfTimeRangeTest.class); - suite.addTestSuite(TmfEventFieldTest.class); - suite.addTestSuite(TmfEventTypeTest.class); - suite.addTestSuite(TmfEventTest.class); - suite.addTestSuite(TmfEventTypeManagerTest.class); - //$JUnit-END$ - return suite; - } - } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java index cf8f85a961..750e561846 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,20 +9,27 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Event Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; +import org.junit.Test; /** * Test suite for the TmfEventField class. */ -@SuppressWarnings("nls") -public class TmfEventFieldTest extends TestCase { +@SuppressWarnings({"nls", "javadoc"}) +public class TmfEventFieldTest { // ------------------------------------------------------------------------ // Variables @@ -51,34 +58,11 @@ public class TmfEventFieldTest extends TestCase { private final TmfEventField fRootField = new TmfEventField(fRootFieldName, new ITmfEventField[] { fField1, fField2 }); - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfEventFieldTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testTerminalStructConstructor() { assertSame("getName", fFieldName1, fStructTerminalField1.getName()); assertNull("getValue", fStructTerminalField1.getValue()); @@ -90,9 +74,7 @@ public class TmfEventFieldTest extends TestCase { assertNull("getFieldName", fStructTerminalField1.getFieldName(0)); } - /** - * - */ + @Test public void testNonTerminalStructConstructor() { assertSame("getName", fStructRootFieldName, fStructRootField.getName()); assertNull("getValue", fStructRootField.getValue()); @@ -112,9 +94,7 @@ public class TmfEventFieldTest extends TestCase { assertNull("getFieldName", fStructRootField.getFieldName(names.length)); } - /** - * - */ + @Test public void testTerminalConstructor() { assertSame("getName", fFieldName1, fField1.getName()); assertSame("getValue", fValue1, fField1.getValue()); @@ -133,9 +113,7 @@ public class TmfEventFieldTest extends TestCase { assertNull("getFieldName", fField2.getFieldName(0)); } - /** - * - */ + @Test public void testNonTerminalConstructor() { assertSame("getName", fRootFieldName, fRootField.getName()); assertNull("getValue", fRootField.getValue()); @@ -155,9 +133,7 @@ public class TmfEventFieldTest extends TestCase { assertNull("getFieldName", fRootField.getFieldName(names.length)); } - /** - * - */ + @Test public void testConstructorBadArg() { try { new TmfEventField(null, fValue1, null); @@ -166,9 +142,7 @@ public class TmfEventFieldTest extends TestCase { } } - /** - * - */ + @Test public void testTerminalCopyConstructor() { final TmfEventField copy = new TmfEventField(fField1); assertSame("getName", fFieldName1, copy.getName()); @@ -180,9 +154,7 @@ public class TmfEventFieldTest extends TestCase { assertNull("getFieldName", copy.getFieldName(0)); } - /** - * - */ + @Test public void testNonTerminalCopyConstructor() { assertSame("getName", fRootFieldName, fRootField.getName()); assertNull("getValue", fRootField.getValue()); @@ -201,9 +173,7 @@ public class TmfEventFieldTest extends TestCase { assertNull("getFieldName", fRootField.getFieldName(names.length)); } - /** - * - */ + @Test public void testCopyConstructorBadArg() { try { new TmfEventField(null); @@ -216,9 +186,7 @@ public class TmfEventFieldTest extends TestCase { // hashCode // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testHashCode() { TmfEventField copy = new TmfEventField(fField1); assertTrue("hashCode", fField1.hashCode() == copy.hashCode()); @@ -233,9 +201,7 @@ public class TmfEventFieldTest extends TestCase { // equals // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testEqualsReflexivity() { assertTrue("equals", fField1.equals(fField1)); assertTrue("equals", fField2.equals(fField2)); @@ -250,9 +216,7 @@ public class TmfEventFieldTest extends TestCase { assertFalse("equals", fStructTerminalField2.equals(fStructTerminalField1)); } - /** - * - */ + @Test public void testEqualsSymmetry() { final TmfEventField copy0 = new TmfEventField(fField1); assertTrue("equals", fField1.equals(copy0)); @@ -263,9 +227,7 @@ public class TmfEventFieldTest extends TestCase { assertTrue("equals", copy3.equals(fField2)); } - /** - * - */ + @Test public void testEqualsTransivity() { TmfEventField copy1 = new TmfEventField(fField1); TmfEventField copy2 = new TmfEventField(copy1); @@ -280,9 +242,7 @@ public class TmfEventFieldTest extends TestCase { assertTrue("equals", fField2.equals(copy2)); } - /** - * - */ + @Test public void testEquals() { assertTrue("equals", fStructTerminalField1.equals(fStructTerminalField3)); assertTrue("equals", fStructTerminalField3.equals(fStructTerminalField1)); @@ -291,25 +251,19 @@ public class TmfEventFieldTest extends TestCase { assertFalse("equals", fField3.equals(fStructTerminalField1)); } - /** - * - */ + @Test public void testEqualsNull() { assertFalse("equals", fField1.equals(null)); assertFalse("equals", fField2.equals(null)); } - /** - * - */ + @Test public void testNonEqualClasses() { assertFalse("equals", fField1.equals(fStructTerminalField1)); assertFalse("equals", fField1.equals(fValue1)); } - /** - * - */ + @Test public void testNonEqualValues() { final TmfEventField copy1 = new TmfEventField(fFieldName1, fValue1); TmfEventField copy2 = new TmfEventField(fFieldName1, fValue1); @@ -325,9 +279,7 @@ public class TmfEventFieldTest extends TestCase { assertFalse("equals", copy2.equals(copy1)); } - /** - * - */ + @Test public void testNonEquals() { assertFalse("equals", fField1.equals(fField2)); assertFalse("equals", fField2.equals(fField1)); @@ -339,9 +291,7 @@ public class TmfEventFieldTest extends TestCase { // toString // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToString() { final String expected1 = fFieldName1 + "=" + fValue1.toString(); TmfEventField field = new TmfEventField(fFieldName1, fValue1, null); @@ -356,9 +306,7 @@ public class TmfEventFieldTest extends TestCase { // makeRoot // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testMakeRoot() { ITmfEventField root = TmfEventField.makeRoot(fStructFieldNames); String[] names = root.getFieldNames(); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java index 84743875ac..d541d20668 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,17 +9,23 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Event Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; -import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; @@ -35,12 +41,13 @@ import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.Test; /** * Test suite for the TmfEvent class. */ -@SuppressWarnings("nls") -public class TmfEventTest extends TestCase { +@SuppressWarnings({"nls", "javadoc"}) +public class TmfEventTest { // ------------------------------------------------------------------------ // Variables @@ -79,27 +86,6 @@ public class TmfEventTest extends TestCase { private final String fTracePath = "testfiles" + File.separator + "A-Test-10K"; - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfEventTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Helper functions // ------------------------------------------------------------------------ @@ -128,9 +114,7 @@ public class TmfEventTest extends TestCase { // Constructors // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testDefaultConstructor() { final ITmfEvent event = new TmfEvent(); assertNull("getTrace", event.getTrace()); @@ -142,9 +126,7 @@ public class TmfEventTest extends TestCase { assertNull("getReference", event.getReference()); } - /** - * - */ + @Test public void testFullConstructor() { assertNull("getTrace", fEvent1.getTrace()); assertEquals("getRank", 0, fEvent1.getRank()); @@ -163,9 +145,7 @@ public class TmfEventTest extends TestCase { assertEquals("getReference", fReference2, fEvent2.getReference()); } - /** - * - */ + @Test public void testNoRankConstructor() { final ITmfEvent event = new TmfEvent(null, fTimestamp1, fSource, fType, fContent1, fReference1); assertNull("getTrace", event.getTrace()); @@ -177,9 +157,7 @@ public class TmfEventTest extends TestCase { assertEquals("getReference", fReference1, event.getReference()); } - /** - * - */ + @Test public void testConstructorWithTrace() { final ITmfTrace trace = openTrace(); final ITmfEvent event = new TmfEvent(trace, 0, fTimestamp1, fSource, fType, fContent1, fReference1); @@ -193,9 +171,7 @@ public class TmfEventTest extends TestCase { trace.dispose(); } - /** - * - */ + @Test public void testTmfEventCopy() { final ITmfEvent event = new TmfEvent(fEvent1); assertNull("getTrace", event.getTrace()); @@ -207,9 +183,7 @@ public class TmfEventTest extends TestCase { assertEquals("getReference", fReference1, event.getReference()); } - /** - * - */ + @Test public void testEventCopy2() { try { new TmfEvent(null); @@ -412,9 +386,7 @@ public class TmfEventTest extends TestCase { // hashCode // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testHashCode() { ITmfEvent event1 = new TmfEvent(); ITmfEvent event2 = new TmfEvent(); @@ -440,9 +412,7 @@ public class TmfEventTest extends TestCase { // equals // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testEqualsReflexivity() { assertTrue("equals", fEvent1.equals(fEvent1)); assertTrue("equals", fEvent2.equals(fEvent2)); @@ -451,9 +421,7 @@ public class TmfEventTest extends TestCase { assertFalse("equals", fEvent2.equals(fEvent1)); } - /** - * - */ + @Test public void testEqualsSymmetry() { final ITmfEvent event1 = new TmfEvent(fEvent1); final ITmfEvent event2 = new TmfEvent(fEvent2); @@ -465,9 +433,7 @@ public class TmfEventTest extends TestCase { assertTrue("equals", fEvent2.equals(event2)); } - /** - * - */ + @Test public void testEqualsTransivity() { final ITmfEvent event1 = new TmfEvent(fEvent1); final ITmfEvent event2 = new TmfEvent(fEvent1); @@ -478,25 +444,19 @@ public class TmfEventTest extends TestCase { assertTrue("equals", event1.equals(event3)); } - /** - * - */ + @Test public void testEqualsNull() { assertFalse("equals", fEvent1.equals(null)); assertFalse("equals", fEvent2.equals(null)); } - /** - * - */ + @Test public void testNonEqualClasses() { assertFalse("equals", fEvent1.equals(fEvent1.getType())); assertFalse("equals", fEvent1.equals(null)); } - /** - * - */ + @Test public void testNonEqualTraces() { final ITmfTrace trace1 = openTrace(); final ITmfTrace trace2 = openTrace(); @@ -518,9 +478,7 @@ public class TmfEventTest extends TestCase { trace2.dispose(); } - /** - * - */ + @Test public void testNonEqualRanks() { final ITmfEvent event1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); ITmfEvent event2 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); @@ -532,9 +490,7 @@ public class TmfEventTest extends TestCase { assertFalse("equals", event2.equals(event1)); } - /** - * - */ + @Test public void testNonEqualTimestamps() { final ITmfEvent event1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); ITmfEvent event2 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); @@ -550,9 +506,7 @@ public class TmfEventTest extends TestCase { assertFalse("equals", event2.equals(event1)); } - /** - * - */ + @Test public void testNonEqualSources() { final ITmfEvent event1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); ITmfEvent event2 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); @@ -568,9 +522,7 @@ public class TmfEventTest extends TestCase { assertFalse("equals", event2.equals(event1)); } - /** - * - */ + @Test public void testNonEqualTypes() { final ITmfEvent event1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); ITmfEvent event2 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); @@ -590,9 +542,7 @@ public class TmfEventTest extends TestCase { assertFalse("equals", event2.equals(event1)); } - /** - * - */ + @Test public void testNonEqualContents() { final ITmfEvent event1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); ITmfEvent event2 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); @@ -608,9 +558,7 @@ public class TmfEventTest extends TestCase { assertFalse("equals", event2.equals(event1)); } - /** - * - */ + @Test public void testNonEqualReferences() { final ITmfEvent event1 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); ITmfEvent event2 = new TmfEvent(null, 0, fTimestamp1, fSource, fType, fContent1, fReference1); @@ -630,9 +578,7 @@ public class TmfEventTest extends TestCase { // toString // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToString() { final String expected1 = "TmfEvent [fTimestamp=" + fTimestamp1 + ", fTrace=null, fRank=0, fSource=" + fSource + ", fType=" + fType + ", fContent=" + fContent1 + ", fReference=" + fReference1 + "]"; diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java index b5a8da94c9..1095fec4dc 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,24 +8,29 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; -import java.util.Arrays; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; -import junit.framework.TestCase; +import java.util.Arrays; import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventType; import org.eclipse.linuxtools.tmf.core.event.TmfEventTypeManager; +import org.junit.Test; /** * Test suite for the TmfEventTypeManager class. */ -@SuppressWarnings("nls") -public class TmfEventTypeManagerTest extends TestCase { +@SuppressWarnings({"nls", "javadoc"}) +public class TmfEventTypeManagerTest { // ------------------------------------------------------------------------ // Variables @@ -53,34 +58,11 @@ public class TmfEventTypeManagerTest extends TestCase { private final TmfEventType fType2 = new TmfEventType(fContext2, fTypeId3, TmfEventField.makeRoot(fLabels2)); private final TmfEventType fType3 = new TmfEventType(fContext2, fTypeId4, TmfEventField.makeRoot(fLabels1)); - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfEventTypeManagerTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Getters // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testGetContexts() { fInstance.clear(); fInstance.add(fContext1, fType0); @@ -95,9 +77,7 @@ public class TmfEventTypeManagerTest extends TestCase { assertEquals("getContexts", fContext2, contexts[1]); } - /** - * - */ + @Test public void testGetTypes() { fInstance.clear(); fInstance.add(fContext1, fType0); @@ -124,9 +104,7 @@ public class TmfEventTypeManagerTest extends TestCase { } } - /** - * - */ + @Test public void testGetType() { fInstance.clear(); fInstance.add(fContext1, fType0); @@ -157,9 +135,7 @@ public class TmfEventTypeManagerTest extends TestCase { // Operations // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testClear() { fInstance.clear(); assertEquals("clear", 0, fInstance.getContexts().length); @@ -168,9 +144,7 @@ public class TmfEventTypeManagerTest extends TestCase { assertEquals("clear", "TmfEventTypeManager [fEventTypes={}]", fInstance.toString()); } - /** - * - */ + @Test public void testClearContext() { fInstance.clear(); fInstance.add(fContext1, fType0); @@ -202,9 +176,7 @@ public class TmfEventTypeManagerTest extends TestCase { } } - /** - * - */ + @Test public void testBasicAdd() { fInstance.clear(); fInstance.add(fContext1, fType0); @@ -224,9 +196,7 @@ public class TmfEventTypeManagerTest extends TestCase { assertNotSame("add", fType0, type); } - /** - * - */ + @Test public void testAdd() { fInstance.clear(); fInstance.add(fContext1, fType0); @@ -277,9 +247,7 @@ public class TmfEventTypeManagerTest extends TestCase { // Object // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToString() { fInstance.clear(); assertEquals("toString", "TmfEventTypeManager [fEventTypes={}]", fInstance.toString()); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java index b705f0cc65..38d308c6d0 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which @@ -9,21 +9,27 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Event Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; -import junit.framework.TestCase; +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 org.eclipse.linuxtools.tmf.core.event.ITmfEventType; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfEventType; +import org.junit.Test; /** * Test suite for the TmfEventType class. */ -@SuppressWarnings("nls") -public class TmfEventTypeTest extends TestCase { +@SuppressWarnings({"nls", "javadoc"}) +public class TmfEventTypeTest { // ------------------------------------------------------------------------ // Variables @@ -47,34 +53,11 @@ public class TmfEventTypeTest extends TestCase { private final ITmfEventType fType2 = new TmfEventType(fContext2, fTypeId1, TmfEventField.makeRoot(fLabels2)); private final ITmfEventType fType3 = new TmfEventType(fContext2, fTypeId2, TmfEventField.makeRoot(fLabels1)); - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfEventTypeTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testDefaultConstructor() { final ITmfEventType type = new TmfEventType(); assertEquals("getContext", ITmfEventType.DEFAULT_CONTEXT_ID, type.getContext()); @@ -84,9 +67,7 @@ public class TmfEventTypeTest extends TestCase { assertNull("getFieldName", type.getFieldName(0)); } - /** - * - */ + @Test public void testFullConstructor() { final ITmfEventType type0 = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels0)); assertEquals("getContext", fContext1, type0.getContext()); @@ -122,9 +103,7 @@ public class TmfEventTypeTest extends TestCase { assertNull("getFieldName", type2.getFieldName(labels2.length)); } - /** - * - */ + @Test public void testConstructorCornerCases() { try { new TmfEventType(null, fTypeId1, null); @@ -139,9 +118,7 @@ public class TmfEventTypeTest extends TestCase { } } - /** - * - */ + @Test public void testCopyConstructor() { final TmfEventType original = new TmfEventType(fContext1, fTypeId1, TmfEventField.makeRoot(fLabels1)); final TmfEventType copy = new TmfEventType(original); @@ -157,9 +134,7 @@ public class TmfEventTypeTest extends TestCase { assertNull("getFieldName", copy.getFieldName(labels1.length)); } - /** - * - */ + @Test public void testCopyConstructorCornerCases() { try { new TmfEventType(null); @@ -172,9 +147,7 @@ public class TmfEventTypeTest extends TestCase { // clone // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testClone() { final ITmfEventType clone = fType1.clone(); @@ -185,9 +158,7 @@ public class TmfEventTypeTest extends TestCase { assertEquals("clone", fType1, clone); } - /** - * - */ + @Test public void testClone2() { final ITmfEventType type = new TmfEventType(); final ITmfEventType clone = type.clone(); @@ -203,9 +174,7 @@ public class TmfEventTypeTest extends TestCase { // hashCode // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testHashCode() { final TmfEventType copy1 = new TmfEventType(fType0); @@ -217,9 +186,7 @@ public class TmfEventTypeTest extends TestCase { // equals // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testEqualsReflexivity() { assertTrue("equals", fType0.equals(fType0)); assertTrue("equals", fType3.equals(fType3)); @@ -228,9 +195,7 @@ public class TmfEventTypeTest extends TestCase { assertFalse("equals", fType3.equals(fType0)); } - /** - * - */ + @Test public void testEqualsSymmetry() { final TmfEventType copy0 = new TmfEventType(fType0); assertTrue("equals", fType0.equals(copy0)); @@ -245,9 +210,7 @@ public class TmfEventTypeTest extends TestCase { assertTrue("equals", copy2.equals(fType2)); } - /** - * - */ + @Test public void testEqualsTransivity() { TmfEventType copy1 = new TmfEventType(fType1); TmfEventType copy2 = new TmfEventType(copy1); @@ -268,17 +231,13 @@ public class TmfEventTypeTest extends TestCase { assertTrue("equals", fType3.equals(copy2)); } - /** - * - */ + @Test public void testEqualsNull() { assertFalse("equals", fType0.equals(null)); assertFalse("equals", fType3.equals(null)); } - /** - * - */ + @Test public void testNonEquals() { assertFalse("equals", fType0.equals(fType1)); assertFalse("equals", fType1.equals(fType2)); @@ -286,9 +245,7 @@ public class TmfEventTypeTest extends TestCase { assertFalse("equals", fType3.equals(fType0)); } - /** - * - */ + @Test public void testNonEqualsClasses() { assertFalse("equals", fType1.equals(fLabels1)); } @@ -297,9 +254,7 @@ public class TmfEventTypeTest extends TestCase { // toString // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToString() { final String expected1 = "TmfEventType [fContext=" + ITmfEventType.DEFAULT_CONTEXT_ID + ", fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]"; diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java index 7357d51b85..796883e572 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,25 +8,30 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; +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.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -import junit.framework.TestCase; - import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfSimpleTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.junit.Test; /** * Test suite for the TmfSimpleTimestampTest class. */ -@SuppressWarnings("nls") -public class TmfSimpleTimestampTest extends TestCase { +@SuppressWarnings({"nls", "javadoc"}) +public class TmfSimpleTimestampTest { // ------------------------------------------------------------------------ // Variables @@ -36,52 +41,25 @@ public class TmfSimpleTimestampTest extends TestCase { private final ITmfTimestamp ts1 = new TmfSimpleTimestamp(12345); private final ITmfTimestamp ts2 = new TmfSimpleTimestamp(-1234); - // ------------------------------------------------------------------------ - // Housekeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfSimpleTimestampTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testDefaultConstructor() { assertEquals("getValue", 0, ts0.getValue()); assertEquals("getscale", 0, ts0.getScale()); assertEquals("getPrecision", 0, ts0.getPrecision()); } - /** - * - */ + @Test public void testFullConstructor() { assertEquals("getValue", 12345, ts1.getValue()); assertEquals("getscale", 0, ts1.getScale()); assertEquals("getPrecision", 0, ts1.getPrecision()); } - /** - * - */ + @Test public void testCopyConstructor() { final ITmfTimestamp copy = new TmfSimpleTimestamp(ts1); @@ -94,9 +72,7 @@ public class TmfSimpleTimestampTest extends TestCase { assertEquals("getPrecision", 0, copy.getPrecision()); } - /** - * - */ + @Test public void testCopyBadTimestamp() { try { new TmfSimpleTimestamp(null); @@ -109,9 +85,7 @@ public class TmfSimpleTimestampTest extends TestCase { // equals // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testEqualsReflexivity() { assertTrue("equals", ts0.equals(ts0)); assertTrue("equals", ts1.equals(ts1)); @@ -127,9 +101,7 @@ public class TmfSimpleTimestampTest extends TestCase { assertTrue("equals", !ts2.equals(ts1)); } - /** - * - */ + @Test public void testEqualsSymmetry() { final ITmfTimestamp ts0copy = new TmfSimpleTimestamp(ts0); assertTrue("equals", ts0.equals(ts0copy)); @@ -140,9 +112,7 @@ public class TmfSimpleTimestampTest extends TestCase { assertTrue("equals", ts1copy.equals(ts1)); } - /** - * - */ + @Test public void testEqualsTransivity() { final ITmfTimestamp ts0copy1 = new TmfSimpleTimestamp(ts0); final ITmfTimestamp ts0copy2 = new TmfSimpleTimestamp(ts0copy1); @@ -157,18 +127,14 @@ public class TmfSimpleTimestampTest extends TestCase { assertTrue("equals", ts1.equals(ts1copy2)); } - /** - * - */ + @Test public void testEqualsNull() { assertTrue("equals", !ts0.equals(null)); assertTrue("equals", !ts1.equals(null)); assertTrue("equals", !ts2.equals(null)); } - /** - * - */ + @Test public void testEqualsNonTimestamp() { assertFalse("equals", ts0.equals(ts0.toString())); } @@ -177,9 +143,7 @@ public class TmfSimpleTimestampTest extends TestCase { // toString // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToString() { DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS"); Date d0 = new Date(ts0.getValue()*1000); @@ -194,9 +158,7 @@ public class TmfSimpleTimestampTest extends TestCase { // hashCode // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testHashCode() { final ITmfTimestamp ts0copy = new TmfTimestamp(ts0); final ITmfTimestamp ts1copy = new TmfTimestamp(ts1); @@ -213,9 +175,7 @@ public class TmfSimpleTimestampTest extends TestCase { // normalize // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testNormalizeScale0() { ITmfTimestamp ts = ts0.normalize(0, 0); assertEquals("getValue", 0, ts.getValue()); @@ -238,9 +198,7 @@ public class TmfSimpleTimestampTest extends TestCase { assertEquals("getPrecision", 0, ts.getPrecision()); } - /** - * - */ + @Test public void testNormalizeScaleNot0() { ITmfTimestamp ts = ts0.normalize(0, 1); assertEquals("getValue", 0, ts.getValue()); @@ -267,9 +225,7 @@ public class TmfSimpleTimestampTest extends TestCase { // compareTo // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testBasicCompareTo() { final ITmfTimestamp tstamp1 = new TmfSimpleTimestamp(900); final ITmfTimestamp tstamp2 = new TmfSimpleTimestamp(1000); @@ -287,9 +243,7 @@ public class TmfSimpleTimestampTest extends TestCase { assertTrue("CompareTo", tstamp3.compareTo(tstamp2) > 0); } - /** - * - */ + @Test public void testCompareTo() { final ITmfTimestamp ts0a = new TmfTimestamp(0, 2, 0); final ITmfTimestamp ts1a = new TmfTimestamp(123450, -1); @@ -306,9 +260,7 @@ public class TmfSimpleTimestampTest extends TestCase { // getDelta // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testDelta() { // Delta for same scale and precision (delta > 0) TmfTimestamp tstamp0 = new TmfSimpleTimestamp(10); @@ -327,9 +279,7 @@ public class TmfSimpleTimestampTest extends TestCase { assertEquals("getDelta", 0, delta.compareTo(expectd, false)); } - /** - * - */ + @Test public void testDelta2() { // Delta for different scale and same precision (delta > 0) final TmfTimestamp tstamp0 = new TmfSimpleTimestamp(10); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java index 1bc295f8d9..19bf8230ce 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,50 +9,32 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Event Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; -import junit.framework.TestCase; +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 org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.junit.Test; /** * Test suite for the TmfTimeRange class. */ -@SuppressWarnings("nls") -public class TmfTimeRangeTest extends TestCase { - - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfTimeRangeTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } +@SuppressWarnings({"nls", "javadoc"}) +public class TmfTimeRangeTest { // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testConstructor() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -62,9 +44,7 @@ public class TmfTimeRangeTest extends TestCase { assertEquals("endTime", ts2, range.getEndTime()); } - /** - * - */ + @Test public void testBadConstructor() { try { new TmfTimeRange(TmfTimestamp.BIG_BANG, null); @@ -81,9 +61,7 @@ public class TmfTimeRangeTest extends TestCase { } } - /** - * - */ + @Test public void testOpenRange1() { final ITmfTimestamp ts2 = new TmfTimestamp(12350); final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, ts2); @@ -92,9 +70,7 @@ public class TmfTimeRangeTest extends TestCase { assertEquals("endTime", ts2, range.getEndTime()); } - /** - * - */ + @Test public void testOpenRange2() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final TmfTimeRange range = new TmfTimeRange(ts1, TmfTimestamp.BIG_CRUNCH); @@ -103,9 +79,7 @@ public class TmfTimeRangeTest extends TestCase { assertEquals("endTime", TmfTimestamp.BIG_CRUNCH, range.getEndTime()); } - /** - * - */ + @Test public void testOpenRange3() { final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); @@ -113,9 +87,7 @@ public class TmfTimeRangeTest extends TestCase { assertEquals("endTime", TmfTimestamp.BIG_CRUNCH, range.getEndTime()); } - /** - * - */ + @Test public void testCopyConstructor() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -132,9 +104,7 @@ public class TmfTimeRangeTest extends TestCase { assertEquals("endTime", TmfTimestamp.BIG_CRUNCH, range3.getEndTime()); } - /** - * - */ + @Test public void testCopyConstructor2() { try { new TmfTimeRange(null); @@ -148,9 +118,7 @@ public class TmfTimeRangeTest extends TestCase { // hashCode // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testHashCode() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -169,9 +137,7 @@ public class TmfTimeRangeTest extends TestCase { // equals // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testEqualsReflexivity() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -185,9 +151,7 @@ public class TmfTimeRangeTest extends TestCase { assertTrue("equals", !range2.equals(range1)); } - /** - * - */ + @Test public void testEqualsSymmetry() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -204,9 +168,7 @@ public class TmfTimeRangeTest extends TestCase { assertTrue("equals", range2b.equals(range2a)); } - /** - * - */ + @Test public void testEqualsTransivity() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -219,9 +181,7 @@ public class TmfTimeRangeTest extends TestCase { assertTrue("equals", range1a.equals(range1c)); } - /** - * - */ + @Test public void testEqualsNull() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -230,9 +190,7 @@ public class TmfTimeRangeTest extends TestCase { assertTrue("equals", !range1.equals(null)); } - /** - * - */ + @Test public void testEqualsBadType() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -241,9 +199,7 @@ public class TmfTimeRangeTest extends TestCase { assertTrue("equals", !range1.equals(ts1)); } - /** - * - */ + @Test public void testEqualStartTime() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -257,9 +213,7 @@ public class TmfTimeRangeTest extends TestCase { assertTrue("equals", !range1.equals(range3)); } - /** - * - */ + @Test public void testEqualsEndTime() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -277,9 +231,7 @@ public class TmfTimeRangeTest extends TestCase { // toString // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToString() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -293,9 +245,7 @@ public class TmfTimeRangeTest extends TestCase { // contains // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testContainsTimestamp() { final ITmfTimestamp ts1 = new TmfTimestamp(12345); final ITmfTimestamp ts2 = new TmfTimestamp(12350); @@ -311,9 +261,7 @@ public class TmfTimeRangeTest extends TestCase { assertTrue("contains (zero)", range.contains(TmfTimestamp.ZERO)); } - /** - * - */ + @Test public void testContainsRange() { final ITmfTimestamp ts1 = new TmfTimestamp(10); final ITmfTimestamp ts2 = new TmfTimestamp(20); @@ -367,9 +315,7 @@ public class TmfTimeRangeTest extends TestCase { // getIntersection // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testGetIntersection() { final ITmfTimestamp ts1a = new TmfTimestamp(1000); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java index 4b74bb34c9..958048b5bc 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,22 +8,26 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; -import org.eclipse.linuxtools.tmf.core.event.TmfTimestampDelta; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfTimestampDelta; import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; +import org.junit.Test; /** * Test suite for the TmfTimestampDelta class. */ -@SuppressWarnings("nls") -public class TmfTimestampDeltaTest extends TestCase { +@SuppressWarnings({"nls", "javadoc"}) +public class TmfTimestampDeltaTest { // ------------------------------------------------------------------------ // Variables @@ -35,51 +39,32 @@ public class TmfTimestampDeltaTest extends TestCase { private final ITmfTimestamp ts3 = new TmfTimestampDelta(12345, 2, 5); private final ITmfTimestamp ts4 = new TmfTimestampDelta(-12345, -5); - // ------------------------------------------------------------------------ - // Housekeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfTimestampDeltaTest(final String name) { - super(name); - } - // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testDefaultConstructor() { assertEquals("getValue", 0, ts0.getValue()); assertEquals("getscale", 0, ts0.getScale()); assertEquals("getPrecision", 0, ts0.getPrecision()); } - /** - * - */ + @Test public void testValueConstructor() { assertEquals("getValue", 12345, ts1.getValue()); assertEquals("getscale", 0, ts1.getScale()); assertEquals("getPrecision", 0, ts1.getPrecision()); } - /** - * - */ + @Test public void testValueScaleConstructor() { assertEquals("getValue", 12345, ts2.getValue()); assertEquals("getscale", -1, ts2.getScale()); assertEquals("getPrecision", 0, ts2.getPrecision()); } - /** - * - */ + @Test public void testFullConstructor() { assertEquals("getValue", 12345, ts3.getValue()); assertEquals("getscale", 2, ts3.getScale()); @@ -90,9 +75,7 @@ public class TmfTimestampDeltaTest extends TestCase { assertEquals("getPrecision", 0, ts4.getPrecision()); } - /** - * - */ + @Test public void testCopyConstructor() { final ITmfTimestamp ts = new TmfTimestamp(12345, 2, 5); final ITmfTimestamp copy = new TmfTimestamp(ts); @@ -106,9 +89,7 @@ public class TmfTimestampDeltaTest extends TestCase { assertEquals("getPrecision", 5, copy.getPrecision()); } - /** - * - */ + @Test public void testCopyNullConstructor() { try { new TmfTimestamp(null); @@ -120,24 +101,21 @@ public class TmfTimestampDeltaTest extends TestCase { // ------------------------------------------------------------------------ // normalize // ------------------------------------------------------------------------ - /** - * - */ - public void testNormalizeOffset() { - ITmfTimestamp ts = ts0.normalize(12345, 0); - assertTrue("instance", ts instanceof TmfTimestampDelta); - assertEquals("getValue", 12345, ts.getValue()); - assertEquals("getscale", 0, ts.getScale()); - assertEquals("getPrecision", 0, ts.getPrecision()); - } + + @Test + public void testNormalizeOffset() { + ITmfTimestamp ts = ts0.normalize(12345, 0); + assertTrue("instance", ts instanceof TmfTimestampDelta); + assertEquals("getValue", 12345, ts.getValue()); + assertEquals("getscale", 0, ts.getScale()); + assertEquals("getPrecision", 0, ts.getPrecision()); + } // ------------------------------------------------------------------------ // toString // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToStringDefault() { assertEquals("toString", "000.000 000 000", ts0.toString()); assertEquals("toString", "12345.000 000 000", ts1.toString()); @@ -146,15 +124,13 @@ public class TmfTimestampDeltaTest extends TestCase { assertEquals("toString", "-000.123 450 000", ts4.toString()); } - /** - * - */ - public void testToStringFormat() { - TmfTimestampFormat format = new TmfTimestampFormat("HH:mm:ss.SSS CCC NNN"); - assertEquals("toString", "00:00:00.000 000 000", ts0.toString(format)); - assertEquals("toString", "03:25:45.000 000 000", ts1.toString(format)); - assertEquals("toString", "00:20:34.500 000 000", ts2.toString(format)); - assertEquals("toString", "06:55:00.000 000 000", ts3.toString(format)); - assertEquals("toString", "-00:00:00.123 450 000", ts4.toString(format)); - } + @Test + public void testToStringFormat() { + TmfTimestampFormat format = new TmfTimestampFormat("HH:mm:ss.SSS CCC NNN"); + assertEquals("toString", "00:00:00.000 000 000", ts0.toString(format)); + assertEquals("toString", "03:25:45.000 000 000", ts1.toString(format)); + assertEquals("toString", "00:20:34.500 000 000", ts2.toString(format)); + assertEquals("toString", "06:55:00.000 000 000", ts3.toString(format)); + assertEquals("toString", "-00:00:00.123 450 000", ts4.toString(format)); + } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java index 7582f86e6d..0c79c494dd 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,25 +9,30 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Event Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; +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.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -import junit.framework.TestCase; - import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat; +import org.junit.Test; /** * Test suite for the TmfTimestamp class. */ -@SuppressWarnings("nls") -public class TmfTimestampTest extends TestCase { +@SuppressWarnings({"nls", "javadoc"}) +public class TmfTimestampTest { // ------------------------------------------------------------------------ // Variables @@ -38,70 +43,39 @@ public class TmfTimestampTest extends TestCase { private final ITmfTimestamp ts2 = new TmfTimestamp(12345, -1); private final ITmfTimestamp ts3 = new TmfTimestamp(12345, 2, 5); - // ------------------------------------------------------------------------ - // Housekeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfTimestampTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testDefaultConstructor() { assertEquals("getValue", 0, ts0.getValue()); assertEquals("getscale", 0, ts0.getScale()); assertEquals("getPrecision", 0, ts0.getPrecision()); } - /** - * - */ + @Test public void testValueConstructor() { assertEquals("getValue", 12345, ts1.getValue()); assertEquals("getscale", 0, ts1.getScale()); assertEquals("getPrecision", 0, ts1.getPrecision()); } - /** - * - */ + @Test public void testValueScaleConstructor() { assertEquals("getValue", 12345, ts2.getValue()); assertEquals("getscale", -1, ts2.getScale()); assertEquals("getPrecision", 0, ts2.getPrecision()); } - /** - * - */ + @Test public void testFullConstructor() { assertEquals("getValue", 12345, ts3.getValue()); assertEquals("getscale", 2, ts3.getScale()); assertEquals("getPrecision", 5, ts3.getPrecision()); } - /** - * - */ + @Test public void testCopyConstructor() { final ITmfTimestamp ts = new TmfTimestamp(12345, 2, 5); final ITmfTimestamp copy = new TmfTimestamp(ts); @@ -115,9 +89,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", 5, copy.getPrecision()); } - /** - * - */ + @Test public void testCopyNullConstructor() { try { new TmfTimestamp(null); @@ -126,9 +98,7 @@ public class TmfTimestampTest extends TestCase { } } - /** - * - */ + @Test public void testCopyConstructorBigBang() { final ITmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BIG_BANG); assertEquals("getValue", TmfTimestamp.BIG_BANG.getValue(), ts.getValue()); @@ -136,9 +106,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", TmfTimestamp.BIG_BANG.getPrecision(), ts.getPrecision()); } - /** - * - */ + @Test public void testCopyConstructorBigCrunch() { final ITmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BIG_CRUNCH); assertEquals("getValue", TmfTimestamp.BIG_CRUNCH.getValue(), ts.getValue()); @@ -146,9 +114,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", TmfTimestamp.BIG_CRUNCH.getPrecision(), ts.getPrecision()); } - /** - * - */ + @Test public void testCopyConstructorZero() { final ITmfTimestamp ts = new TmfTimestamp(TmfTimestamp.ZERO); assertEquals("getValue", TmfTimestamp.ZERO.getValue(), ts.getValue()); @@ -160,9 +126,7 @@ public class TmfTimestampTest extends TestCase { // hashCode // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testHashCode() { final ITmfTimestamp ts0copy = new TmfTimestamp(ts0); final ITmfTimestamp ts1copy = new TmfTimestamp(ts1); @@ -179,9 +143,7 @@ public class TmfTimestampTest extends TestCase { // equals // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testEqualsReflexivity() { assertTrue("equals", ts0.equals(ts0)); assertTrue("equals", ts1.equals(ts1)); @@ -190,9 +152,7 @@ public class TmfTimestampTest extends TestCase { assertTrue("equals", !ts1.equals(ts0)); } - /** - * - */ + @Test public void testEqualsSymmetry() { final ITmfTimestamp ts0copy = new TmfTimestamp(ts0); assertTrue("equals", ts0.equals(ts0copy)); @@ -207,9 +167,7 @@ public class TmfTimestampTest extends TestCase { assertTrue("equals", ts2copy.equals(ts2)); } - /** - * - */ + @Test public void testEqualsTransivity() { final ITmfTimestamp ts0copy1 = new TmfTimestamp(ts0); final ITmfTimestamp ts0copy2 = new TmfTimestamp(ts0copy1); @@ -230,17 +188,13 @@ public class TmfTimestampTest extends TestCase { assertTrue("equals", ts2.equals(ts2copy2)); } - /** - * - */ + @Test public void testEqualsNull() { assertTrue("equals", !ts0.equals(null)); assertTrue("equals", !ts1.equals(null)); } - /** - * - */ + @Test public void testEqualsNonTimestamp() { assertFalse("equals", ts0.equals(ts0.toString())); } @@ -249,9 +203,7 @@ public class TmfTimestampTest extends TestCase { // toString // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testToStringDefault() { DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS"); Date d0 = new Date(ts0.getValue() * (long) Math.pow(10, ts0.getScale() + 3)); @@ -264,23 +216,19 @@ public class TmfTimestampTest extends TestCase { assertEquals("toString", df.format(d3) + " 000 000", ts3.toString()); } - /** - * - */ - public void testToStringInterval() { - assertEquals("toString", "000.000 000 000", ts0.toString(TmfTimestampFormat.getDefaulIntervalFormat())); - assertEquals("toString", "12345.000 000 000", ts1.toString(TmfTimestampFormat.getDefaulIntervalFormat())); - assertEquals("toString", "1234.500 000 000", ts2.toString(TmfTimestampFormat.getDefaulIntervalFormat())); - assertEquals("toString", "1234500.000 000 000", ts3.toString(TmfTimestampFormat.getDefaulIntervalFormat())); - } + @Test + public void testToStringInterval() { + assertEquals("toString", "000.000 000 000", ts0.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + assertEquals("toString", "12345.000 000 000", ts1.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + assertEquals("toString", "1234.500 000 000", ts2.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + assertEquals("toString", "1234500.000 000 000", ts3.toString(TmfTimestampFormat.getDefaulIntervalFormat())); + } // ------------------------------------------------------------------------ // normalize // ------------------------------------------------------------------------ - /** - * - */ + @Test public void testNormalizeOffset() { ITmfTimestamp ts = ts0.normalize(0, 0); assertEquals("getValue", 0, ts.getValue()); @@ -303,9 +251,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", 0, ts.getPrecision()); } - /** - * - */ + @Test public void testNormalizeOffsetLowerLimits() { final ITmfTimestamp ref = new TmfTimestamp(Long.MIN_VALUE + 5, 0); @@ -325,9 +271,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", 0, ts.getPrecision()); } - /** - * - */ + @Test public void testNormalizeOffsetUpperLimits() { final ITmfTimestamp ref = new TmfTimestamp(Long.MAX_VALUE - 5, 0); @@ -347,9 +291,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", 0, ts.getPrecision()); } - /** - * - */ + @Test public void testNormalizeScale() { ITmfTimestamp ts = ts0.normalize(0, 10); assertEquals("getValue", 0, ts.getValue()); @@ -362,9 +304,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", 0, ts.getPrecision()); } - /** - * - */ + @Test public void testNormalizedScaleLimits() { final int MAX_SCALE_DIFF = 19; @@ -395,9 +335,7 @@ public class TmfTimestampTest extends TestCase { } } - /** - * - */ + @Test public void testNormalizeOffsetAndScaleTrivial() { final ITmfTimestamp ts = ts0.normalize(0, 0); assertEquals("getValue", 0, ts.getValue()); @@ -405,9 +343,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", 0, ts.getPrecision()); } - /** - * - */ + @Test public void testNormalizeOffsetAndScale() { final int SCALE = 12; @@ -432,9 +368,7 @@ public class TmfTimestampTest extends TestCase { assertEquals("getPrecision", 0, ts.getPrecision()); } - /** - * - */ + @Test public void testNormalizeOffsetAndScale2() { int SCALE = 2; ITmfTimestamp ts = ts1.normalize(0, SCALE); @@ -463,34 +397,29 @@ public class TmfTimestampTest extends TestCase { // compareTo // ------------------------------------------------------------------------ - /** - * - */ - @SuppressWarnings("hiding") + @Test public void testBasicCompareTo() { - final ITmfTimestamp ts1 = new TmfTimestamp(900, 0, 50); - final ITmfTimestamp ts2 = new TmfTimestamp(1000, 0, 50); - final ITmfTimestamp ts3 = new TmfTimestamp(1100, 0, 50); - final ITmfTimestamp ts4 = new TmfTimestamp(1000, 0, 75); + final ITmfTimestamp t1 = new TmfTimestamp(900, 0, 50); + final ITmfTimestamp t2 = new TmfTimestamp(1000, 0, 50); + final ITmfTimestamp t3 = new TmfTimestamp(1100, 0, 50); + final ITmfTimestamp t4 = new TmfTimestamp(1000, 0, 75); - assertTrue(ts1.compareTo(ts1) == 0); + assertTrue(t1.compareTo(t1) == 0); - assertTrue("CompareTo", ts1.compareTo(ts2) < 0); - assertTrue("CompareTo", ts1.compareTo(ts3) < 0); - assertTrue("CompareTo", ts1.compareTo(ts4) < 0); + assertTrue("CompareTo", t1.compareTo(t2) < 0); + assertTrue("CompareTo", t1.compareTo(t3) < 0); + assertTrue("CompareTo", t1.compareTo(t4) < 0); - assertTrue("CompareTo", ts2.compareTo(ts1) > 0); - assertTrue("CompareTo", ts2.compareTo(ts3) < 0); - assertTrue("CompareTo", ts2.compareTo(ts4) == 0); + assertTrue("CompareTo", t2.compareTo(t1) > 0); + assertTrue("CompareTo", t2.compareTo(t3) < 0); + assertTrue("CompareTo", t2.compareTo(t4) == 0); - assertTrue("CompareTo", ts3.compareTo(ts1) > 0); - assertTrue("CompareTo", ts3.compareTo(ts2) > 0); - assertTrue("CompareTo", ts3.compareTo(ts4) > 0); + assertTrue("CompareTo", t3.compareTo(t1) > 0); + assertTrue("CompareTo", t3.compareTo(t2) > 0); + assertTrue("CompareTo", t3.compareTo(t4) > 0); } - /** - * - */ + @Test public void testCompareToCornerCases1() { final ITmfTimestamp ts0a = new TmfTimestamp(ts0); final ITmfTimestamp ts0b = new TmfTimestamp(ts0.getValue(), ts0.getScale() + 1); @@ -504,9 +433,7 @@ public class TmfTimestampTest extends TestCase { assertTrue("compareTo", ts0.compareTo(ts0d, false) == -1); } - /** - * - */ + @Test public void testCompareToCornerCases2() { final ITmfTimestamp ts0a = new TmfTimestamp(Long.MAX_VALUE, Integer.MAX_VALUE - 1); final ITmfTimestamp ts0b = new TmfTimestamp(0, Integer.MAX_VALUE); @@ -522,9 +449,7 @@ public class TmfTimestampTest extends TestCase { assertTrue("compareTo", ts0c.compareTo(ts0b, false) == 1); } - /** - * - */ + @Test public void testCompareToCornerCases3() { final ITmfTimestamp ts0a = new TmfTimestamp(Long.MIN_VALUE, Integer.MAX_VALUE - 1); final ITmfTimestamp ts0b = new TmfTimestamp(0, Integer.MAX_VALUE); @@ -540,119 +465,103 @@ public class TmfTimestampTest extends TestCase { assertTrue("compareTo", ts0c.compareTo(ts0b, false) == -1); } - /** - * - */ + @Test public void testCompareToCornerCases4() { assertTrue("compareTo", ts0.compareTo(null, false) == 1); assertTrue("compareTo", ts0.compareTo(null, true) == 1); } - /** - * - */ - @SuppressWarnings("hiding") + @Test public void testCompareToSameScale() { - final ITmfTimestamp ts1 = new TmfTimestamp(900, 0, 50); - final ITmfTimestamp ts2 = new TmfTimestamp(1000, 0, 50); - final ITmfTimestamp ts3 = new TmfTimestamp(1100, 0, 50); - final ITmfTimestamp ts4 = new TmfTimestamp(1000, 0, 75); + final ITmfTimestamp t1 = new TmfTimestamp(900, 0, 50); + final ITmfTimestamp t2 = new TmfTimestamp(1000, 0, 50); + final ITmfTimestamp t3 = new TmfTimestamp(1100, 0, 50); + final ITmfTimestamp t4 = new TmfTimestamp(1000, 0, 75); - assertTrue(ts1.compareTo(ts1, false) == 0); + assertTrue(t1.compareTo(t1, false) == 0); - assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0); - assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0); - assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0); + assertTrue("CompareTo", t1.compareTo(t2, false) < 0); + assertTrue("CompareTo", t1.compareTo(t3, false) < 0); + assertTrue("CompareTo", t1.compareTo(t4, false) < 0); - assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0); - assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0); - assertTrue("CompareTo", ts2.compareTo(ts4, false) == 0); + assertTrue("CompareTo", t2.compareTo(t1, false) > 0); + assertTrue("CompareTo", t2.compareTo(t3, false) < 0); + assertTrue("CompareTo", t2.compareTo(t4, false) == 0); - assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0); - assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0); - assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0); + assertTrue("CompareTo", t3.compareTo(t1, false) > 0); + assertTrue("CompareTo", t3.compareTo(t2, false) > 0); + assertTrue("CompareTo", t3.compareTo(t4, false) > 0); } - /** - * - */ - @SuppressWarnings("hiding") + @Test public void testCompareToDifferentScale() { - final ITmfTimestamp ts1 = new TmfTimestamp(9000, -1, 50); - final ITmfTimestamp ts2 = new TmfTimestamp(1000, 0, 50); - final ITmfTimestamp ts3 = new TmfTimestamp(110, 1, 50); - final ITmfTimestamp ts4 = new TmfTimestamp(1, 3, 75); + final ITmfTimestamp t1 = new TmfTimestamp(9000, -1, 50); + final ITmfTimestamp t2 = new TmfTimestamp(1000, 0, 50); + final ITmfTimestamp t3 = new TmfTimestamp(110, 1, 50); + final ITmfTimestamp t4 = new TmfTimestamp(1, 3, 75); - assertTrue("CompareTo", ts1.compareTo(ts1, false) == 0); + assertTrue("CompareTo", t1.compareTo(t1, false) == 0); - assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0); - assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0); - assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0); + assertTrue("CompareTo", t1.compareTo(t2, false) < 0); + assertTrue("CompareTo", t1.compareTo(t3, false) < 0); + assertTrue("CompareTo", t1.compareTo(t4, false) < 0); - assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0); - assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0); - assertTrue("CompareTo", ts2.compareTo(ts4, false) == 0); + assertTrue("CompareTo", t2.compareTo(t1, false) > 0); + assertTrue("CompareTo", t2.compareTo(t3, false) < 0); + assertTrue("CompareTo", t2.compareTo(t4, false) == 0); - assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0); - assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0); - assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0); + assertTrue("CompareTo", t3.compareTo(t1, false) > 0); + assertTrue("CompareTo", t3.compareTo(t2, false) > 0); + assertTrue("CompareTo", t3.compareTo(t4, false) > 0); } - /** - * - */ - @SuppressWarnings("hiding") + @Test public void testCompareToWithinPrecision() { - final ITmfTimestamp ts1 = new TmfTimestamp(900, 0, 50); - final ITmfTimestamp ts2 = new TmfTimestamp(1000, 0, 50); - final ITmfTimestamp ts3 = new TmfTimestamp(1100, 0, 50); - final ITmfTimestamp ts4 = new TmfTimestamp(1000, 0, 75); + final ITmfTimestamp t1 = new TmfTimestamp(900, 0, 50); + final ITmfTimestamp t2 = new TmfTimestamp(1000, 0, 50); + final ITmfTimestamp t3 = new TmfTimestamp(1100, 0, 50); + final ITmfTimestamp t4 = new TmfTimestamp(1000, 0, 75); - assertTrue("CompareTo", ts1.compareTo(ts1, true) == 0); + assertTrue("CompareTo", t1.compareTo(t1, true) == 0); - assertTrue("CompareTo", ts1.compareTo(ts2, true) == 0); - assertTrue("CompareTo", ts1.compareTo(ts3, true) < 0); - assertTrue("CompareTo", ts1.compareTo(ts4, true) == 0); + assertTrue("CompareTo", t1.compareTo(t2, true) == 0); + assertTrue("CompareTo", t1.compareTo(t3, true) < 0); + assertTrue("CompareTo", t1.compareTo(t4, true) == 0); - assertTrue("CompareTo", ts2.compareTo(ts1, true) == 0); - assertTrue("CompareTo", ts2.compareTo(ts3, true) == 0); - assertTrue("CompareTo", ts2.compareTo(ts4, true) == 0); + assertTrue("CompareTo", t2.compareTo(t1, true) == 0); + assertTrue("CompareTo", t2.compareTo(t3, true) == 0); + assertTrue("CompareTo", t2.compareTo(t4, true) == 0); - assertTrue("CompareTo", ts3.compareTo(ts1, true) > 0); - assertTrue("CompareTo", ts3.compareTo(ts2, true) == 0); - assertTrue("CompareTo", ts3.compareTo(ts4, true) == 0); + assertTrue("CompareTo", t3.compareTo(t1, true) > 0); + assertTrue("CompareTo", t3.compareTo(t2, true) == 0); + assertTrue("CompareTo", t3.compareTo(t4, true) == 0); } - /** - * - */ - @SuppressWarnings("hiding") + @Test public void testCompareToLargeScale1() { - final ITmfTimestamp ts1 = new TmfTimestamp(-1, 100); - final ITmfTimestamp ts2 = new TmfTimestamp(-1000, -100); - final ITmfTimestamp ts3 = new TmfTimestamp(1, 100); - final ITmfTimestamp ts4 = new TmfTimestamp(1000, -100); + final ITmfTimestamp t1 = new TmfTimestamp(-1, 100); + final ITmfTimestamp t2 = new TmfTimestamp(-1000, -100); + final ITmfTimestamp t3 = new TmfTimestamp(1, 100); + final ITmfTimestamp t4 = new TmfTimestamp(1000, -100); - assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0); - assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0); - assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0); + assertTrue("CompareTo", t1.compareTo(t2, false) < 0); + assertTrue("CompareTo", t1.compareTo(t3, false) < 0); + assertTrue("CompareTo", t1.compareTo(t4, false) < 0); - assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0); - assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0); - assertTrue("CompareTo", ts2.compareTo(ts4, false) < 0); + assertTrue("CompareTo", t2.compareTo(t1, false) > 0); + assertTrue("CompareTo", t2.compareTo(t3, false) < 0); + assertTrue("CompareTo", t2.compareTo(t4, false) < 0); - assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0); - assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0); - assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0); + assertTrue("CompareTo", t3.compareTo(t1, false) > 0); + assertTrue("CompareTo", t3.compareTo(t2, false) > 0); + assertTrue("CompareTo", t3.compareTo(t4, false) > 0); - assertTrue("CompareTo", ts4.compareTo(ts1, false) > 0); - assertTrue("CompareTo", ts4.compareTo(ts2, false) > 0); - assertTrue("CompareTo", ts4.compareTo(ts3, false) < 0); + assertTrue("CompareTo", t4.compareTo(t1, false) > 0); + assertTrue("CompareTo", t4.compareTo(t2, false) > 0); + assertTrue("CompareTo", t4.compareTo(t3, false) < 0); } - /** - * - */ + @Test public void testCompareToLargeScale2() { final ITmfTimestamp ts0a = new TmfTimestamp(0, Integer.MAX_VALUE); final ITmfTimestamp ts0b = new TmfTimestamp(1, Integer.MAX_VALUE); @@ -668,74 +577,71 @@ public class TmfTimestampTest extends TestCase { // getDelta // ------------------------------------------------------------------------ - /** - * - */ - @SuppressWarnings("hiding") + @Test public void testDelta() { // Delta for same scale and precision (delta > 0) - ITmfTimestamp ts0 = new TmfTimestamp(10, 9); - ITmfTimestamp ts1 = new TmfTimestamp(5, 9); + ITmfTimestamp t0 = new TmfTimestamp(10, 9); + ITmfTimestamp t1 = new TmfTimestamp(5, 9); ITmfTimestamp exp = new TmfTimestamp(5, 9); - ITmfTimestamp delta = ts0.getDelta(ts1); + ITmfTimestamp delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, false)); // Delta for same scale and precision (delta < 0) - ts0 = new TmfTimestamp(5, 9); - ts1 = new TmfTimestamp(10, 9); + t0 = new TmfTimestamp(5, 9); + t1 = new TmfTimestamp(10, 9); exp = new TmfTimestamp(-5, 9); - delta = ts0.getDelta(ts1); + delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, false)); // Delta for different scale and same precision (delta > 0) - ts0 = new TmfTimestamp(5, 9); - ts1 = new TmfTimestamp(10, 8); + t0 = new TmfTimestamp(5, 9); + t1 = new TmfTimestamp(10, 8); exp = new TmfTimestamp(4, 9); - delta = ts0.getDelta(ts1); + delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, false)); // Delta for different scale and same precision (delta > 0) - ts0 = new TmfTimestamp(5, 9); - ts1 = new TmfTimestamp(10, 7); + t0 = new TmfTimestamp(5, 9); + t1 = new TmfTimestamp(10, 7); exp = new TmfTimestamp(5, 9); - delta = ts0.getDelta(ts1); + delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, false)); // Delta for different scale and same precision - ts0 = new TmfTimestamp(10, 9); - ts1 = new TmfTimestamp(5, 8); + t0 = new TmfTimestamp(10, 9); + t1 = new TmfTimestamp(5, 8); exp = new TmfTimestamp(10, 9); - delta = ts0.getDelta(ts1); + delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, false)); // Delta for same scale and different precision - ts0 = new TmfTimestamp(10, 9, 1); - ts1 = new TmfTimestamp(5, 9, 2); + t0 = new TmfTimestamp(10, 9, 1); + t1 = new TmfTimestamp(5, 9, 2); exp = new TmfTimestamp(5, 9, 3); - delta = ts0.getDelta(ts1); + delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, true)); assertEquals("precision", 3, delta.getPrecision()); // Delta for same scale and different precision - ts0 = new TmfTimestamp(5, 9, 2); - ts1 = new TmfTimestamp(10, 9, 1); + t0 = new TmfTimestamp(5, 9, 2); + t1 = new TmfTimestamp(10, 9, 1); exp = new TmfTimestamp(-5, 9, 3); - delta = ts0.getDelta(ts1); + delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, true)); assertEquals("precision", 3, delta.getPrecision()); // Delta for different scale and different precision - ts0 = new TmfTimestamp(5, 9, 2); - ts1 = new TmfTimestamp(10, 8, 1); + t0 = new TmfTimestamp(5, 9, 2); + t1 = new TmfTimestamp(10, 8, 1); exp = new TmfTimestamp(4, 9, 3); - delta = ts0.getDelta(ts1); + delta = t0.getDelta(t1); assertEquals("getDelta", 0, delta.compareTo(exp, true)); assertEquals("precision", 2, delta.getPrecision()); } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/AllTests.java index e6d2e3561d..44ecb49c27 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/AllTests.java @@ -1,32 +1,32 @@ -package org.eclipse.linuxtools.tmf.core.tests.request; +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 + *******************************************************************************/ -import junit.framework.Test; -import junit.framework.TestSuite; +package org.eclipse.linuxtools.tmf.core.tests.request; -import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** - * AllTests - *

- * Implement me. Please. - *

+ * Requests tests */ -@SuppressWarnings({ "nls" }) +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TmfCoalescedDataRequestTest.class, + TmfCoalescedEventRequestTest.class, + TmfDataRequestTest.class, + TmfEventRequestTest.class, + TmfRequestExecutorTest.class +}) public class AllTests { - /** - * @return the test suite - */ - public static Test suite() { - TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".request"); //$NON-NLS-1$); - //$JUnit-BEGIN$ - suite.addTestSuite(TmfDataRequestTest.class); - suite.addTestSuite(TmfEventRequestTest.class); - suite.addTestSuite(TmfCoalescedDataRequestTest.class); - suite.addTestSuite(TmfCoalescedEventRequestTest.class); - suite.addTestSuite(TmfRequestExecutorTest.class); - //$JUnit-END$ - return suite; - } - } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedDataRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedDataRequestTest.java index cd944d7d9a..fa465f4d7f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedDataRequestTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedDataRequestTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,104 +9,100 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Added tests to check offsets + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.request; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedDataRequest; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfDataRequestStub; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfCoalescedDataRequest class. */ -@SuppressWarnings({"nls","javadoc"}) -public class TmfCoalescedDataRequestTest extends TestCase { - - // ------------------------------------------------------------------------ - // Variables - // ------------------------------------------------------------------------ - - private TmfCoalescedDataRequest fRequest1; - private TmfCoalescedDataRequest fRequest2; - private TmfCoalescedDataRequest fRequest3; - private TmfCoalescedDataRequest fRequest4; - - private TmfCoalescedDataRequest fRequest1b; - private TmfCoalescedDataRequest fRequest1c; - - private int fRequestCount; - - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfCoalescedDataRequestTest(final String name) { - super(name); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - TmfDataRequest.reset(); - fRequest1 = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); - fRequest2 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 100, 200); - fRequest3 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 200); - fRequest4 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 300); - - fRequest1b = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); - fRequest1c = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); - - fRequestCount = fRequest1c.getRequestId() + 1; - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - - private static TmfCoalescedDataRequest setupTestRequest(final boolean[] flags) { - - TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200) { - @Override - public void handleCompleted() { - super.handleCompleted(); - flags[0] = true; - } - @Override - public void handleSuccess() { - super.handleSuccess(); - flags[1] = true; - } - @Override - public void handleFailure() { - super.handleFailure(); - flags[2] = true; - } - @Override - public void handleCancel() { - super.handleCancel(); - flags[3] = true; - } - }; - return request; - } - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - public void testTmfCoalescedDataRequest() { - TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class); +@SuppressWarnings({ "nls", "javadoc" }) +public class TmfCoalescedDataRequestTest { + + // ------------------------------------------------------------------------ + // Variables + // ------------------------------------------------------------------------ + + private TmfCoalescedDataRequest fRequest1; + private TmfCoalescedDataRequest fRequest2; + private TmfCoalescedDataRequest fRequest3; + private TmfCoalescedDataRequest fRequest4; + + private TmfCoalescedDataRequest fRequest1b; + private TmfCoalescedDataRequest fRequest1c; + + private int fRequestCount; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + @Before + public void setUp() { + TmfDataRequest.reset(); + fRequest1 = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); + fRequest2 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 100, 200); + fRequest3 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 200); + fRequest4 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 300); + + fRequest1b = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); + fRequest1c = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); + + fRequestCount = fRequest1c.getRequestId() + 1; + } + + private static TmfCoalescedDataRequest setupTestRequest(final boolean[] flags) { + + TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200) { + @Override + public void handleCompleted() { + super.handleCompleted(); + flags[0] = true; + } + + @Override + public void handleSuccess() { + super.handleSuccess(); + flags[1] = true; + } + + @Override + public void handleFailure() { + super.handleFailure(); + flags[2] = true; + } + + @Override + public void handleCancel() { + super.handleCancel(); + flags[3] = true; + } + }; + return request; + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + @Test + public void testTmfCoalescedDataRequest() { + TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 0, request.getIndex()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -116,13 +112,14 @@ public class TmfCoalescedDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfCoalescedDataRequestIndex() { - TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10); + @Test + public void testTmfCoalescedDataRequestIndex() { + TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 10, request.getIndex()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -132,13 +129,14 @@ public class TmfCoalescedDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfCoalescedDataRequestIndexNbRequested() { - TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100); + @Test + public void testTmfCoalescedDataRequestIndexNbRequested() { + TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 10, request.getIndex()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -148,13 +146,14 @@ public class TmfCoalescedDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfCoalescedDataRequestIndexNbEventsBlocksize() { - TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); + @Test + public void testTmfCoalescedDataRequestIndexNbEventsBlocksize() { + TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 10, request.getIndex()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -164,21 +163,23 @@ public class TmfCoalescedDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - // ------------------------------------------------------------------------ - // equals - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ - public void testEqualsReflexivity() { + @Test + public void testEqualsReflexivity() { assertTrue("equals", fRequest1.equals(fRequest1)); assertTrue("equals", fRequest2.equals(fRequest2)); assertFalse("equals", fRequest1.equals(fRequest2)); assertFalse("equals", fRequest2.equals(fRequest1)); - } + } - public void testEqualsSymmetry() { + @Test + public void testEqualsSymmetry() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1)); @@ -186,34 +187,38 @@ public class TmfCoalescedDataRequestTest extends TestCase { assertFalse("equals", fRequest2.equals(fRequest3)); assertFalse("equals", fRequest3.equals(fRequest1)); assertFalse("equals", fRequest3.equals(fRequest2)); - } + } - public void testEqualsTransivity() { + @Test + public void testEqualsTransivity() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1c)); assertTrue("equals", fRequest1.equals(fRequest1c)); - } + } - public void testEqualsNull() { + @Test + public void testEqualsNull() { assertFalse("equals", fRequest1.equals(null)); assertFalse("equals", fRequest2.equals(null)); - } + } - // ------------------------------------------------------------------------ - // hashCode - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ - public void testHashCode() { + @Test + public void testHashCode() { assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode()); assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode()); - assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); - } + assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); + } - // ------------------------------------------------------------------------ - // toString - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // toString + // ------------------------------------------------------------------------ - public void testToString() { + @Test + public void testToString() { String expected1 = "[TmfCoalescedDataRequest(0,ITmfEvent,10,100,200)]"; String expected2 = "[TmfCoalescedDataRequest(1,ITmfEvent,20,100,200)]"; String expected3 = "[TmfCoalescedDataRequest(2,ITmfEvent,20,200,200)]"; @@ -229,13 +234,14 @@ public class TmfCoalescedDataRequestTest extends TestCase { // isCompatible // ------------------------------------------------------------------------ + @Test public void testIsCompatible() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); - TmfDataRequest request1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - TmfDataRequest request2 = new TmfDataRequestStub(ITmfEvent.class, 5, 100, 200); - TmfDataRequest request3 = new TmfDataRequestStub(ITmfEvent.class, 5, 4, 200); - TmfDataRequest request4 = new TmfDataRequestStub(ITmfEvent.class, 5, 5, 200); - TmfDataRequest request5 = new TmfDataRequestStub(ITmfEvent.class, 15, 100, 200); + TmfDataRequest request1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + TmfDataRequest request2 = new TmfDataRequestStub(ITmfEvent.class, 5, 100, 200); + TmfDataRequest request3 = new TmfDataRequestStub(ITmfEvent.class, 5, 4, 200); + TmfDataRequest request4 = new TmfDataRequestStub(ITmfEvent.class, 5, 5, 200); + TmfDataRequest request5 = new TmfDataRequestStub(ITmfEvent.class, 15, 100, 200); TmfDataRequest request6 = new TmfDataRequestStub(ITmfEvent.class, 100, 100, 200); TmfDataRequest request7 = new TmfDataRequestStub(ITmfEvent.class, 110, 100, 200); TmfDataRequest request8 = new TmfDataRequestStub(ITmfEvent.class, 111, 100, 200); @@ -260,100 +266,108 @@ public class TmfCoalescedDataRequestTest extends TestCase { // addRequest // ------------------------------------------------------------------------ + @Test public void testAddRequest1() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 10, coalescedRequest.getIndex()); + assertEquals("addRequest", 10, coalescedRequest.getIndex()); assertEquals("addRequest", 100, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } + @Test public void testAddRequest2() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 100, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 5, coalescedRequest.getIndex()); + assertEquals("addRequest", 5, coalescedRequest.getIndex()); assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } + @Test public void testAddRequest3() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 4, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 5, coalescedRequest.getIndex()); + assertEquals("addRequest", 5, coalescedRequest.getIndex()); assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } + @Test public void testAddRequest4() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 5, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 5, coalescedRequest.getIndex()); + assertEquals("addRequest", 5, coalescedRequest.getIndex()); assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } + @Test public void testAddRequest5() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 15, 100, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 10, coalescedRequest.getIndex()); + assertEquals("addRequest", 10, coalescedRequest.getIndex()); assertEquals("addRequest", 105, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } + @Test public void testAddRequest6() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 100, 100, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 10, coalescedRequest.getIndex()); + assertEquals("addRequest", 10, coalescedRequest.getIndex()); assertEquals("addRequest", 190, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } + @Test public void testAddRequest7() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 110, 100, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 10, coalescedRequest.getIndex()); + assertEquals("addRequest", 10, coalescedRequest.getIndex()); assertEquals("addRequest", 200, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } + @Test public void testAddRequest8() { TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200); TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 111, 100, 200); assertTrue("isCompatible", coalescedRequest.isCompatible(request)); coalescedRequest.addRequest(request); - assertEquals("addRequest", 10, coalescedRequest.getIndex()); + assertEquals("addRequest", 10, coalescedRequest.getIndex()); assertEquals("addRequest", 201, coalescedRequest.getNbRequested()); assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } - // ------------------------------------------------------------------------ - // done + // ------------------------------------------------------------------------ + // done // ------------------------------------------------------------------------ + @Test public void testDone() { - // Test request final boolean[] crFlags = new boolean[4]; TmfCoalescedDataRequest request = setupTestRequest(crFlags); @@ -362,108 +376,107 @@ public class TmfCoalescedDataRequestTest extends TestCase { request.addRequest(subRequest1); request.addRequest(subRequest2); - request.done(); - - // Validate the coalescing request - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); - - assertTrue ("handleCompleted", crFlags[0]); - assertTrue ("handleSuccess", crFlags[1]); - assertFalse("handleFailure", crFlags[2]); - assertFalse("handleCancel", crFlags[3]); - - // Validate the first coalesced request - assertTrue ("isCompleted", subRequest1.isCompleted()); - assertFalse("isFailed", subRequest1.isFailed()); - assertFalse("isCancelled", subRequest1.isCancelled()); - - // Validate the second coalesced request - assertTrue ("isCompleted", subRequest2.isCompleted()); - assertFalse("isFailed", subRequest2.isFailed()); - assertFalse("isCancelled", subRequest2.isCancelled()); - } - - // ------------------------------------------------------------------------ - // fail - // ------------------------------------------------------------------------ - - public void testFail() { - - final boolean[] crFlags = new boolean[4]; - TmfCoalescedDataRequest request = setupTestRequest(crFlags); - TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - request.addRequest(subRequest1); - request.addRequest(subRequest2); - - request.fail(); - - // Validate the coalescing request - assertTrue ("isCompleted", request.isCompleted()); - assertTrue ("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); - - assertTrue ("handleCompleted", crFlags[0]); - assertFalse("handleSuccess", crFlags[1]); - assertTrue ("handleFailure", crFlags[2]); - assertFalse("handleCancel", crFlags[3]); - - // Validate the first coalesced request - assertTrue ("isCompleted", subRequest1.isCompleted()); - assertTrue ("isFailed", subRequest1.isFailed()); - assertFalse("isCancelled", subRequest1.isCancelled()); - - // Validate the second coalesced request - assertTrue ("isCompleted", subRequest2.isCompleted()); - assertTrue ("isFailed", subRequest2.isFailed()); - assertFalse("isCancelled", subRequest2.isCancelled()); - } - - // ------------------------------------------------------------------------ - // cancel - // ------------------------------------------------------------------------ - - public void testCancel() { - - final boolean[] crFlags = new boolean[4]; - TmfCoalescedDataRequest request = setupTestRequest(crFlags); - TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - request.addRequest(subRequest1); - request.addRequest(subRequest2); - - request.cancel(); - - // Validate the coalescing request - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertTrue ("isCancelled", request.isCancelled()); - - assertTrue ("handleCompleted", crFlags[0]); - assertFalse("handleSuccess", crFlags[1]); - assertFalse("handleFailure", crFlags[2]); - assertTrue ("handleCancel", crFlags[3]); - - // Validate the first coalesced request - assertTrue ("isCompleted", subRequest1.isCompleted()); - assertFalse("isFailed", subRequest1.isFailed()); - assertTrue ("isCancelled", subRequest1.isCancelled()); - - // Validate the second coalesced request - assertTrue ("isCompleted", subRequest2.isCompleted()); - assertFalse("isFailed", subRequest2.isFailed()); - assertTrue ("isCancelled", subRequest2.isCancelled()); - } - - - // ------------------------------------------------------------------------ - // cancel sub-requests - // ------------------------------------------------------------------------ + request.done(); - public void testCancelSubRequests() { + // Validate the coalescing request + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); + + assertTrue("handleCompleted", crFlags[0]); + assertTrue("handleSuccess", crFlags[1]); + assertFalse("handleFailure", crFlags[2]); + assertFalse("handleCancel", crFlags[3]); + + // Validate the first coalesced request + assertTrue("isCompleted", subRequest1.isCompleted()); + assertFalse("isFailed", subRequest1.isFailed()); + assertFalse("isCancelled", subRequest1.isCancelled()); + + // Validate the second coalesced request + assertTrue("isCompleted", subRequest2.isCompleted()); + assertFalse("isFailed", subRequest2.isFailed()); + assertFalse("isCancelled", subRequest2.isCancelled()); + } + + // ------------------------------------------------------------------------ + // fail + // ------------------------------------------------------------------------ + @Test + public void testFail() { + final boolean[] crFlags = new boolean[4]; + TmfCoalescedDataRequest request = setupTestRequest(crFlags); + TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + request.addRequest(subRequest1); + request.addRequest(subRequest2); + + request.fail(); + + // Validate the coalescing request + assertTrue("isCompleted", request.isCompleted()); + assertTrue("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); + + assertTrue("handleCompleted", crFlags[0]); + assertFalse("handleSuccess", crFlags[1]); + assertTrue("handleFailure", crFlags[2]); + assertFalse("handleCancel", crFlags[3]); + + // Validate the first coalesced request + assertTrue("isCompleted", subRequest1.isCompleted()); + assertTrue("isFailed", subRequest1.isFailed()); + assertFalse("isCancelled", subRequest1.isCancelled()); + + // Validate the second coalesced request + assertTrue("isCompleted", subRequest2.isCompleted()); + assertTrue("isFailed", subRequest2.isFailed()); + assertFalse("isCancelled", subRequest2.isCancelled()); + } + + // ------------------------------------------------------------------------ + // cancel + // ------------------------------------------------------------------------ + + @Test + public void testCancel() { + final boolean[] crFlags = new boolean[4]; + TmfCoalescedDataRequest request = setupTestRequest(crFlags); + TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + TmfDataRequest subRequest2 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + request.addRequest(subRequest1); + request.addRequest(subRequest2); + + request.cancel(); + + // Validate the coalescing request + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertTrue("isCancelled", request.isCancelled()); + + assertTrue("handleCompleted", crFlags[0]); + assertFalse("handleSuccess", crFlags[1]); + assertFalse("handleFailure", crFlags[2]); + assertTrue("handleCancel", crFlags[3]); + + // Validate the first coalesced request + assertTrue("isCompleted", subRequest1.isCompleted()); + assertFalse("isFailed", subRequest1.isFailed()); + assertTrue("isCancelled", subRequest1.isCancelled()); + + // Validate the second coalesced request + assertTrue("isCompleted", subRequest2.isCompleted()); + assertFalse("isFailed", subRequest2.isFailed()); + assertTrue("isCancelled", subRequest2.isCancelled()); + } + + // ------------------------------------------------------------------------ + // cancel sub-requests + // ------------------------------------------------------------------------ + + @Test + public void testCancelSubRequests() { final boolean[] crFlags = new boolean[4]; TmfCoalescedDataRequest request = setupTestRequest(crFlags); TmfDataRequest subRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); @@ -480,7 +493,7 @@ public class TmfCoalescedDataRequestTest extends TestCase { // Validate the coalescing request assertFalse("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); + assertFalse("isFailed", request.isFailed()); assertFalse("isCancelled", request.isCancelled()); // Cancel second sub-request diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java index d6f0a890ac..e656b0a441 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfCoalescedEventRequestTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,18 +8,21 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.request; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.Vector; -import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager; @@ -39,99 +42,90 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfEventRequestStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.Before; +import org.junit.Test; /** - * TmfCoalescedEventRequestTest - *

* Test suite for the TmfCoalescedEventRequest class. */ -@SuppressWarnings({"nls","javadoc"}) -public class TmfCoalescedEventRequestTest extends TestCase { - - // ------------------------------------------------------------------------ - // Variables - // ------------------------------------------------------------------------ - - private final TmfTimeRange range1 = new TmfTimeRange(TmfTimeRange.ETERNITY); - private final TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH); - - private TmfCoalescedEventRequest fRequest1; - private TmfCoalescedEventRequest fRequest2; - private TmfCoalescedEventRequest fRequest3; - private TmfCoalescedEventRequest fRequest4; - - private TmfCoalescedEventRequest fRequest1b; - private TmfCoalescedEventRequest fRequest1c; - - private int fRequestCount; - - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfCoalescedEventRequestTest(String name) { - super(name); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - TmfDataRequest.reset(); - fRequest1 = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); - fRequest2 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 100, 200); - fRequest3 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 200, 200); - fRequest4 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 200, 300); - - fRequest1b = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); - fRequest1c = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); - - fRequestCount = fRequest1c.getRequestId() + 1; - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - - private TmfCoalescedEventRequest setupTestRequest(final boolean[] flags) { - - TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200) { - @Override - public void handleCompleted() { - super.handleCompleted(); - flags[0] = true; - } - @Override - public void handleSuccess() { - super.handleSuccess(); - flags[1] = true; - } - @Override - public void handleFailure() { - super.handleFailure(); - flags[2] = true; - } - @Override - public void handleCancel() { - super.handleCancel(); - flags[3] = true; - } - }; - return request; - } - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - public void testTmfCoalescedEventRequest() { - TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class); +@SuppressWarnings({ "nls", "javadoc" }) +public class TmfCoalescedEventRequestTest { + + // ------------------------------------------------------------------------ + // Variables + // ------------------------------------------------------------------------ + + private final TmfTimeRange range1 = new TmfTimeRange(TmfTimeRange.ETERNITY); + private final TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH); + + private TmfCoalescedEventRequest fRequest1; + private TmfCoalescedEventRequest fRequest2; + private TmfCoalescedEventRequest fRequest3; + private TmfCoalescedEventRequest fRequest4; + + private TmfCoalescedEventRequest fRequest1b; + private TmfCoalescedEventRequest fRequest1c; + + private int fRequestCount; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + @Before + public void setUp() { + TmfDataRequest.reset(); + fRequest1 = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); + fRequest2 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 100, 200); + fRequest3 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 200, 200); + fRequest4 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 200, 300); + + fRequest1b = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); + fRequest1c = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); + + fRequestCount = fRequest1c.getRequestId() + 1; + } + + private TmfCoalescedEventRequest setupTestRequest(final boolean[] flags) { + + TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200) { + @Override + public void handleCompleted() { + super.handleCompleted(); + flags[0] = true; + } + + @Override + public void handleSuccess() { + super.handleSuccess(); + flags[1] = true; + } + + @Override + public void handleFailure() { + super.handleFailure(); + flags[2] = true; + } + + @Override + public void handleCancel() { + super.handleCancel(); + flags[3] = true; + } + }; + return request; + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + @Test + public void testTmfCoalescedEventRequest() { + TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getRange", range1, request.getRange()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -141,13 +135,14 @@ public class TmfCoalescedEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfCoalescedEventRequestIndex() { - TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1); + @Test + public void testTmfCoalescedEventRequestIndex() { + TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getRange", range1, request.getRange()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -157,13 +152,13 @@ public class TmfCoalescedEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfCoalescedEventRequestIndexNbRequested() { - TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100); + public void testTmfCoalescedEventRequestIndexNbRequested() { + TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getRange", range1, request.getRange()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -173,13 +168,14 @@ public class TmfCoalescedEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfCoalescedEventRequestIndexNbEventsBlocksize() { - TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); + @Test + public void testTmfCoalescedEventRequestIndexNbEventsBlocksize() { + TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getRange", range1, request.getRange()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -189,21 +185,23 @@ public class TmfCoalescedEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - // ------------------------------------------------------------------------ - // equals - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ - public void testEqualsReflexivity() { + @Test + public void testEqualsReflexivity() { assertTrue("equals", fRequest1.equals(fRequest1)); assertTrue("equals", fRequest2.equals(fRequest2)); assertFalse("equals", fRequest1.equals(fRequest2)); assertFalse("equals", fRequest2.equals(fRequest1)); - } + } - public void testEqualsSymmetry() { + @Test + public void testEqualsSymmetry() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1)); @@ -211,48 +209,53 @@ public class TmfCoalescedEventRequestTest extends TestCase { assertFalse("equals", fRequest2.equals(fRequest3)); assertFalse("equals", fRequest3.equals(fRequest1)); assertFalse("equals", fRequest3.equals(fRequest2)); - } + } - public void testEqualsTransivity() { + @Test + public void testEqualsTransivity() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1c)); assertTrue("equals", fRequest1.equals(fRequest1c)); - } + } - public void testEqualsNull() { + @Test + public void testEqualsNull() { assertFalse("equals", fRequest1.equals(null)); assertFalse("equals", fRequest2.equals(null)); - } + } - public void testEqualsSuper() { - TmfCoalescedDataRequest dataRequest1 = new TmfCoalescedDataRequest( - fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested()); - TmfCoalescedDataRequest dataRequest2 = new TmfCoalescedDataRequest( - fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested()); - TmfCoalescedDataRequest dataRequest3 = new TmfCoalescedDataRequest( - fRequest3.getDataType(), fRequest3.getIndex(), fRequest3.getNbRequested()); + @Test + public void testEqualsSuper() { + TmfCoalescedDataRequest dataRequest1 = new TmfCoalescedDataRequest( + fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested()); + TmfCoalescedDataRequest dataRequest2 = new TmfCoalescedDataRequest( + fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested()); + TmfCoalescedDataRequest dataRequest3 = new TmfCoalescedDataRequest( + fRequest3.getDataType(), fRequest3.getIndex(), fRequest3.getNbRequested()); - assertTrue("equals", fRequest1.equals(dataRequest2)); + assertTrue("equals", fRequest1.equals(dataRequest2)); assertTrue("equals", fRequest2.equals(dataRequest1)); assertFalse("equals", fRequest1.equals(dataRequest3)); assertFalse("equals", fRequest3.equals(dataRequest1)); - } + } - // ------------------------------------------------------------------------ - // hashCode - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ - public void testHashCode() { + @Test + public void testHashCode() { assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode()); assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode()); - assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); - } + assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); + } - // ------------------------------------------------------------------------ - // toString - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // toString + // ------------------------------------------------------------------------ - public void testToString() { + @Test + public void testToString() { String expected1 = "[TmfCoalescedEventRequest(0,ITmfEvent," + range1 + ",0,100,200)]"; String expected2 = "[TmfCoalescedEventRequest(1,ITmfEvent," + range2 + ",0,100,200)]"; String expected3 = "[TmfCoalescedEventRequest(2,ITmfEvent," + range2 + ",0,200,200)]"; @@ -262,202 +265,203 @@ public class TmfCoalescedEventRequestTest extends TestCase { assertEquals("toString", expected2, fRequest2.toString()); assertEquals("toString", expected3, fRequest3.toString()); assertEquals("toString", expected4, fRequest4.toString()); - } + } - // ------------------------------------------------------------------------ - // isCompatible - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // isCompatible + // ------------------------------------------------------------------------ - @SuppressWarnings("hiding") - public void testIsCompatible() { - TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); - TmfEventRequest request1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - TmfEventRequest request2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 200); - TmfEventRequest request3 = new TmfEventRequestStub(ITmfEvent.class, range1, 101, 200); + @Test + public void testIsCompatible() { + TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200); + TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 200); + TmfEventRequest req3 = new TmfEventRequestStub(ITmfEvent.class, range1, 101, 200); - assertTrue("isCompatible", coalescedRequest.isCompatible(request1)); - assertTrue("isCompatible", coalescedRequest.isCompatible(request2)); - assertTrue("isCompatible", coalescedRequest.isCompatible(request3)); - } + assertTrue("isCompatible", coalescedRequest.isCompatible(req1)); + assertTrue("isCompatible", coalescedRequest.isCompatible(req2)); + assertTrue("isCompatible", coalescedRequest.isCompatible(req3)); + } // ------------------------------------------------------------------------ // addEvent // ------------------------------------------------------------------------ - @SuppressWarnings("hiding") + @Test public void testAddEvent1() { TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 2147483647, 200, ExecutionType.FOREGROUND); - TmfEventRequest request1 = new TmfEventRequestStub(ITmfEvent.class, range1, 0, 2147483647, 200); - TmfEventRequest request2 = new TmfEventRequestStub(ITmfEvent.class, range1, 1, 2147483647, 200); + TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 0, 2147483647, 200); + TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range1, 1, 2147483647, 200); - assertTrue("isCompatible", coalescedRequest.isCompatible(request1)); - assertTrue("isCompatible", coalescedRequest.isCompatible(request2)); + assertTrue("isCompatible", coalescedRequest.isCompatible(req1)); + assertTrue("isCompatible", coalescedRequest.isCompatible(req2)); - coalescedRequest.addRequest(request1); - coalescedRequest.addRequest(request2); + coalescedRequest.addRequest(req1); + coalescedRequest.addRequest(req2); - assertEquals("addRequest", 0, coalescedRequest.getIndex()); + assertEquals("addRequest", 0, coalescedRequest.getIndex()); assertEquals("addRequest", 2147483647, coalescedRequest.getNbRequested()); - assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); + assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); } - @SuppressWarnings("hiding") + @Test public void testAddEvent2() { TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 1, 2147483647, 200, ExecutionType.FOREGROUND); - TmfEventRequest request1 = new TmfEventRequestStub(ITmfEvent.class, range1, 1, 2147483647, 200); - TmfEventRequest request2 = new TmfEventRequestStub(ITmfEvent.class, range1, 0, 2147483647, 200); + TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 1, 2147483647, 200); + TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range1, 0, 2147483647, 200); - assertTrue("isCompatible", coalescedRequest.isCompatible(request1)); - assertTrue("isCompatible", coalescedRequest.isCompatible(request2)); + assertTrue("isCompatible", coalescedRequest.isCompatible(req1)); + assertTrue("isCompatible", coalescedRequest.isCompatible(req2)); - coalescedRequest.addRequest(request1); - coalescedRequest.addRequest(request2); + coalescedRequest.addRequest(req1); + coalescedRequest.addRequest(req2); - assertEquals("addRequest", 0, coalescedRequest.getIndex()); + assertEquals("addRequest", 0, coalescedRequest.getIndex()); assertEquals("addRequest", 2147483647, coalescedRequest.getNbRequested()); - assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); + assertEquals("addRequest", 200, coalescedRequest.getBlockSize()); + + } + + // ------------------------------------------------------------------------ + // done + // ------------------------------------------------------------------------ + + @Test + public void testDone() { + // Test request + final boolean[] crFlags = new boolean[4]; + TmfCoalescedEventRequest request = setupTestRequest(crFlags); + TmfEventRequest subRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + TmfEventRequest subRequest2 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + request.addRequest(subRequest1); + request.addRequest(subRequest2); + + request.done(); + + // Validate the coalescing request + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); + + assertTrue("handleCompleted", crFlags[0]); + assertTrue("handleSuccess", crFlags[1]); + assertFalse("handleFailure", crFlags[2]); + assertFalse("handleCancel", crFlags[3]); + + // Validate the first coalesced request + assertTrue("isCompleted", subRequest1.isCompleted()); + assertFalse("isFailed", subRequest1.isFailed()); + assertFalse("isCancelled", subRequest1.isCancelled()); + + // Validate the second coalesced request + assertTrue("isCompleted", subRequest2.isCompleted()); + assertFalse("isFailed", subRequest2.isFailed()); + assertFalse("isCancelled", subRequest2.isCancelled()); + } + + // ------------------------------------------------------------------------ + // fail + // ------------------------------------------------------------------------ + + @Test + public void testFail() { + final boolean[] crFlags = new boolean[4]; + TmfCoalescedEventRequest request = setupTestRequest(crFlags); + TmfEventRequest subRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + TmfEventRequest subRequest2 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + request.addRequest(subRequest1); + request.addRequest(subRequest2); + + request.fail(); + + // Validate the coalescing request + assertTrue("isCompleted", request.isCompleted()); + assertTrue("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); + + assertTrue("handleCompleted", crFlags[0]); + assertFalse("handleSuccess", crFlags[1]); + assertTrue("handleFailure", crFlags[2]); + assertFalse("handleCancel", crFlags[3]); + + // Validate the first coalesced request + assertTrue("isCompleted", subRequest1.isCompleted()); + assertTrue("isFailed", subRequest1.isFailed()); + assertFalse("isCancelled", subRequest1.isCancelled()); + // Validate the second coalesced request + assertTrue("isCompleted", subRequest2.isCompleted()); + assertTrue("isFailed", subRequest2.isFailed()); + assertFalse("isCancelled", subRequest2.isCancelled()); } - // ------------------------------------------------------------------------ - // done - // ------------------------------------------------------------------------ - - public void testDone() { - - // Test request - final boolean[] crFlags = new boolean[4]; - TmfCoalescedEventRequest request = setupTestRequest(crFlags); - TmfEventRequest subRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - TmfEventRequest subRequest2 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - request.addRequest(subRequest1); - request.addRequest(subRequest2); - - request.done(); - - // Validate the coalescing request - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); - - assertTrue ("handleCompleted", crFlags[0]); - assertTrue ("handleSuccess", crFlags[1]); - assertFalse("handleFailure", crFlags[2]); - assertFalse("handleCancel", crFlags[3]); - - // Validate the first coalesced request - assertTrue ("isCompleted", subRequest1.isCompleted()); - assertFalse("isFailed", subRequest1.isFailed()); - assertFalse("isCancelled", subRequest1.isCancelled()); - - // Validate the second coalesced request - assertTrue ("isCompleted", subRequest2.isCompleted()); - assertFalse("isFailed", subRequest2.isFailed()); - assertFalse("isCancelled", subRequest2.isCancelled()); - } - - // ------------------------------------------------------------------------ - // fail - // ------------------------------------------------------------------------ - - public void testFail() { - - final boolean[] crFlags = new boolean[4]; - TmfCoalescedEventRequest request = setupTestRequest(crFlags); - TmfEventRequest subRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - TmfEventRequest subRequest2 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - request.addRequest(subRequest1); - request.addRequest(subRequest2); - - request.fail(); - - // Validate the coalescing request - assertTrue ("isCompleted", request.isCompleted()); - assertTrue ("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); - - assertTrue ("handleCompleted", crFlags[0]); - assertFalse("handleSuccess", crFlags[1]); - assertTrue ("handleFailure", crFlags[2]); - assertFalse("handleCancel", crFlags[3]); - - // Validate the first coalesced request - assertTrue ("isCompleted", subRequest1.isCompleted()); - assertTrue ("isFailed", subRequest1.isFailed()); - assertFalse("isCancelled", subRequest1.isCancelled()); - - // Validate the second coalesced request - assertTrue ("isCompleted", subRequest2.isCompleted()); - assertTrue ("isFailed", subRequest2.isFailed()); - assertFalse("isCancelled", subRequest2.isCancelled()); - } - - // ------------------------------------------------------------------------ - // cancel - // ------------------------------------------------------------------------ - - public void testCancel() { - - final boolean[] crFlags = new boolean[4]; - TmfCoalescedEventRequest request = setupTestRequest(crFlags); - TmfEventRequest subRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - TmfEventRequest subRequest2 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - request.addRequest(subRequest1); - request.addRequest(subRequest2); - - request.cancel(); - - // Validate the coalescing request - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertTrue ("isCancelled", request.isCancelled()); - - assertTrue ("handleCompleted", crFlags[0]); - assertFalse("handleSuccess", crFlags[1]); - assertFalse("handleFailure", crFlags[2]); - assertTrue ("handleCancel", crFlags[3]); - - // Validate the first coalesced request - assertTrue ("isCompleted", subRequest1.isCompleted()); - assertFalse("isFailed", subRequest1.isFailed()); - assertTrue ("isCancelled", subRequest1.isCancelled()); - - // Validate the second coalesced request - assertTrue ("isCompleted", subRequest2.isCompleted()); - assertFalse("isFailed", subRequest2.isFailed()); - assertTrue ("isCancelled", subRequest2.isCancelled()); - } - - // ------------------------------------------------------------------------ - // Coalescing - // ------------------------------------------------------------------------ - - private static final String DIRECTORY = "testfiles"; + // ------------------------------------------------------------------------ + // cancel + // ------------------------------------------------------------------------ + + @Test + public void testCancel() { + final boolean[] crFlags = new boolean[4]; + TmfCoalescedEventRequest request = setupTestRequest(crFlags); + TmfEventRequest subRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + TmfEventRequest subRequest2 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + request.addRequest(subRequest1); + request.addRequest(subRequest2); + + request.cancel(); + + // Validate the coalescing request + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertTrue("isCancelled", request.isCancelled()); + + assertTrue("handleCompleted", crFlags[0]); + assertFalse("handleSuccess", crFlags[1]); + assertFalse("handleFailure", crFlags[2]); + assertTrue("handleCancel", crFlags[3]); + + // Validate the first coalesced request + assertTrue("isCompleted", subRequest1.isCompleted()); + assertFalse("isFailed", subRequest1.isFailed()); + assertTrue("isCancelled", subRequest1.isCancelled()); + + // Validate the second coalesced request + assertTrue("isCompleted", subRequest2.isCompleted()); + assertFalse("isFailed", subRequest2.isFailed()); + assertTrue("isCancelled", subRequest2.isCancelled()); + } + + // ------------------------------------------------------------------------ + // Coalescing + // ------------------------------------------------------------------------ + + private static final String DIRECTORY = "testfiles"; private static final String TEST_STREAM = "A-Test-10K"; - private static final int NB_EVENTS = 5000; - private static final int BLOCK_SIZE = 100; + private static final int NB_EVENTS = 5000; + private static final int BLOCK_SIZE = 100; // Initialize the test trace private TmfTraceStub fTrace = null; + private synchronized TmfTraceStub setupTrace(String path) { - if (fTrace == null) { - try { - URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); - File test = new File(FileLocator.toFileURL(location).toURI()); - fTrace = new TmfTraceStub(test.getPath(), 500); - } catch (TmfTraceException e) { - e.printStackTrace(); + if (fTrace == null) { + try { + URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null); + File test = new File(FileLocator.toFileURL(location).toURI()); + fTrace = new TmfTraceStub(test.getPath(), 500); + } catch (TmfTraceException e) { + e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return fTrace; + } catch (IOException e) { + e.printStackTrace(); + } + } + return fTrace; } - Vector requestedEvents1; + Vector requestedEvents1; Vector requestedEvents2; Vector requestedEvents3; @@ -468,16 +472,17 @@ public class TmfCoalescedEventRequestTest extends TestCase { ITmfDataProvider[] providers; private static class TmfTestTriggerSignal extends TmfSignal { - public final boolean forceCancel; - public final long fIndex; - public TmfTestTriggerSignal(Object source, long index, boolean cancel) { - super(source); - forceCancel = cancel; - fIndex = index; - } + public final boolean forceCancel; + public final long fIndex; + + public TmfTestTriggerSignal(Object source, long index, boolean cancel) { + super(source); + forceCancel = cancel; + fIndex = index; + } } - @TmfSignalHandler + @TmfSignalHandler public void trigger(final TmfTestTriggerSignal signal) { TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); @@ -488,13 +493,13 @@ public class TmfCoalescedEventRequestTest extends TestCase { int nbRead = 0; @Override public void handleData(ITmfEvent event) { - super.handleData(event); - if (!isCompleted()) { - requestedEvents1.add(event); - if (++nbRead >= BLOCK_SIZE && signal.forceCancel) { + super.handleData(event); + if (!isCompleted()) { + requestedEvents1.add(event); + if (++nbRead >= BLOCK_SIZE && signal.forceCancel) { cancel(); } - } + } } }; @@ -502,10 +507,10 @@ public class TmfCoalescedEventRequestTest extends TestCase { request2 = new TmfEventRequest(ITmfEvent.class, range, signal.fIndex + REQUEST_OFFSET, NB_EVENTS, BLOCK_SIZE) { @Override public void handleData(ITmfEvent event) { - super.handleData(event); - if (!isCompleted()) { - requestedEvents2.add(event); - } + super.handleData(event); + if (!isCompleted()) { + requestedEvents2.add(event); + } } }; @@ -513,10 +518,10 @@ public class TmfCoalescedEventRequestTest extends TestCase { request3 = new TmfEventRequest(ITmfEvent.class, range, signal.fIndex + 2 * REQUEST_OFFSET, NB_EVENTS, BLOCK_SIZE) { @Override public void handleData(ITmfEvent event) { - super.handleData(event); - if (!isCompleted()) { - requestedEvents3.add(event); - } + super.handleData(event); + if (!isCompleted()) { + requestedEvents3.add(event); + } } }; @@ -540,16 +545,16 @@ public class TmfCoalescedEventRequestTest extends TestCase { try { assertEquals("Request1: nbEvents", NB_EVENTS, requestedEvents1.size()); - assertTrue ("Request1: isCompleted", request1.isCompleted()); - assertFalse ("Request1: isCancelled", request1.isCancelled()); + assertTrue("Request1: isCompleted", request1.isCompleted()); + assertFalse("Request1: isCancelled", request1.isCancelled()); assertEquals("Request2: nbEvents", NB_EVENTS, requestedEvents2.size()); - assertTrue ("Request2: isCompleted", request2.isCompleted()); - assertFalse ("Request2: isCancelled", request2.isCancelled()); + assertTrue("Request2: isCompleted", request2.isCompleted()); + assertFalse("Request2: isCancelled", request2.isCancelled()); assertEquals("Request3: nbEvents", NB_EVENTS, requestedEvents3.size()); - assertTrue ("Request3: isCompleted", request3.isCompleted()); - assertFalse ("Request3: isCancelled", request3.isCancelled()); + assertTrue("Request3: isCompleted", request3.isCompleted()); + assertFalse("Request3: isCancelled", request3.isCancelled()); // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! @@ -558,43 +563,44 @@ public class TmfCoalescedEventRequestTest extends TestCase { assertEquals("Distinct events", i + 1 + request2.getIndex(), requestedEvents2.get(i).getTimestamp().getValue()); assertEquals("Distinct events", i + 1 + request3.getIndex(), requestedEvents3.get(i).getTimestamp().getValue()); } - } - finally { + } finally { TmfSignalManager.deregister(this); fTrace.dispose(); fTrace = null; } } + @Test public void testCoalescedRequest() throws InterruptedException { runCoalescedRequest(0); runCoalescedRequest(1); runCoalescedRequest(5); } - public void testCancelCoalescedRequest() throws InterruptedException { + @Test + public void testCancelCoalescedRequest() throws InterruptedException { - fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM); + fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM); - TmfSignalManager.register(this); - TmfTestTriggerSignal signal = new TmfTestTriggerSignal(this, 0, true); - TmfSignalManager.dispatchSignal(signal); + TmfSignalManager.register(this); + TmfTestTriggerSignal signal = new TmfTestTriggerSignal(this, 0, true); + TmfSignalManager.dispatchSignal(signal); request1.waitForCompletion(); request2.waitForCompletion(); request3.waitForCompletion(); assertEquals("Request1: nbEvents", BLOCK_SIZE, requestedEvents1.size()); - assertTrue ("Request1: isCompleted", request1.isCompleted()); - assertTrue ("Request1: isCancelled", request1.isCancelled()); + assertTrue("Request1: isCompleted", request1.isCompleted()); + assertTrue("Request1: isCancelled", request1.isCancelled()); assertEquals("Request2: nbEvents", NB_EVENTS, requestedEvents2.size()); - assertTrue ("Request2: isCompleted", request2.isCompleted()); - assertFalse ("Request2: isCancelled", request2.isCancelled()); + assertTrue("Request2: isCompleted", request2.isCompleted()); + assertFalse("Request2: isCancelled", request2.isCancelled()); assertEquals("Request3: nbEvents", NB_EVENTS, requestedEvents3.size()); - assertTrue ("Request3: isCompleted", request3.isCompleted()); - assertFalse ("Request3: isCancelled", request3.isCancelled()); + assertTrue("Request3: isCompleted", request3.isCompleted()); + assertFalse("Request3: isCancelled", request3.isCancelled()); // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! @@ -611,8 +617,4 @@ public class TmfCoalescedEventRequestTest extends TestCase { fTrace = null; } - // ------------------------------------------------------------------------ - // - // ------------------------------------------------------------------------ - } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfDataRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfDataRequestTest.java index ddf85561eb..cc7abc98b6 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfDataRequestTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfDataRequestTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,102 +8,96 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.request; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfDataRequestStub; +import org.junit.Before; +import org.junit.Test; /** - * TmfDataRequestTest - *

* Test suite for the TmfDataRequest class. */ -@SuppressWarnings({"nls","javadoc"}) -public class TmfDataRequestTest extends TestCase { +@SuppressWarnings({ "nls", "javadoc" }) +public class TmfDataRequestTest { - // ------------------------------------------------------------------------ - // Variables - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // Variables + // ------------------------------------------------------------------------ - private static TmfDataRequest fRequest1; - private static TmfDataRequest fRequest1b; - private static TmfDataRequest fRequest1c; - private static TmfDataRequest fRequest2; - private static TmfDataRequest fRequest3; - private static TmfDataRequest fRequest4; + private static TmfDataRequest fRequest1; + private static TmfDataRequest fRequest1b; + private static TmfDataRequest fRequest1c; + private static TmfDataRequest fRequest2; + private static TmfDataRequest fRequest3; + private static TmfDataRequest fRequest4; - private static int fRequestCount; + private static int fRequestCount; // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfDataRequestTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - TmfDataRequest.reset(); - fRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - fRequest2 = new TmfDataRequestStub(ITmfEvent.class, 20, 100, 200); - fRequest3 = new TmfDataRequestStub(ITmfEvent.class, 20, 200, 200); - fRequest4 = new TmfDataRequestStub(ITmfEvent.class, 20, 200, 300); - fRequest1b = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - fRequest1c = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); - fRequestCount = fRequest1c.getRequestId() + 1; - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - private static TmfDataRequest setupTestRequest(final boolean[] flags) { - - TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200) { - @Override - public void handleCompleted() { - super.handleCompleted(); - flags[0] = true; - } - @Override - public void handleSuccess() { - super.handleSuccess(); - flags[1] = true; - } - @Override - public void handleFailure() { - super.handleFailure(); - flags[2] = true; - } - @Override - public void handleCancel() { - super.handleCancel(); - flags[3] = true; - } - }; - return request; - } - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - public void testTmfDataRequest() { + // Housekeeping + // ------------------------------------------------------------------------ + + @Before + public void setUp() { + TmfDataRequest.reset(); + fRequest1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + fRequest2 = new TmfDataRequestStub(ITmfEvent.class, 20, 100, 200); + fRequest3 = new TmfDataRequestStub(ITmfEvent.class, 20, 200, 200); + fRequest4 = new TmfDataRequestStub(ITmfEvent.class, 20, 200, 300); + fRequest1b = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + fRequest1c = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); + fRequestCount = fRequest1c.getRequestId() + 1; + } + + private static TmfDataRequest setupTestRequest(final boolean[] flags) { + + TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200) { + @Override + public void handleCompleted() { + super.handleCompleted(); + flags[0] = true; + } + + @Override + public void handleSuccess() { + super.handleSuccess(); + flags[1] = true; + } + + @Override + public void handleFailure() { + super.handleFailure(); + flags[2] = true; + } + + @Override + public void handleCancel() { + super.handleCancel(); + flags[3] = true; + } + }; + return request; + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + @Test + public void testTmfDataRequest() { TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 0, request.getIndex()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -113,13 +107,14 @@ public class TmfDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfDataRequestIndex() { + @Test + public void testTmfDataRequestIndex() { TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 10, request.getIndex()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -129,13 +124,14 @@ public class TmfDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfDataRequestIndexNbRequested() { + @Test + public void testTmfDataRequestIndexNbRequested() { TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10, 100); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 10, request.getIndex()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -145,13 +141,14 @@ public class TmfDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfDataRequestIndexNbEventsBlocksize() { + @Test + public void testTmfDataRequestIndexNbEventsBlocksize() { TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("getIndex", 10, request.getIndex()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -161,21 +158,23 @@ public class TmfDataRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - // ------------------------------------------------------------------------ - // equals - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ - public void testEqualsReflexivity() { + @Test + public void testEqualsReflexivity() { assertTrue("equals", fRequest1.equals(fRequest1)); assertTrue("equals", fRequest2.equals(fRequest2)); assertFalse("equals", fRequest1.equals(fRequest2)); assertFalse("equals", fRequest2.equals(fRequest1)); - } + } - public void testEqualsSymmetry() { + @Test + public void testEqualsSymmetry() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1)); @@ -183,34 +182,38 @@ public class TmfDataRequestTest extends TestCase { assertFalse("equals", fRequest2.equals(fRequest3)); assertFalse("equals", fRequest3.equals(fRequest1)); assertFalse("equals", fRequest3.equals(fRequest2)); - } + } - public void testEqualsTransivity() { + @Test + public void testEqualsTransivity() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1c)); assertTrue("equals", fRequest1.equals(fRequest1c)); - } + } - public void testEqualsNull() { + @Test + public void testEqualsNull() { assertFalse("equals", fRequest1.equals(null)); assertFalse("equals", fRequest2.equals(null)); - } + } - // ------------------------------------------------------------------------ - // hashCode - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ - public void testHashCode() { + @Test + public void testHashCode() { assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode()); assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode()); - assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); - } + assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); + } - // ------------------------------------------------------------------------ - // toString - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // toString + // ------------------------------------------------------------------------ - public void testToString() { + @Test + public void testToString() { String expected1 = "[TmfDataRequest(0,ITmfEvent,10,100,200)]"; String expected2 = "[TmfDataRequest(1,ITmfEvent,20,100,200)]"; String expected3 = "[TmfDataRequest(2,ITmfEvent,20,200,200)]"; @@ -220,70 +223,66 @@ public class TmfDataRequestTest extends TestCase { assertEquals("toString", expected2, fRequest2.toString()); assertEquals("toString", expected3, fRequest3.toString()); assertEquals("toString", expected4, fRequest4.toString()); - } + } - // ------------------------------------------------------------------------ - // done - // ------------------------------------------------------------------------ - - public void testDone() { - - final boolean[] flags = new boolean[4]; - TmfDataRequest request = setupTestRequest(flags); - request.done(); - - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); - - assertTrue ("handleCompleted", flags[0]); - assertTrue ("handleSuccess", flags[1]); - assertFalse("handleFailure", flags[2]); - assertFalse("handleCancel", flags[3]); - } + // ------------------------------------------------------------------------ + // done + // ------------------------------------------------------------------------ - // ------------------------------------------------------------------------ - // fail - // ------------------------------------------------------------------------ + @Test + public void testDone() { + final boolean[] flags = new boolean[4]; + TmfDataRequest request = setupTestRequest(flags); + request.done(); - public void testFail() { + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); - final boolean[] flags = new boolean[4]; - TmfDataRequest request = setupTestRequest(flags); - request.fail(); + assertTrue("handleCompleted", flags[0]); + assertTrue("handleSuccess", flags[1]); + assertFalse("handleFailure", flags[2]); + assertFalse("handleCancel", flags[3]); + } - assertTrue ("isCompleted", request.isCompleted()); - assertTrue ("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); + // ------------------------------------------------------------------------ + // fail + // ------------------------------------------------------------------------ - assertTrue ("handleCompleted", flags[0]); - assertFalse("handleSuccess", flags[1]); - assertTrue ("handleFailure", flags[2]); - assertFalse("handleCancel", flags[3]); - } + @Test + public void testFail() { + final boolean[] flags = new boolean[4]; + TmfDataRequest request = setupTestRequest(flags); + request.fail(); - // ------------------------------------------------------------------------ - // cancel - // ------------------------------------------------------------------------ + assertTrue("isCompleted", request.isCompleted()); + assertTrue("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); - public void testCancel() { + assertTrue("handleCompleted", flags[0]); + assertFalse("handleSuccess", flags[1]); + assertTrue("handleFailure", flags[2]); + assertFalse("handleCancel", flags[3]); + } - final boolean[] flags = new boolean[4]; - TmfDataRequest request = setupTestRequest(flags); - request.cancel(); + // ------------------------------------------------------------------------ + // cancel + // ------------------------------------------------------------------------ - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertTrue ("isCancelled", request.isCancelled()); + @Test + public void testCancel() { + final boolean[] flags = new boolean[4]; + TmfDataRequest request = setupTestRequest(flags); + request.cancel(); - assertTrue ("handleCompleted", flags[0]); - assertFalse("handleSuccess", flags[1]); - assertFalse("handleFailure", flags[2]); - assertTrue ("handleCancel", flags[3]); - } + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertTrue("isCancelled", request.isCancelled()); - // ------------------------------------------------------------------------ - // waitForCompletion - // ------------------------------------------------------------------------ + assertTrue("handleCompleted", flags[0]); + assertFalse("handleSuccess", flags[1]); + assertFalse("handleFailure", flags[2]); + assertTrue("handleCancel", flags[3]); + } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventRequestTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventRequestTest.java index 936eec307b..626d0b45b0 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventRequestTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfEventRequestTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Ericsson + * Copyright (c) 2009, 2010, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,11 +8,14 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.request; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; @@ -20,99 +23,90 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfEventRequestStub; +import org.junit.Before; +import org.junit.Test; /** - * TmfEventRequestTest - *

* Test suite for the TmfEventRequest class. */ -@SuppressWarnings({"nls","javadoc"}) -public class TmfEventRequestTest extends TestCase { - - // ------------------------------------------------------------------------ - // Variables - // ------------------------------------------------------------------------ - - private static TmfTimeRange range1 = new TmfTimeRange(TmfTimeRange.ETERNITY); - private static TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH); - - private static TmfEventRequest fRequest1; - private static TmfEventRequest fRequest1b; - private static TmfEventRequest fRequest1c; - private static TmfEventRequest fRequest2; - private static TmfEventRequest fRequest3; - private static TmfEventRequest fRequest4; - - private static int fRequestCount; - - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfEventRequestTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - TmfDataRequest.reset(); - fRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - fRequest2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 200); - fRequest3 = new TmfEventRequestStub(ITmfEvent.class, range2, 200, 200); - fRequest4 = new TmfEventRequestStub(ITmfEvent.class, range2, 200, 300); - fRequest1b = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - fRequest1c = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); - fRequestCount = fRequest1c.getRequestId() + 1; - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - private static TmfEventRequest setupTestRequest(final boolean[] flags) { - - TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, new TmfTimeRange(TmfTimeRange.ETERNITY), 100, 200) { - @Override - public void handleCompleted() { - super.handleCompleted(); - flags[0] = true; - } - @Override - public void handleSuccess() { - super.handleSuccess(); - flags[1] = true; - } - @Override - public void handleFailure() { - super.handleFailure(); - flags[2] = true; - } - @Override - public void handleCancel() { - super.handleCancel(); - flags[3] = true; - } - }; - return request; - } - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - public void testTmfEventRequest() { +@SuppressWarnings({ "nls", "javadoc" }) +public class TmfEventRequestTest { + + // ------------------------------------------------------------------------ + // Variables + // ------------------------------------------------------------------------ + + private static TmfTimeRange range1 = new TmfTimeRange(TmfTimeRange.ETERNITY); + private static TmfTimeRange range2 = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH); + + private static TmfEventRequest fRequest1; + private static TmfEventRequest fRequest1b; + private static TmfEventRequest fRequest1c; + private static TmfEventRequest fRequest2; + private static TmfEventRequest fRequest3; + private static TmfEventRequest fRequest4; + + private static int fRequestCount; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + @Before + public void setUp() { + TmfDataRequest.reset(); + fRequest1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + fRequest2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 200); + fRequest3 = new TmfEventRequestStub(ITmfEvent.class, range2, 200, 200); + fRequest4 = new TmfEventRequestStub(ITmfEvent.class, range2, 200, 300); + fRequest1b = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + fRequest1c = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200); + fRequestCount = fRequest1c.getRequestId() + 1; + } + + private static TmfEventRequest setupTestRequest(final boolean[] flags) { + + TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, new TmfTimeRange(TmfTimeRange.ETERNITY), 100, 200) { + @Override + public void handleCompleted() { + super.handleCompleted(); + flags[0] = true; + } + + @Override + public void handleSuccess() { + super.handleSuccess(); + flags[1] = true; + } + + @Override + public void handleFailure() { + super.handleFailure(); + flags[2] = true; + } + + @Override + public void handleCancel() { + super.handleCancel(); + flags[3] = true; + } + }; + return request; + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + @Test + public void testTmfEventRequest() { TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class); assertEquals("getRequestId", fRequestCount++, request.getRequestId()); - assertEquals("getDataType", ITmfEvent.class, request.getDataType()); + assertEquals("getDataType", ITmfEvent.class, request.getDataType()); - assertEquals("StartTime", TmfTimestamp.BIG_BANG, request.getRange().getStartTime()); - assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); + assertEquals("StartTime", TmfTimestamp.BIG_BANG, request.getRange().getStartTime()); + assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); assertEquals("getIndex", 0, request.getIndex()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -122,9 +116,10 @@ public class TmfEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfEventRequestTimeRange() { + @Test + public void testTmfEventRequestTimeRange() { TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH); TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, range); @@ -132,7 +127,7 @@ public class TmfEventRequestTest extends TestCase { assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("StartTime", new TmfTimestamp(), request.getRange().getStartTime()); - assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); + assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); assertEquals("getIndex", 0, request.getIndex()); assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested()); @@ -142,9 +137,10 @@ public class TmfEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfEventRequestTimeRangeNbRequested() { + @Test + public void testTmfEventRequestTimeRangeNbRequested() { TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH); TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, range, 100); @@ -152,7 +148,7 @@ public class TmfEventRequestTest extends TestCase { assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("StartTime", new TmfTimestamp(), request.getRange().getStartTime()); - assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); + assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); assertEquals("getIndex", 0, request.getIndex()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -162,9 +158,10 @@ public class TmfEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - public void testTmfEventRequestTimeRangeNbRequestedBlocksize() { + @Test + public void testTmfEventRequestTimeRangeNbRequestedBlocksize() { TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(), TmfTimestamp.BIG_CRUNCH); TmfEventRequest request = new TmfEventRequestStub(ITmfEvent.class, range, 100, 200); @@ -172,7 +169,7 @@ public class TmfEventRequestTest extends TestCase { assertEquals("getDataType", ITmfEvent.class, request.getDataType()); assertEquals("StartTime", new TmfTimestamp(), request.getRange().getStartTime()); - assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); + assertEquals("EndTime", TmfTimestamp.BIG_CRUNCH, request.getRange().getEndTime()); assertEquals("getIndex", 0, request.getIndex()); assertEquals("getNbRequestedEvents", 100, request.getNbRequested()); @@ -182,21 +179,23 @@ public class TmfEventRequestTest extends TestCase { assertFalse("isCancelled", request.isCancelled()); assertEquals("getNbRead", 0, request.getNbRead()); - } + } - // ------------------------------------------------------------------------ - // equals - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ - public void testEqualsReflexivity() { + @Test + public void testEqualsReflexivity() { assertTrue("equals", fRequest1.equals(fRequest1)); assertTrue("equals", fRequest2.equals(fRequest2)); assertFalse("equals", fRequest1.equals(fRequest2)); assertFalse("equals", fRequest2.equals(fRequest1)); - } + } - public void testEqualsSymmetry() { + @Test + public void testEqualsSymmetry() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1)); @@ -204,34 +203,38 @@ public class TmfEventRequestTest extends TestCase { assertFalse("equals", fRequest2.equals(fRequest3)); assertFalse("equals", fRequest3.equals(fRequest1)); assertFalse("equals", fRequest3.equals(fRequest2)); - } + } - public void testEqualsTransivity() { + @Test + public void testEqualsTransivity() { assertTrue("equals", fRequest1.equals(fRequest1b)); assertTrue("equals", fRequest1b.equals(fRequest1c)); assertTrue("equals", fRequest1.equals(fRequest1c)); - } + } - public void testEqualsNull() { + @Test + public void testEqualsNull() { assertFalse("equals", fRequest1.equals(null)); assertFalse("equals", fRequest2.equals(null)); - } + } - // ------------------------------------------------------------------------ - // hashCode - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ - public void testHashCode() { + @Test + public void testHashCode() { assertTrue("hashCode", fRequest1.hashCode() == fRequest1.hashCode()); assertTrue("hashCode", fRequest2.hashCode() == fRequest2.hashCode()); - assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); - } + assertTrue("hashCode", fRequest1.hashCode() != fRequest2.hashCode()); + } - // ------------------------------------------------------------------------ - // toString - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // toString + // ------------------------------------------------------------------------ - public void testToString() { + @Test + public void testToString() { String expected1 = "[TmfEventRequest(0,ITmfEvent," + range1 + ",0,100,200)]"; String expected2 = "[TmfEventRequest(1,ITmfEvent," + range2 + ",0,100,200)]"; String expected3 = "[TmfEventRequest(2,ITmfEvent," + range2 + ",0,200,200)]"; @@ -241,70 +244,66 @@ public class TmfEventRequestTest extends TestCase { assertEquals("toString", expected2, fRequest2.toString()); assertEquals("toString", expected3, fRequest3.toString()); assertEquals("toString", expected4, fRequest4.toString()); - } - - // ------------------------------------------------------------------------ - // done - // ------------------------------------------------------------------------ - - public void testDone() { - - final boolean[] flags = new boolean[4]; - TmfEventRequest request = setupTestRequest(flags); - request.done(); - - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); + } - assertTrue ("handleCompleted", flags[0]); - assertTrue ("handleSuccess", flags[1]); - assertFalse("handleFailure", flags[2]); - assertFalse("handleCancel", flags[3]); - } + // ------------------------------------------------------------------------ + // done + // ------------------------------------------------------------------------ - // ------------------------------------------------------------------------ - // fail - // ------------------------------------------------------------------------ + @Test + public void testDone() { + final boolean[] flags = new boolean[4]; + TmfEventRequest request = setupTestRequest(flags); + request.done(); - public void testFail() { + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); - final boolean[] flags = new boolean[4]; - TmfEventRequest request = setupTestRequest(flags); - request.fail(); + assertTrue("handleCompleted", flags[0]); + assertTrue("handleSuccess", flags[1]); + assertFalse("handleFailure", flags[2]); + assertFalse("handleCancel", flags[3]); + } - assertTrue ("isCompleted", request.isCompleted()); - assertTrue ("isFailed", request.isFailed()); - assertFalse("isCancelled", request.isCancelled()); + // ------------------------------------------------------------------------ + // fail + // ------------------------------------------------------------------------ - assertTrue ("handleCompleted", flags[0]); - assertFalse("handleSuccess", flags[1]); - assertTrue ("handleFailure", flags[2]); - assertFalse("handleCancel", flags[3]); - } + @Test + public void testFail() { + final boolean[] flags = new boolean[4]; + TmfEventRequest request = setupTestRequest(flags); + request.fail(); - // ------------------------------------------------------------------------ - // cancel - // ------------------------------------------------------------------------ + assertTrue("isCompleted", request.isCompleted()); + assertTrue("isFailed", request.isFailed()); + assertFalse("isCancelled", request.isCancelled()); - public void testCancel() { + assertTrue("handleCompleted", flags[0]); + assertFalse("handleSuccess", flags[1]); + assertTrue("handleFailure", flags[2]); + assertFalse("handleCancel", flags[3]); + } - final boolean[] flags = new boolean[4]; - TmfEventRequest request = setupTestRequest(flags); - request.cancel(); + // ------------------------------------------------------------------------ + // cancel + // ------------------------------------------------------------------------ - assertTrue ("isCompleted", request.isCompleted()); - assertFalse("isFailed", request.isFailed()); - assertTrue ("isCancelled", request.isCancelled()); + @Test + public void testCancel() { + final boolean[] flags = new boolean[4]; + TmfEventRequest request = setupTestRequest(flags); + request.cancel(); - assertTrue ("handleCompleted", flags[0]); - assertFalse("handleSuccess", flags[1]); - assertFalse("handleFailure", flags[2]); - assertTrue ("handleCancel", flags[3]); - } + assertTrue("isCompleted", request.isCompleted()); + assertFalse("isFailed", request.isFailed()); + assertTrue("isCancelled", request.isCancelled()); - // ------------------------------------------------------------------------ - // waitForCompletion - // ------------------------------------------------------------------------ + assertTrue("handleCompleted", flags[0]); + assertFalse("handleSuccess", flags[1]); + assertFalse("handleFailure", flags[2]); + assertTrue("handleCancel", flags[3]); + } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestExecutorTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestExecutorTest.java index bd6ef51b3c..626417ded4 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestExecutorTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/request/TmfRequestExecutorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,11 +8,14 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.request; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.eclipse.linuxtools.internal.tmf.core.component.TmfEventThread; import org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor; @@ -26,11 +29,15 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfSignal; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + /** * Test suite for the TmfRequestExecutor class. */ @SuppressWarnings({ "nls" }) -public class TmfRequestExecutorTest extends TestCase { +public class TmfRequestExecutorTest { // ------------------------------------------------------------------------ // Variables @@ -38,137 +45,153 @@ public class TmfRequestExecutorTest extends TestCase { private TmfRequestExecutor fExecutor; - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfRequestExecutorTest(String name) { - super(name); - } + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ - @Override - protected void setUp() throws Exception { - super.setUp(); + /** + * Setup + */ + @Before + public void setUp() { fExecutor = new TmfRequestExecutor(); - } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + /** + * Cleanup + */ + @After + public void tearDown() { fExecutor.stop(); } - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - /** - * Test method for {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#TmfRequestExecutor()}. - */ - public void testTmfRequestExecutor() { - TmfRequestExecutor executor = new TmfRequestExecutor(); - assertFalse("isShutdown", executor.isShutdown()); - assertFalse("isTerminated", executor.isTerminated()); - } - - /** - * Test method for {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#stop()}. - */ - public void testStop() { - TmfRequestExecutor executor = new TmfRequestExecutor(); - executor.stop(); - assertTrue("isShutdown", executor.isShutdown()); - assertTrue("isTerminated", executor.isTerminated()); - } - - // ------------------------------------------------------------------------ - // execute - // ------------------------------------------------------------------------ - - // Dummy context - private static class MyContext implements ITmfContext { - private long fNbRequested; + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Test method for + * {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#TmfRequestExecutor()} + */ + @Test + public void testTmfRequestExecutor() { + TmfRequestExecutor executor = new TmfRequestExecutor(); + assertFalse("isShutdown", executor.isShutdown()); + assertFalse("isTerminated", executor.isTerminated()); + } + + /** + * Test method for + * {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#stop()} + */ + @Test + public void testStop() { + TmfRequestExecutor executor = new TmfRequestExecutor(); + executor.stop(); + assertTrue("isShutdown", executor.isShutdown()); + assertTrue("isTerminated", executor.isTerminated()); + } + + // ------------------------------------------------------------------------ + // execute + // ------------------------------------------------------------------------ + + // Dummy context + private static class MyContext implements ITmfContext { + private long fNbRequested; private long fRank; public MyContext(long requested) { fNbRequested = requested; fRank = 0; } + @Override public long getRank() { return (fRank <= fNbRequested) ? fRank : -1; } + @Override public ITmfLocation getLocation() { return null; } + @Override public boolean hasValidRank() { return true; } + @Override public void setLocation(ITmfLocation location) { } + @Override public void setRank(long rank) { fRank = rank; } + @Override public void increaseRank() { fRank++; } + @Override public void dispose() { } + @Override public MyContext clone() { return this; } - } + } - // Dummy provider - private static class MyProvider extends TmfDataProvider { - private ITmfEvent fEvent = new TmfEvent(); + // Dummy provider + private static class MyProvider extends TmfDataProvider { + private ITmfEvent fEvent = new TmfEvent(); @Override public String getName() { return null; } + @Override public void dispose() { } + @Override public void broadcast(TmfSignal signal) { } + @Override public void sendRequest(ITmfDataRequest request) { } + @Override public void fireRequest() { } + @Override public void notifyPendingRequest(boolean isIncrement) { } + @Override public ITmfEvent getNext(ITmfContext context) { context.increaseRank(); return context.getRank() >= 0 ? fEvent : null; } + @Override public ITmfContext armRequest(ITmfDataRequest request) { return new MyContext(request.getNbRequested()); } - } + } - // Dummy request + // Dummy request private static class MyRequest extends TmfDataRequest { public MyRequest(ExecutionType priority, int requested) { super(ITmfEvent.class, 0, requested, priority); } + @Override public void done() { synchronized (monitor) { @@ -187,16 +210,18 @@ public class TmfRequestExecutorTest extends TestCase { private final static Object monitor = new Object(); /** - * Test method for {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#execute(java.lang.Runnable)}. - */ - public void testExecute() { + * Test method for + * {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#execute(java.lang.Runnable)} + */ + @Test + public void testExecute() { MyProvider provider = new MyProvider(); - MyRequest request1 = new MyRequest(ExecutionType.BACKGROUND, Integer.MAX_VALUE / 5); - MyThread thread1 = new MyThread(provider, request1); - MyRequest request2 = new MyRequest(ExecutionType.FOREGROUND, Integer.MAX_VALUE / 10); - MyThread thread2 = new MyThread(provider, request2); - MyRequest request3 = new MyRequest(ExecutionType.FOREGROUND, Integer.MAX_VALUE / 10); - MyThread thread3 = new MyThread(provider, request3); + MyRequest request1 = new MyRequest(ExecutionType.BACKGROUND, Integer.MAX_VALUE / 5); + MyThread thread1 = new MyThread(provider, request1); + MyRequest request2 = new MyRequest(ExecutionType.FOREGROUND, Integer.MAX_VALUE / 10); + MyThread thread2 = new MyThread(provider, request2); + MyRequest request3 = new MyRequest(ExecutionType.FOREGROUND, Integer.MAX_VALUE / 10); + MyThread thread3 = new MyThread(provider, request3); // Start thread1 fExecutor.execute(thread1); @@ -204,7 +229,7 @@ public class TmfRequestExecutorTest extends TestCase { Thread.sleep(1000); } catch (InterruptedException e) { } - assertTrue("isRunning", thread1.isRunning()); + assertTrue("isRunning", thread1.isRunning()); // Start higher priority thread2 fExecutor.execute(thread2); @@ -256,17 +281,19 @@ public class TmfRequestExecutorTest extends TestCase { assertTrue("isCompleted", thread1.isCompleted()); } - // ------------------------------------------------------------------------ - // toString - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // toString + // ------------------------------------------------------------------------ - /** - * Test method for {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#toString()}. - */ - public void testToString() { + /** + * Test method for + * {@link org.eclipse.linuxtools.internal.tmf.core.request.TmfRequestExecutor#toString()} + */ + @Test + public void testToString() { TmfRequestExecutor executor = new TmfRequestExecutor(); String expected = "[TmfRequestExecutor(ThreadPoolExecutor)]"; assertEquals("toString", expected, executor.toString()); - } + } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/AllTests.java index d6c151f0fa..b1da18db75 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/AllTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,28 +8,21 @@ * * Contributors: * Alexandre Montplaisir - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 ******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.statesystem; -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** * Test suite for org.eclipse.linuxtools.tmf.core.statesystem */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + StateSystemPushPopTest.class +}) public class AllTests { - /** - * @return The state system test suite - */ - public static Test suite() { - final TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".statesystem"); //$NON-NLS-1$ //$NON-NLS-2$; - //$JUnit-BEGIN$ - suite.addTestSuite(StateSystemPushPopTest.class); - //$JUnit-END$ - return suite; - } } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java index 6f8154acca..6744ecac90 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/StateSystemPushPopTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,16 +8,19 @@ * * Contributors: * Alexandre Montplaisir - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 ******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.statesystem; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.IOException; import java.util.List; -import junit.framework.TestCase; - import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem; import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree.HistoryTreeBackend; @@ -29,6 +32,9 @@ import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystemBuilder; import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Unit tests for stack-attributes in the Generic State System (using @@ -36,7 +42,7 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; * * @author Alexandre Montplaisir */ -public class StateSystemPushPopTest extends TestCase { +public class StateSystemPushPopTest { private ITmfStateSystemBuilder ss; @@ -57,13 +63,10 @@ public class StateSystemPushPopTest extends TestCase { /** * Test case constructor * - * @param name - * The test name * @throws IOException * If we couldn't create the state history test file */ - public StateSystemPushPopTest(final String name) throws IOException { - super(name); + public StateSystemPushPopTest() throws IOException { testHtFile = File.createTempFile("test", ".ht"); //$NON-NLS-1$ //$NON-NLS-2$ testHtFile.deleteOnExit(); } @@ -82,7 +85,7 @@ public class StateSystemPushPopTest extends TestCase { * @throws StateValueTypeException * Fails the test */ - @Override + @Before public void setUp() throws IOException, TimeRangeException, AttributeNotFoundException, StateValueTypeException { ITmfStateValue value; @@ -134,7 +137,7 @@ public class StateSystemPushPopTest extends TestCase { /** * Clean-up after running a test. Delete the .ht file we created. */ - @Override + @After public void tearDown() { testHtFile.delete(); } @@ -143,6 +146,7 @@ public class StateSystemPushPopTest extends TestCase { * Test that the value of the stack-attribute at the start and end of the * history are correct. */ + @Test public void testBeginEnd() { try { interval = ss.querySingleState(0, attribute); @@ -167,6 +171,7 @@ public class StateSystemPushPopTest extends TestCase { /** * Run single queries on the attribute stacks (with .querySingleState()). */ + @Test public void testSingleQueries() { try { final int subAttribute1 = ss.getQuarkRelative(attribute, "1"); //$NON-NLS-1$ @@ -203,6 +208,7 @@ public class StateSystemPushPopTest extends TestCase { /** * Test the .querySingletStackTop() convenience method. */ + @Test public void testStackTop() { try { interval = ss.querySingleStackTop(10, attribute); @@ -231,6 +237,7 @@ public class StateSystemPushPopTest extends TestCase { /** * Test the places where the stack is empty. */ + @Test public void testEmptyStack() { try { /* At the start */ @@ -265,6 +272,7 @@ public class StateSystemPushPopTest extends TestCase { /** * Test full-queries (.queryFullState()) on the attribute stacks. */ + @Test public void testFullQueries() { List state; try { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java index ab44c9c94f..847140c70f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/AllTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson + * Copyright (c) 2009, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,39 +9,29 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Trace Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** * Test suite for org.eclipse.linuxtools.tmf.core.trace */ -@SuppressWarnings({ "nls" }) +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TmfCheckpointIndexTest.class, + TmfCheckpointIndexTest2.class, + TmfCheckpointTest.class, + TmfContextTest.class, + TmfExperimentCheckpointIndexTest.class, + TmfExperimentTest.class, + TmfLocationTest.class, + TmfMultiTraceExperimentTest.class, + TmfTraceTest.class +}) public class AllTests { - /** - * @return the test suite - */ - public static Test suite() { - TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".trace"); //$NON-NLS-1$); - //$JUnit-BEGIN$ - suite.addTestSuite(TmfLocationTest.class); - suite.addTestSuite(TmfContextTest.class); - suite.addTestSuite(TmfCheckpointTest.class); - suite.addTestSuite(TmfCheckpointIndexTest.class); - suite.addTestSuite(TmfCheckpointIndexTest2.class); - suite.addTestSuite(TmfTraceTest.class); - - suite.addTestSuite(TmfExperimentCheckpointIndexTest.class); - suite.addTestSuite(TmfExperimentTest.class); - suite.addTestSuite(TmfMultiTraceExperimentTest.class); - //$JUnit-END$ - return suite; - } - } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java index 50206408d7..d940f1d076 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,18 +9,20 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adapted for TMF Trace Model 1.0 + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.List; -import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; @@ -33,12 +35,15 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfCheckpointIndexTest class. */ @SuppressWarnings({"nls","javadoc"}) -public class TmfCheckpointIndexTest extends TestCase { +public class TmfCheckpointIndexTest { // ------------------------------------------------------------------------ // Variables @@ -55,22 +60,13 @@ public class TmfCheckpointIndexTest extends TestCase { // Housekeeping // ------------------------------------------------------------------------ - /** - * @param name the test name - */ - public TmfCheckpointIndexTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { setupTrace(DIRECTORY + File.separator + TEST_STREAM); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() { fTrace.dispose(); fTrace = null; fEmptyTrace.dispose(); @@ -147,6 +143,7 @@ public class TmfCheckpointIndexTest extends TestCase { // Verify checkpoints // ------------------------------------------------------------------------ + @Test @SuppressWarnings("null") public void testTmfTraceIndexing() { assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize()); @@ -171,6 +168,7 @@ public class TmfCheckpointIndexTest extends TestCase { } } + @Test @SuppressWarnings("null") public void testEmptyTmfTraceIndexing() { assertEquals("getCacheSize", ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, fEmptyTrace.getCacheSize()); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java index eabcf335f7..b6bd11e5de 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointIndexTest2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,18 +8,21 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.List; -import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; @@ -31,13 +34,16 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfEmptyTraceStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfCheckpointIndexer class (events with same * timestamp around checkpoint). */ @SuppressWarnings({"nls","javadoc"}) -public class TmfCheckpointIndexTest2 extends TestCase { +public class TmfCheckpointIndexTest2 { // ------------------------------------------------------------------------ // Variables @@ -56,22 +62,13 @@ public class TmfCheckpointIndexTest2 extends TestCase { // Housekeeping // ------------------------------------------------------------------------ - /** - * @param name the test name - */ - public TmfCheckpointIndexTest2(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { setupTrace(DIRECTORY + File.separator + TEST_STREAM); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() { fTrace.dispose(); fTrace = null; fEmptyTrace.dispose(); @@ -148,6 +145,7 @@ public class TmfCheckpointIndexTest2 extends TestCase { // Verify checkpoints // ------------------------------------------------------------------------ + @Test @SuppressWarnings("null") public void testTmfTraceMultiTimestamps() { assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize()); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java index bedaa6991b..dbb1669f64 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfCheckpointTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,11 +9,16 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adapted for TMF Trace Model 1.0 + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; -import junit.framework.TestCase; +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 org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; @@ -21,57 +26,38 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation; +import org.junit.Test; /** * Test suite for the TmfCheckpoint class. */ @SuppressWarnings({"nls","javadoc"}) -public class TmfCheckpointTest extends TestCase { +public class TmfCheckpointTest { // ------------------------------------------------------------------------ // Variables // ------------------------------------------------------------------------ - ITmfTimestamp fTimestamp1 = new TmfTimestamp(); - ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG; - ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH; + private ITmfTimestamp fTimestamp1 = new TmfTimestamp(); + private ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG; + private ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH; - Long aLong1 = 12345L; - Long aLong2 = 23456L; - Long aLong3 = 34567L; - ITmfLocation fLocation1 = new TmfLongLocation(aLong1); - ITmfLocation fLocation2 = new TmfLongLocation(aLong2); - ITmfLocation fLocation3 = new TmfLongLocation(aLong3); + private Long aLong1 = 12345L; + private Long aLong2 = 23456L; + private Long aLong3 = 34567L; + private ITmfLocation fLocation1 = new TmfLongLocation(aLong1); + private ITmfLocation fLocation2 = new TmfLongLocation(aLong2); + private ITmfLocation fLocation3 = new TmfLongLocation(aLong3); - TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, new TmfContext(fLocation1)); - TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, new TmfContext(fLocation2)); - TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, new TmfContext(fLocation3)); - - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfCheckpointTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } + private TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, new TmfContext(fLocation1)); + private TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, new TmfContext(fLocation2)); + private TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, new TmfContext(fLocation3)); // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ + @Test public void testTmfCheckpoint() { assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp()); assertEquals("TmfCheckpoint", fLocation1, fCheckpoint1.getLocation()); @@ -84,6 +70,7 @@ public class TmfCheckpointTest extends TestCase { assertEquals("TmfCheckpoint", fLocation1, checkpoint.getLocation()); } + @Test public void testTmfLocationCopy2() { try { new TmfCheckpoint(null); @@ -101,6 +88,7 @@ public class TmfCheckpointTest extends TestCase { // clone // ------------------------------------------------------------------------ + @Test public void testClone() { try { TmfCheckpoint checkpoint1 = fCheckpoint1.clone(); @@ -132,6 +120,7 @@ public class TmfCheckpointTest extends TestCase { // compareTo // ------------------------------------------------------------------------ + @Test public void testCompareTo() { assertEquals("compareTo", 0, fCheckpoint1.compareTo(fCheckpoint1)); assertEquals("compareTo", 1, fCheckpoint1.compareTo(fCheckpoint2)); @@ -146,6 +135,7 @@ public class TmfCheckpointTest extends TestCase { assertEquals("compareTo", 0, fCheckpoint3.compareTo(fCheckpoint3)); } + @Test public void testCompareToNull() { final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, new TmfContext(fLocation1)); final TmfCheckpoint checkpoint2 = new TmfCheckpoint(null, new TmfContext(fLocation2)); @@ -173,6 +163,7 @@ public class TmfCheckpointTest extends TestCase { // hashCode // ------------------------------------------------------------------------ + @Test public void testHashCode() { final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); @@ -184,6 +175,7 @@ public class TmfCheckpointTest extends TestCase { assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode()); } + @Test public void testHashCodeNull() { final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, new TmfContext(fLocation1)); final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp1, null); @@ -201,6 +193,7 @@ public class TmfCheckpointTest extends TestCase { // equals // ------------------------------------------------------------------------ + @Test public void testEqualsReflexivity() { assertTrue("equals", fCheckpoint1.equals(fCheckpoint1)); assertTrue("equals", fCheckpoint2.equals(fCheckpoint2)); @@ -209,6 +202,7 @@ public class TmfCheckpointTest extends TestCase { assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1)); } + @Test public void testEqualsSymmetry() { final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); @@ -220,6 +214,7 @@ public class TmfCheckpointTest extends TestCase { assertTrue("equals", fCheckpoint2.equals(checkpoint2)); } + @Test public void testEqualsTransivity() { final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); final TmfCheckpoint checkpoint2 = new TmfCheckpoint(checkpoint1); @@ -230,6 +225,7 @@ public class TmfCheckpointTest extends TestCase { assertTrue("equals", checkpoint1.equals(checkpoint3)); } + @Test public void testNotEqual() { // Various checkpoints final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, new TmfContext(fLocation1)); @@ -259,6 +255,7 @@ public class TmfCheckpointTest extends TestCase { // toString // ------------------------------------------------------------------------ + @Test public void testToString() { final String expected1 = "TmfCheckpoint [fContext=" + fCheckpoint1.getContext() + ", fTimestamp=" + fCheckpoint1.getTimestamp() + "]"; diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java index 764aa449ae..2358768c92 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,75 +9,62 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adapted for TMF Trace Model 1.0 + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; -import junit.framework.TestCase; +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 org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfTimestampLocation; +import org.junit.Test; /** * Test suite for the TmfContext class. */ @SuppressWarnings({"nls","javadoc"}) -public class TmfContextTest extends TestCase { +public class TmfContextTest { // ------------------------------------------------------------------------ // Variables // ------------------------------------------------------------------------ - final String aString = "some location"; - final Long aLong = 12345L; - final TmfTimestamp aTimestamp = new TmfTimestamp(); + private final String aString = "some location"; + private final Long aLong = 12345L; + private final TmfTimestamp aTimestamp = new TmfTimestamp(); - final TmfStringLocation fLocation1 = new TmfStringLocation(aString); - final TmfLongLocation fLocation2 = new TmfLongLocation(aLong); - final TmfTimestampLocation fLocation3 = new TmfTimestampLocation(aTimestamp); + private final TmfStringLocation fLocation1 = new TmfStringLocation(aString); + private final TmfLongLocation fLocation2 = new TmfLongLocation(aLong); + private final TmfTimestampLocation fLocation3 = new TmfTimestampLocation(aTimestamp); - final long fRank1 = 1; - final long fRank2 = 2; - final long fRank3 = 3; + private final long fRank1 = 1; + private final long fRank2 = 2; + private final long fRank3 = 3; - final TmfContext fContext1 = new TmfContext(fLocation1, fRank1); - final TmfContext fContext2 = new TmfContext(fLocation2, fRank2); - final TmfContext fContext3 = new TmfContext(fLocation3, fRank3); - - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfContextTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } + private final TmfContext fContext1 = new TmfContext(fLocation1, fRank1); + private final TmfContext fContext2 = new TmfContext(fLocation2, fRank2); + private final TmfContext fContext3 = new TmfContext(fLocation3, fRank3); // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ + @Test public void testTmfContextDefault() { final TmfContext context = new TmfContext(); assertEquals("getLocation", null, context.getLocation()); assertEquals("getRank", ITmfContext.UNKNOWN_RANK, context.getRank()); } + @Test public void testTmfContextNoRank() { final TmfContext context1 = new TmfContext(fLocation1); final TmfContext context2 = new TmfContext(fLocation2); @@ -92,6 +79,7 @@ public class TmfContextTest extends TestCase { assertEquals("getRank", ITmfContext.UNKNOWN_RANK, context3.getRank()); } + @Test public void testTmfContext() { assertEquals("getLocation", fLocation1, fContext1.getLocation()); assertEquals("getLocation", fLocation2, fContext2.getLocation()); @@ -102,6 +90,7 @@ public class TmfContextTest extends TestCase { assertEquals("getRank", fRank3, fContext3.getRank()); } + @Test public void testTmfContextCopy() { final TmfContext context1 = new TmfContext(fContext1); final TmfContext context2 = new TmfContext(fContext2); @@ -116,6 +105,7 @@ public class TmfContextTest extends TestCase { assertEquals("getRank", fRank3, context3.getRank()); } + @Test public void testTmfContextCopy2() { try { new TmfContext((TmfContext) null); @@ -133,6 +123,7 @@ public class TmfContextTest extends TestCase { // equals // ------------------------------------------------------------------------ + @Test public void testEqualsReflexivity() { assertTrue("equals", fContext1.equals(fContext1)); assertTrue("equals", fContext2.equals(fContext2)); @@ -141,6 +132,7 @@ public class TmfContextTest extends TestCase { assertFalse("equals", fContext2.equals(fContext1)); } + @Test public void testEqualsSymmetry() { final TmfContext context1 = new TmfContext(fContext1); final TmfContext context2 = new TmfContext(fContext2); @@ -152,6 +144,7 @@ public class TmfContextTest extends TestCase { assertTrue("equals", fContext2.equals(context2)); } + @Test public void testEqualsTransivity() { final TmfContext context1 = new TmfContext(fContext1); final TmfContext context2 = new TmfContext(context1); @@ -162,6 +155,7 @@ public class TmfContextTest extends TestCase { assertTrue("equals", context1.equals(context3)); } + @Test public void testEqualsNull() { assertFalse("equals", fContext1.equals(null)); assertFalse("equals", fContext2.equals(null)); @@ -170,6 +164,7 @@ public class TmfContextTest extends TestCase { private static class MyContext extends TmfContext { } + @Test public void testNonEquals() { // Different classes @@ -202,6 +197,7 @@ public class TmfContextTest extends TestCase { // hashCode // ------------------------------------------------------------------------ + @Test public void testHashCode() { final TmfContext context1 = new TmfContext(fContext1); final TmfContext context2 = new TmfContext(fContext2); @@ -221,6 +217,7 @@ public class TmfContextTest extends TestCase { // toString // ------------------------------------------------------------------------ + @Test public void testToString() { final String expected1 = "TmfContext [fLocation=" + fLocation1 + ", fRank=" + 1 + "]"; final String expected2 = "TmfContext [fLocation=" + fLocation2 + ", fRank=" + 2 + "]"; @@ -235,6 +232,7 @@ public class TmfContextTest extends TestCase { // clone // ------------------------------------------------------------------------ + @Test public void testClone() { try { final TmfContext context1 = fContext1.clone(); @@ -260,6 +258,7 @@ public class TmfContextTest extends TestCase { // setLocation, setRank, updateRank // ------------------------------------------------------------------------ + @Test public void testSetLocation() { final TmfContext context1 = new TmfContext(fContext1); context1.setLocation(fContext2.getLocation()); @@ -268,6 +267,7 @@ public class TmfContextTest extends TestCase { assertEquals("getRank", 1, context1.getRank()); } + @Test public void testSetRank() { final TmfContext context1 = new TmfContext(fContext1); context1.setRank(fContext2.getRank()); @@ -276,6 +276,7 @@ public class TmfContextTest extends TestCase { assertEquals("getRank", fRank2, context1.getRank()); } + @Test public void testIncreaseRank() { final TmfContext context1 = new TmfContext(fContext1); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java index e44f2b1a5b..f439c95f57 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentCheckpointIndexTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson + * Copyright (c) 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,18 +8,20 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.List; -import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; @@ -36,12 +38,15 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfCheckpointIndexTest class. */ @SuppressWarnings({"nls","javadoc"}) -public class TmfExperimentCheckpointIndexTest extends TestCase { +public class TmfExperimentCheckpointIndexTest { // ------------------------------------------------------------------------ // Attributes @@ -61,58 +66,51 @@ public class TmfExperimentCheckpointIndexTest extends TestCase { // Housekeeping // ------------------------------------------------------------------------ - /** - * @param name the test name - */ - public TmfExperimentCheckpointIndexTest(final String name) { - super(name); - } - - @Override - protected synchronized void setUp() throws Exception { - super.setUp(); - if (fExperiment == null) { - setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2); - fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE); - fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); - } + @Before + public void setUp() { + setupTraces(); + fExperiment = new TmfExperimentStub(EXPERIMENT, fTestTraces, BLOCK_SIZE); + fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() { fExperiment.dispose(); fExperiment = null; + for (ITmfTrace trace : fTestTraces) { + trace.dispose(); + } fTestTraces = null; } - private synchronized static ITmfTrace[] setupTrace(final String path1, final String path2) { - if (fTestTraces == null) { - fTestTraces = new ITmfTrace[2]; - try { - URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null); - File test = new File(FileLocator.toFileURL(location).toURI()); - final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true); - fTestTraces[0] = trace1; - location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null); - test = new File(FileLocator.toFileURL(location).toURI()); - final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true); - fTestTraces[1] = trace2; - } catch (final TmfTraceException e) { - e.printStackTrace(); - } catch (final URISyntaxException e) { - e.printStackTrace(); - } catch (final IOException e) { - e.printStackTrace(); - } + private static void setupTraces() { + final String path1 = DIRECTORY + File.separator + TEST_STREAM1; + final String path2 = DIRECTORY + File.separator + TEST_STREAM2; + + fTestTraces = new ITmfTrace[2]; + try { + URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path1), null); + File test = new File(FileLocator.toFileURL(location).toURI()); + final TmfTraceStub trace1 = new TmfTraceStub(test.getPath(), 0, true); + fTestTraces[0] = trace1; + location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path2), null); + test = new File(FileLocator.toFileURL(location).toURI()); + final TmfTraceStub trace2 = new TmfTraceStub(test.getPath(), 0, true); + fTestTraces[1] = trace2; + } catch (final TmfTraceException e) { + e.printStackTrace(); + } catch (final URISyntaxException e) { + e.printStackTrace(); + } catch (final IOException e) { + e.printStackTrace(); } - return fTestTraces; } // ------------------------------------------------------------------------ // Verify checkpoints // ------------------------------------------------------------------------ + @Test @SuppressWarnings("null") public void testTmfTraceIndexing() { assertEquals("getCacheSize", BLOCK_SIZE, fExperiment.getCacheSize()); @@ -148,9 +146,9 @@ public class TmfExperimentCheckpointIndexTest extends TestCase { // Streaming // ------------------------------------------------------------------------ + @Test @SuppressWarnings("null") public void testGrowingIndex() { - ITmfTrace[] testTraces = new TmfTraceStub[2]; try { URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(DIRECTORY + File.separator + TEST_STREAM1), null); @@ -201,6 +199,12 @@ public class TmfExperimentCheckpointIndexTest extends TestCase { assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0)); assertEquals("Checkpoint value", i * pageSize + 1, checkpoint.getTimestamp().getValue()); } + + /* Clean up (since we didn't use the class-specific fixtures) */ + experiment.dispose(); + for (ITmfTrace trace : testTraces) { + trace.dispose(); + } } } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java index 4b9dd815d1..f2dbb426d0 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,10 +9,17 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Trace Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -20,8 +27,6 @@ import java.net.URL; import java.util.Collection; import java.util.Vector; -import junit.framework.TestCase; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; @@ -43,12 +48,14 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfExperiment class (single trace). */ @SuppressWarnings({"nls","javadoc"}) -public class TmfExperimentTest extends TestCase { +public class TmfExperimentTest { // ------------------------------------------------------------------------ // Attributes @@ -60,6 +67,8 @@ public class TmfExperimentTest extends TestCase { private static int NB_EVENTS = 10000; private static int BLOCK_SIZE = 1000; + private static final double DELTA = 1e-15; + private ITmfTrace[] fTestTraces; private TmfExperimentStub fExperiment; @@ -95,31 +104,18 @@ public class TmfExperimentTest extends TestCase { } } - /** - * @param name the test name - */ - public TmfExperimentTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { setupTrace(DIRECTORY + File.separator + TEST_STREAM); setupExperiment(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ + @Test public void testSimpleTmfExperimentConstructor() { - TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, fTestTraces); assertEquals("GetId", EXPERIMENT, experiment.getName()); assertEquals("GetCacheSize", TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, experiment.getCacheSize()); @@ -129,8 +125,8 @@ public class TmfExperimentTest extends TestCase { experiment.dispose(); } + @Test public void testNormalTmfExperimentConstructor() { - assertEquals("GetId", EXPERIMENT, fExperiment.getName()); assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); @@ -149,6 +145,7 @@ public class TmfExperimentTest extends TestCase { // getTimestamp // ------------------------------------------------------------------------ + @Test public void testGetTimestamp() { assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0)); assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1)); @@ -165,6 +162,7 @@ public class TmfExperimentTest extends TestCase { // Bookmarks file handling // ------------------------------------------------------------------------ + @Test public void testBookmarks() { assertNull("GetBookmarksFile", fExperiment.getBookmarksFile()); IFile bookmarks = (IFile) fTestTraces[0].getResource(); @@ -176,18 +174,21 @@ public class TmfExperimentTest extends TestCase { // State system and statistics methods // ------------------------------------------------------------------------ + @Test public void testGetStatistics() { /* There should not be any experiment-specific statistics */ ITmfStatistics stats = fExperiment.getStatistics(); assertNull(stats); } + @Test public void testGetStateSystem() { /* There should not be any experiment-specific state system */ ITmfStateSystem ss = fExperiment.getStateSystem("something"); assertNull(ss); } + @Test public void testListStateSystem() { Collection sss = fExperiment.listStateSystems(); assertNotNull(sss); @@ -198,11 +199,13 @@ public class TmfExperimentTest extends TestCase { // seekEvent by location // ------------------------------------------------------------------------ + @Test public void testSeekBadLocation() { ITmfContext context = fExperiment.seekEvent(new TmfLongLocation(0L)); assertNull("seekEvent", context); } + @Test public void testSeekNoTrace() { TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, EXPERIMENT, null); ITmfContext context = experiment.seekEvent((TmfExperimentLocation) null); @@ -214,8 +217,8 @@ public class TmfExperimentTest extends TestCase { // seekEvent on ratio // ------------------------------------------------------------------------ + @Test public void testSeekEventOnRatio() { - // First event ITmfContext context = fExperiment.seekEvent(0.0); assertEquals("Context rank", 0, context.getRank()); @@ -253,28 +256,28 @@ public class TmfExperimentTest extends TestCase { assertEquals("Context rank", 0, context.getRank()); } + @Test public void testGetLocationRatio() { - // First event ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); double ratio = fExperiment.getLocationRatio(context.getLocation()); context = fExperiment.seekEvent(ratio); double ratio2 = fExperiment.getLocationRatio(context.getLocation()); - assertEquals("getLocationRatio", ratio, ratio2); + assertEquals("getLocationRatio", ratio, ratio2, DELTA); // Middle event context = fExperiment.seekEvent(NB_EVENTS / 2); ratio = fExperiment.getLocationRatio(context.getLocation()); context = fExperiment.seekEvent(ratio); ratio2 = fExperiment.getLocationRatio(context.getLocation()); - assertEquals("getLocationRatio", ratio, ratio2); + assertEquals("getLocationRatio", ratio, ratio2, DELTA); // Last event context = fExperiment.seekEvent(NB_EVENTS - 1); ratio = fExperiment.getLocationRatio(context.getLocation()); context = fExperiment.seekEvent(ratio); ratio2 = fExperiment.getLocationRatio(context.getLocation()); - assertEquals("getLocationRatio", ratio, ratio2); + assertEquals("getLocationRatio", ratio, ratio2, DELTA); } // @SuppressWarnings("rawtypes") @@ -288,8 +291,8 @@ public class TmfExperimentTest extends TestCase { // seekEvent on rank // ------------------------------------------------------------------------ + @Test public void testSeekRankOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // On lower bound, returns the first event (TS = 1) @@ -317,8 +320,8 @@ public class TmfExperimentTest extends TestCase { assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } + @Test public void testSeekRankNotOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event rank 9 @@ -354,8 +357,8 @@ public class TmfExperimentTest extends TestCase { assertEquals("Context rank", 4501, context.getRank()); } + @Test public void testSeekRankOutOfScope() { - // Position trace at beginning ITmfContext context = fExperiment.seekEvent(-1); assertEquals("Event rank", 0, context.getRank()); @@ -377,8 +380,8 @@ public class TmfExperimentTest extends TestCase { // seekEvent on timestamp // ------------------------------------------------------------------------ + @Test public void testSeekTimestampOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event rank 0 @@ -406,8 +409,8 @@ public class TmfExperimentTest extends TestCase { assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } + @Test public void testSeekTimestampNotOnCacheBoundary() { - // Position trace at event rank 1 (TS = 2) ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); assertEquals("Context rank", 1, context.getRank()); @@ -449,8 +452,8 @@ public class TmfExperimentTest extends TestCase { assertEquals("Context rank", 4501, context.getRank()); } + @Test public void testSeekTimestampOutOfScope() { - // Position trace at beginning ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); assertEquals("Event rank", 0, context.getRank()); @@ -470,8 +473,8 @@ public class TmfExperimentTest extends TestCase { // seekEvent by location (context rank is undefined) // ------------------------------------------------------------------------ + @Test public void testSeekLocationOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event rank 0 @@ -505,8 +508,8 @@ public class TmfExperimentTest extends TestCase { assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue()); } + @Test public void testSeekLocationNotOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event 'cacheSize' - 1 @@ -541,8 +544,8 @@ public class TmfExperimentTest extends TestCase { assertEquals("Event timestamp", 4502, event.getTimestamp().getValue()); } + @Test public void testSeekLocationOutOfScope() { - // Position trace at beginning ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); @@ -573,6 +576,7 @@ public class TmfExperimentTest extends TestCase { assertEquals("Experiment context rank", expRank, ctx.getRank()); } + @Test public void testGetNextAfteSeekingOnTS_1() { final long INITIAL_TS = 1; @@ -599,8 +603,8 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfteSeekingOnTS_2() { - final long INITIAL_TS = 2; final int NB_READS = 20; @@ -625,6 +629,7 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfteSeekingOnTS_3() { final long INITIAL_TS = 500; @@ -651,8 +656,8 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnRank_1() { - final long INITIAL_RANK = 0L; final int NB_READS = 20; @@ -677,8 +682,8 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnRank_2() { - final long INITIAL_RANK = 1L; final int NB_READS = 20; @@ -703,8 +708,8 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnRank_3() { - final long INITIAL_RANK = 500L; final int NB_READS = 20; @@ -729,8 +734,8 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnLocation_1() { - final ITmfLocation INITIAL_LOC = null; final long INITIAL_TS = 1; final int NB_READS = 20; @@ -756,8 +761,8 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnLocation_2() { - final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(1L).getLocation(); final long INITIAL_TS = 2; final int NB_READS = 20; @@ -781,8 +786,8 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnLocation_3() { - final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(500L).getLocation(); final long INITIAL_TS = 501; final int NB_READS = 20; @@ -806,6 +811,7 @@ public class TmfExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextLocation() { ITmfContext context1 = fExperiment.seekEvent(0); fExperiment.getNext(context1); @@ -816,6 +822,7 @@ public class TmfExperimentTest extends TestCase { assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); } + @Test public void testGetNextEndLocation() { ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); fExperiment.getNext(context1); @@ -829,8 +836,8 @@ public class TmfExperimentTest extends TestCase { // processRequest // ------------------------------------------------------------------------ + @Test public void testProcessRequestForNbEvents() throws InterruptedException { - final int blockSize = 100; final int nbEvents = 1000; final Vector requestedEvents = new Vector(); @@ -857,8 +864,8 @@ public class TmfExperimentTest extends TestCase { } } + @Test public void testProcessRequestForNbEvents2() throws InterruptedException { - final int blockSize = 2 * NB_EVENTS; final int nbEvents = 1000; final Vector requestedEvents = new Vector(); @@ -885,8 +892,8 @@ public class TmfExperimentTest extends TestCase { } } + @Test public void testProcessRequestForAllEvents() throws InterruptedException { - final int nbEvents = TmfDataRequest.ALL_DATA; final int blockSize = 1; final Vector requestedEvents = new Vector(); @@ -918,8 +925,8 @@ public class TmfExperimentTest extends TestCase { // cancel // ------------------------------------------------------------------------ + @Test public void testCancel() throws InterruptedException { - final int nbEvents = NB_EVENTS; final int blockSize = BLOCK_SIZE; final Vector requestedEvents = new Vector(); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java index dc47e9d8a3..f091cd9fc0 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,66 +8,59 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; -import junit.framework.TestCase; +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 org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfLongLocation; import org.eclipse.linuxtools.tmf.core.trace.TmfTimestampLocation; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfLocation class. */ @SuppressWarnings({"nls","javadoc"}) -public class TmfLocationTest extends TestCase { +public class TmfLocationTest { // ------------------------------------------------------------------------ // Variables // ------------------------------------------------------------------------ - String aString = "some location"; - Long aLong = 12345L; - TmfTimestamp aTimestamp = new TmfTimestamp(); + private String aString = "some location"; + private Long aLong = 12345L; + private TmfTimestamp aTimestamp = new TmfTimestamp(); - TmfStringLocation fLocation1; - TmfStringLocation fLocation2; - TmfLongLocation fLocation3; - TmfTimestampLocation fLocation4; + private TmfStringLocation fLocation1; + private TmfStringLocation fLocation2; + private TmfLongLocation fLocation3; + private TmfTimestampLocation fLocation4; // ------------------------------------------------------------------------ // Housekeeping // ------------------------------------------------------------------------ - /** - * @param name - * the test name - */ - public TmfLocationTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { fLocation1 = new TmfStringLocation((String) null); fLocation2 = new TmfStringLocation(aString); fLocation3 = new TmfLongLocation(aLong); fLocation4 = new TmfTimestampLocation(aTimestamp); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ + @Test public void testTmfLocation() { assertNull("TmfLocation", fLocation1.getLocationInfo()); assertEquals("TmfLocation", aString, fLocation2.getLocationInfo()); @@ -75,6 +68,7 @@ public class TmfLocationTest extends TestCase { assertEquals("TmfLocation", aTimestamp, fLocation4.getLocationInfo()); } + @Test public void testTmfLocationCopy() { TmfStringLocation location1 = new TmfStringLocation(fLocation1); TmfStringLocation location2 = new TmfStringLocation(fLocation2); @@ -91,6 +85,7 @@ public class TmfLocationTest extends TestCase { // hashCode // ------------------------------------------------------------------------ + @Test public void testHashCode() { TmfStringLocation location1 = new TmfStringLocation((String) null); TmfStringLocation location2 = new TmfStringLocation(aString); @@ -114,6 +109,7 @@ public class TmfLocationTest extends TestCase { } } + @Test public void testEqualsWrongTypes() { ITmfLocation location1 = new TmfStringLocation(aString); TmfLocation2 location2 = new TmfLocation2(aString); @@ -122,6 +118,7 @@ public class TmfLocationTest extends TestCase { assertFalse("equals", location2.equals(location1)); } + @Test public void testEqualsWithNulls() { TmfStringLocation location1 = new TmfStringLocation(aString); TmfStringLocation location2 = new TmfStringLocation((String) null); @@ -130,6 +127,7 @@ public class TmfLocationTest extends TestCase { assertFalse("equals", location2.equals(location1)); } + @Test public void testEqualsReflexivity() { assertTrue("equals", fLocation2.equals(fLocation2)); assertTrue("equals", fLocation3.equals(fLocation3)); @@ -138,6 +136,7 @@ public class TmfLocationTest extends TestCase { assertTrue("equals", !fLocation3.equals(fLocation2)); } + @Test public void testEqualsSymmetry() { TmfStringLocation location2 = new TmfStringLocation(aString); TmfLongLocation location3 = new TmfLongLocation(aLong); @@ -149,6 +148,7 @@ public class TmfLocationTest extends TestCase { assertTrue("equals", fLocation3.equals(location3)); } + @Test public void testEqualsTransivity() { TmfStringLocation location1 = new TmfStringLocation(aString); TmfStringLocation location2 = new TmfStringLocation(aString); @@ -159,6 +159,7 @@ public class TmfLocationTest extends TestCase { assertTrue("equals", location3.equals(location1)); } + @Test public void testEqualsNull() { assertTrue("equals", !fLocation2.equals(null)); assertTrue("equals", !fLocation2.equals(null)); @@ -168,19 +169,19 @@ public class TmfLocationTest extends TestCase { // toString // ------------------------------------------------------------------------ - @SuppressWarnings("hiding") + @Test public void testToString() { - String aString = "some location"; - Long aLong = 12345L; - TmfTimestamp aTimestamp = new TmfTimestamp(); + String str = "some location"; + Long lng = 12345L; + TmfTimestamp ts = new TmfTimestamp(); - TmfStringLocation location1 = new TmfStringLocation(aString); - TmfLongLocation location2 = new TmfLongLocation(aLong); - TmfTimestampLocation location3 = new TmfTimestampLocation(aTimestamp); + TmfStringLocation location1 = new TmfStringLocation(str); + TmfLongLocation location2 = new TmfLongLocation(lng); + TmfTimestampLocation location3 = new TmfTimestampLocation(ts); - String expected1 = "TmfLocation [fLocation=" + aString + "]"; - String expected2 = "TmfLocation [fLocation=" + aLong + "]"; - String expected3 = "TmfLocation [fLocation=" + aTimestamp + "]"; + String expected1 = "TmfLocation [fLocation=" + str + "]"; + String expected2 = "TmfLocation [fLocation=" + lng + "]"; + String expected3 = "TmfLocation [fLocation=" + ts + "]"; assertEquals("toString", expected1, location1.toString()); assertEquals("toString", expected2, location2.toString()); diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java index 84dae11f6c..33fac1a74b 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfMultiTraceExperimentTest.java @@ -9,18 +9,22 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adjusted for new Trace Model + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; +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 java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.Vector; -import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; @@ -37,16 +41,19 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfExperiment class (multiple traces). */ @SuppressWarnings({"nls","javadoc"}) -public class TmfMultiTraceExperimentTest extends TestCase { +public class TmfMultiTraceExperimentTest { // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ + private static final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec private static final String DIRECTORY = "testfiles"; private static final String TEST_STREAM1 = "O-Test-10K"; @@ -64,6 +71,15 @@ public class TmfMultiTraceExperimentTest extends TestCase { // Housekeeping // ------------------------------------------------------------------------ + @Before + public void setUp() { + setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2); + if (fExperiment == null) { + fExperiment = new TmfExperimentStub(EXPERIMENT, fTraces, BLOCK_SIZE); + fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); + } + } + private synchronized static ITmfTrace[] setupTrace(final String path1, final String path2) { if (fTraces == null) { fTraces = new ITmfTrace[2]; @@ -90,34 +106,12 @@ public class TmfMultiTraceExperimentTest extends TestCase { return fTraces; } - /** - * @param name the test name - */ - public TmfMultiTraceExperimentTest(final String name) { - super(name); - } - - @Override - protected synchronized void setUp() throws Exception { - super.setUp(); - setupTrace(DIRECTORY + File.separator + TEST_STREAM1, DIRECTORY + File.separator + TEST_STREAM2); - if (fExperiment == null) { - fExperiment = new TmfExperimentStub(EXPERIMENT, fTraces, BLOCK_SIZE); - fExperiment.getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true); - } - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ + @Test public void testBasicTmfExperimentConstructor() { - assertEquals("GetId", EXPERIMENT, fExperiment.getName()); assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents()); @@ -140,8 +134,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { // seekEvent on rank // ------------------------------------------------------------------------ + @Test public void testSeekRankOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // On lower bound, returns the first event (TS = 1) @@ -169,8 +163,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } + @Test public void testSeekRankNotOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event rank 9 @@ -206,8 +200,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Context rank", 4501, context.getRank()); } + @Test public void testSeekRankOutOfScope() { - // Position trace at beginning ITmfContext context = fExperiment.seekEvent(-1); assertEquals("Event rank", 0, context.getRank()); @@ -229,8 +223,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { // seekEvent on timestamp // ------------------------------------------------------------------------ + @Test public void testSeekTimestampOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event rank 0 @@ -258,8 +252,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Context rank", 4 * cacheSize + 1, context.getRank()); } + @Test public void testSeekTimestampNotOnCacheBoundary() { - // Position trace at event rank 1 (TS = 2) ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(2, SCALE, 0)); assertEquals("Context rank", 1, context.getRank()); @@ -301,8 +295,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Context rank", 4501, context.getRank()); } + @Test public void testSeekTimestampOutOfScope() { - // Position trace at beginning ITmfContext context = fExperiment.seekEvent(new TmfTimestamp(-1, SCALE, 0)); assertEquals("Event rank", 0, context.getRank()); @@ -322,8 +316,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { // seekEvent by location (context rank is undefined) // ------------------------------------------------------------------------ + @Test public void testSeekLocationOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event rank 0 @@ -357,8 +351,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Event timestamp", 4 * cacheSize + 2, event.getTimestamp().getValue()); } + @Test public void testSeekLocationNotOnCacheBoundary() { - long cacheSize = fExperiment.getCacheSize(); // Position trace at event 'cacheSize' - 1 @@ -393,8 +387,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Event timestamp", 4502, event.getTimestamp().getValue()); } + @Test public void testSeekLocationOutOfScope() { - // Position trace at beginning ITmfContext context = fExperiment.seekEvent((ITmfLocation) null); @@ -425,8 +419,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Experiment context rank", expRank, ctx.getRank()); } + @Test public void testGetNextAfteSeekingOnTS_1() { - final long INITIAL_TS = 1; final int NB_READS = 20; @@ -451,8 +445,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfteSeekingOnTS_2() { - final long INITIAL_TS = 2; final int NB_READS = 20; @@ -477,8 +471,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfteSeekingOnTS_3() { - final long INITIAL_TS = 500; final int NB_READS = 20; @@ -503,8 +497,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnRank_1() { - final long INITIAL_RANK = 0L; final int NB_READS = 20; @@ -529,8 +523,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnRank_2() { - final long INITIAL_RANK = 1L; final int NB_READS = 20; @@ -555,8 +549,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnRank_3() { - final long INITIAL_RANK = 500L; final int NB_READS = 20; @@ -581,8 +575,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnLocation_1() { - final ITmfLocation INITIAL_LOC = null; final long INITIAL_TS = 1; final int NB_READS = 20; @@ -608,8 +602,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnLocation_2() { - final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(1L).getLocation(); final long INITIAL_TS = 2; final int NB_READS = 20; @@ -633,8 +627,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextAfterSeekingOnLocation_3() { - final ITmfLocation INITIAL_LOC = fExperiment.seekEvent(500L).getLocation(); final long INITIAL_TS = 501; final int NB_READS = 20; @@ -658,6 +652,7 @@ public class TmfMultiTraceExperimentTest extends TestCase { validateContextRanks(context); } + @Test public void testGetNextLocation() { ITmfContext context1 = fExperiment.seekEvent(0); fExperiment.getNext(context1); @@ -668,6 +663,7 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); } + @Test public void testGetNextEndLocation() { ITmfContext context1 = fExperiment.seekEvent(fExperiment.getNbEvents() - 1); fExperiment.getNext(context1); @@ -681,8 +677,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { // processRequest // ------------------------------------------------------------------------ + @Test public void testProcessRequestForNbEvents() throws InterruptedException { - final int blockSize = 100; final int nbEvents = 1000; final Vector requestedEvents = new Vector(); @@ -709,8 +705,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { } } + @Test public void testProcessRequestForNbEvents2() throws InterruptedException { - final int blockSize = 2 * NB_EVENTS; final int nbEvents = 1000; final Vector requestedEvents = new Vector(); @@ -737,8 +733,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { } } + @Test public void testProcessRequestForAllEvents() throws InterruptedException { - final int nbEvents = TmfDataRequest.ALL_DATA; final int blockSize = 1; final Vector requestedEvents = new Vector(); @@ -770,8 +766,8 @@ public class TmfMultiTraceExperimentTest extends TestCase { // cancel // ------------------------------------------------------------------------ + @Test public void testCancel() throws InterruptedException { - final int nbEvents = NB_EVENTS; final int blockSize = BLOCK_SIZE; final Vector requestedEvents = new Vector(); @@ -806,6 +802,7 @@ public class TmfMultiTraceExperimentTest extends TestCase { // getTimestamp // ------------------------------------------------------------------------ + @Test public void testGetTimestamp() { assertEquals("getTimestamp", new TmfTimestamp( 1, (byte) -3), fExperiment.getTimestamp( 0)); assertEquals("getTimestamp", new TmfTimestamp( 2, (byte) -3), fExperiment.getTimestamp( 1)); @@ -823,6 +820,7 @@ public class TmfMultiTraceExperimentTest extends TestCase { // getInitialRangeOffset, getCurrentRange, getCurrentTime // ------------------------------------------------------------------------ + @Test public void testDefaultCurrentTimeValues() { // reset to default initial range offset ((TmfTraceStub)fTraces[0]).setInitialRangeOffset(null); @@ -835,6 +833,6 @@ public class TmfMultiTraceExperimentTest extends TestCase { assertEquals("getInitialRangeOffset", initRange, exp.getInitialRangeOffset()); assertEquals("getCurrentTime", TmfTimestamp.ZERO, exp.getCurrentTime()); assertEquals("getCurrentRange", TmfTimeRange.NULL_RANGE, exp.getCurrentRange()); - } + } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java index 8260ab03dd..482ceb5ca7 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson + * Copyright (c) 2009, 2010, 2012, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -9,10 +9,18 @@ * Contributors: * Francois Chouinard - Initial API and implementation * Francois Chouinard - Adapted for TMF Trace Model 1.0 + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.trace; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -20,8 +28,6 @@ import java.net.URL; import java.util.Collection; import java.util.Vector; -import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager; @@ -42,16 +48,20 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer; import org.eclipse.linuxtools.tmf.core.trace.TmfContext; import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test suite for the TmfTrace class. */ @SuppressWarnings({"nls","javadoc"}) -public class TmfTraceTest extends TestCase { +public class TmfTraceTest { // ------------------------------------------------------------------------ // Variables // ------------------------------------------------------------------------ + private static final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec private static final String DIRECTORY = "testfiles"; private static final String TEST_STREAM = "A-Test-10K"; @@ -65,22 +75,13 @@ public class TmfTraceTest extends TestCase { // Housekeeping // ------------------------------------------------------------------------ - /** - * @param name the test name - */ - public TmfTraceTest(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() { fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() { fTrace.dispose(); fTrace = null; } @@ -111,6 +112,7 @@ public class TmfTraceTest extends TestCase { // Constructors // ------------------------------------------------------------------------ + @Test @SuppressWarnings("null") public void testStandardConstructor() throws TmfTraceException { TmfTraceStub trace = null; @@ -141,6 +143,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); } + @Test @SuppressWarnings("null") public void testStandardConstructorCacheSize() throws TmfTraceException { TmfTraceStub trace = null; @@ -195,6 +198,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); } + @Test @SuppressWarnings("null") public void testFullConstructor() throws TmfTraceException { TmfTraceStub trace = null; @@ -225,6 +229,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); } + @Test @SuppressWarnings("null") public void testLiveTraceConstructor() throws TmfTraceException { TmfTraceStub trace = null; @@ -256,6 +261,7 @@ public class TmfTraceTest extends TestCase { assertEquals("getEndTime", NB_EVENTS, trace.getEndTime().getValue()); } + @Test @SuppressWarnings("null") public void testCopyConstructor() throws TmfTraceException { TmfTraceStub original = null; @@ -302,8 +308,8 @@ public class TmfTraceTest extends TestCase { // Trace initialization // ------------------------------------------------------------------------ + @Test public void testInitializeNullPath() { - // Instantiate an "empty" trace final TmfTraceStub trace = new TmfTraceStub(); @@ -317,8 +323,8 @@ public class TmfTraceTest extends TestCase { } } + @Test public void testInitializeSimplePath() { - // Instantiate an "empty" trace final TmfTraceStub trace = new TmfTraceStub(); @@ -344,8 +350,8 @@ public class TmfTraceTest extends TestCase { assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); } + @Test public void testInitializeNormalPath() { - // Instantiate an "empty" trace final TmfTraceStub trace = new TmfTraceStub(); @@ -372,8 +378,8 @@ public class TmfTraceTest extends TestCase { assertEquals("getEndTime", Long.MIN_VALUE, trace.getEndTime().getValue()); } + @Test public void testInitTrace() throws URISyntaxException, IOException, TmfTraceException, InterruptedException { - // Instantiate an "empty" trace final TmfTraceStub trace = new TmfTraceStub(); @@ -423,6 +429,7 @@ public class TmfTraceTest extends TestCase { // Set/Get streaming interval // ------------------------------------------------------------------------ + @Test public void testSetStreamingInterval() throws TmfTraceException { final TmfTraceStub trace = new TmfTraceStub(fTrace); @@ -448,6 +455,7 @@ public class TmfTraceTest extends TestCase { // Set/Get time range // ------------------------------------------------------------------------ + @Test public void testSetTimeRange() throws TmfTraceException { final TmfTraceStub trace = new TmfTraceStub(fTrace); trace.indexTrace(); @@ -466,6 +474,7 @@ public class TmfTraceTest extends TestCase { trace.dispose(); } + @Test public void testSetStartTime() throws TmfTraceException { final TmfTraceStub trace = new TmfTraceStub(fTrace); trace.indexTrace(); @@ -484,6 +493,7 @@ public class TmfTraceTest extends TestCase { trace.dispose(); } + @Test public void testSetEndTime() throws TmfTraceException { final TmfTraceStub trace = new TmfTraceStub(fTrace); trace.indexTrace(); @@ -502,6 +512,7 @@ public class TmfTraceTest extends TestCase { trace.dispose(); } + @Test public void testSetNbEvents() throws TmfTraceException { final TmfTraceStub trace = new TmfTraceStub(fTrace); trace.indexTrace(); @@ -527,18 +538,21 @@ public class TmfTraceTest extends TestCase { // State system and statistics methods // ------------------------------------------------------------------------ + @Test public void testGetStatistics() { /* Should be null in unit tests */ ITmfStatistics stats = fTrace.getStatistics(); assertNull(stats); } + @Test public void testGetStateSystem() { /* There should be no state system registered so far */ ITmfStateSystem ss = fTrace.getStateSystem("something"); assertNull(ss); } + @Test public void testListStateSystem() { Collection sss = fTrace.listStateSystems(); assertNotNull(sss); @@ -549,8 +563,8 @@ public class TmfTraceTest extends TestCase { // seekEvent on location (note: does not reliably set the rank) // ------------------------------------------------------------------------ + @Test public void testSeekEventOnCacheBoundary() { - // Position trace at event rank 0 ITmfContext context = fTrace.seekEvent(0); ITmfEvent event = fTrace.parseEvent(context); @@ -595,8 +609,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); } + @Test public void testSeekEventNotOnCacheBoundary() { - // Position trace at event rank 9 ITmfContext tmpContext = fTrace.seekEvent(new TmfTimestamp(10, SCALE, 0)); TmfContext context = fTrace.seekEvent(tmpContext.getLocation()); @@ -650,8 +664,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", ITmfContext.UNKNOWN_RANK, context.getRank()); } + @Test public void testSeekEventOutOfScope() { - // Position trace at beginning ITmfContext tmpContext = fTrace.seekEvent(0); ITmfContext context = fTrace.seekEvent(tmpContext.getLocation()); @@ -678,8 +692,8 @@ public class TmfTraceTest extends TestCase { // seekEvent on timestamp (note: does not reliably set the rank) // ------------------------------------------------------------------------ + @Test public void testSeekEventOnNullTimestamp() { - // Position trace at event rank 0 ITmfContext context = fTrace.seekEvent((ITmfTimestamp) null); assertEquals("Event rank", 0, context.getRank()); @@ -689,8 +703,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", 0, context.getRank()); } + @Test public void testSeekEventOnTimestampOnCacheBoundary() { - // Position trace at event rank 0 ITmfContext context = fTrace.seekEvent(new TmfTimestamp(1, SCALE, 0)); assertEquals("Event rank", 0, context.getRank()); @@ -728,8 +742,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", 4001, context.getRank()); } + @Test public void testSeekEventOnTimestampNotOnCacheBoundary() { - // Position trace at event rank 1 ITmfContext context = fTrace.seekEvent(new TmfTimestamp(2, SCALE, 0)); assertEquals("Event rank", 1, context.getRank()); @@ -791,8 +805,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", 4501, context.getRank()); } + @Test public void testSeekEventOnTimestampOutOfScope() { - // Position trace at beginning ITmfContext context = fTrace.seekEvent(new TmfTimestamp(-1, SCALE, 0)); assertEquals("Event rank", 0, context.getRank()); @@ -822,8 +836,8 @@ public class TmfTraceTest extends TestCase { // seekEvent on rank // ------------------------------------------------------------------------ + @Test public void testSeekEventOnNegativeRank() { - // Position trace at event rank 0 ITmfContext context = fTrace.seekEvent(-1); assertEquals("Event rank", 0, context.getRank()); @@ -833,8 +847,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", 0, context.getRank()); } + @Test public void testSeekOnRankOnCacheBoundary() { - // On lower bound, returns the first event (ts = 1) ITmfContext context = fTrace.seekEvent(0); assertEquals("Event rank", 0, context.getRank()); @@ -872,8 +886,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", 4001, context.getRank()); } + @Test public void testSeekOnRankNotOnCacheBoundary() { - // Position trace at event rank 9 ITmfContext context = fTrace.seekEvent(9); assertEquals("Event rank", 9, context.getRank()); @@ -923,8 +937,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", 4501, context.getRank()); } + @Test public void testSeekEventOnRankOutOfScope() { - // Position trace at beginning ITmfContext context = fTrace.seekEvent(-1); assertEquals("Event rank", 0, context.getRank()); @@ -954,8 +968,8 @@ public class TmfTraceTest extends TestCase { // parseEvent - make sure parseEvent doesn't update the context // ------------------------------------------------------------------------ + @Test public void testParseEvent() { - final int NB_READS = 20; // On lower bound, returns the first event (ts = 0) @@ -999,8 +1013,8 @@ public class TmfTraceTest extends TestCase { // getNext - updates the context // ------------------------------------------------------------------------ + @Test public void testGetNextAfteSeekingOnTS_1() { - final long INITIAL_TS = 1; final int NB_READS = 20; @@ -1021,8 +1035,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); } + @Test public void testGetNextAfteSeekingOnTS_2() { - final long INITIAL_TS = 2; final int NB_READS = 20; @@ -1043,8 +1057,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); } + @Test public void testGetNextAfteSeekingOnTS_3() { - final long INITIAL_TS = 500; final int NB_READS = 20; @@ -1065,8 +1079,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); } + @Test public void testGetNextAfterSeekingOnRank_1() { - final long INITIAL_RANK = 0L; final int NB_READS = 20; @@ -1087,8 +1101,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); } + @Test public void testGetNextAfterSeekingOnRank_2() { - final long INITIAL_RANK = 1L; final int NB_READS = 20; @@ -1109,8 +1123,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); } + @Test public void testGetNextAfterSeekingOnRank_3() { - final long INITIAL_RANK = 500L; final int NB_READS = 20; @@ -1131,8 +1145,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", INITIAL_RANK + NB_READS, context.getRank()); } + @Test public void testGetNextAfterSeekingOnLocation_1() { - final ITmfLocation INITIAL_LOC = null; final long INITIAL_TS = 1; final int NB_READS = 20; @@ -1154,8 +1168,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event rank", INITIAL_TS + NB_READS - 1, context.getRank()); } + @Test public void testGetNextAfterSeekingOnLocation_2() { - final ITmfLocation INITIAL_LOC = fTrace.seekEvent(1L).getLocation(); final long INITIAL_TS = 2; final int NB_READS = 20; @@ -1175,8 +1189,8 @@ public class TmfTraceTest extends TestCase { assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); } + @Test public void testGetNextAfterSeekingOnLocation_3() { - final ITmfLocation INITIAL_LOC = fTrace.seekEvent(500L).getLocation(); final long INITIAL_TS = 501; final int NB_READS = 20; @@ -1196,6 +1210,7 @@ public class TmfTraceTest extends TestCase { assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue()); } + @Test public void testGetNextLocation() { ITmfContext context1 = fTrace.seekEvent(0); fTrace.getNext(context1); @@ -1206,6 +1221,7 @@ public class TmfTraceTest extends TestCase { assertEquals("Event timestamp", event1.getTimestamp().getValue(), event2.getTimestamp().getValue()); } + @Test public void testGetNextEndLocation() { ITmfContext context1 = fTrace.seekEvent(fTrace.getNbEvents() - 1); fTrace.getNext(context1); @@ -1219,13 +1235,13 @@ public class TmfTraceTest extends TestCase { // processRequest // ------------------------------------------------------------------------ - @SuppressWarnings("hiding") + @Test public void testProcessEventRequestForAllEvents() throws InterruptedException { - final int BLOCK_SIZE = 1; + final int blockSize = 1; final Vector requestedEvents = new Vector(); final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); - final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { + final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, blockSize) { @Override public void handleData(final ITmfEvent event) { super.handleData(event); @@ -1247,14 +1263,14 @@ public class TmfTraceTest extends TestCase { } } - @SuppressWarnings("hiding") + @Test public void testProcessEventRequestForNbEvents() throws InterruptedException { - final int BLOCK_SIZE = 100; - final int NB_EVENTS = 1000; + final int blockSize = 100; + final int nbEvents = 1000; final Vector requestedEvents = new Vector(); final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); - final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { + final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { @Override public void handleData(final ITmfEvent event) { super.handleData(event); @@ -1265,26 +1281,26 @@ public class TmfTraceTest extends TestCase { providers[0].sendRequest(request); request.waitForCompletion(); - assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); + assertEquals("nbEvents", nbEvents, requestedEvents.size()); assertTrue("isCompleted", request.isCompleted()); assertFalse("isCancelled", request.isCancelled()); // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < NB_EVENTS; i++) { + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", i + 1, requestedEvents.get(i).getTimestamp().getValue()); } } - @SuppressWarnings("hiding") + @Test public void testProcessEventRequestForSomeEvents() throws InterruptedException { - final int BLOCK_SIZE = 1; + final int blockSize = 1; final long startTime = 100; - final int NB_EVENTS = 1000; + final int nbEvents = 1000; final Vector requestedEvents = new Vector(); final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); - final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, NB_EVENTS, BLOCK_SIZE) { + final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, nbEvents, blockSize) { @Override public void handleData(final ITmfEvent event) { super.handleData(event); @@ -1295,27 +1311,27 @@ public class TmfTraceTest extends TestCase { providers[0].sendRequest(request); request.waitForCompletion(); - assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); + assertEquals("nbEvents", nbEvents, requestedEvents.size()); assertTrue("isCompleted", request.isCompleted()); assertFalse("isCancelled", request.isCancelled()); // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < NB_EVENTS; i++) { + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); } } - @SuppressWarnings("hiding") + @Test public void testProcessEventRequestForOtherEvents() throws InterruptedException { - final int BLOCK_SIZE = 1; + final int blockSize = 1; final int startIndex = 99; final long startTime = 100; - final int NB_EVENTS = 1000; + final int nbEvents = 1000; final Vector requestedEvents = new Vector(); final TmfTimeRange range = new TmfTimeRange(new TmfTimestamp(startTime, SCALE), TmfTimestamp.BIG_CRUNCH); - final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, startIndex, NB_EVENTS, BLOCK_SIZE) { + final TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, range, startIndex, nbEvents, blockSize) { @Override public void handleData(final ITmfEvent event) { super.handleData(event); @@ -1326,24 +1342,24 @@ public class TmfTraceTest extends TestCase { providers[0].sendRequest(request); request.waitForCompletion(); - assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); + assertEquals("nbEvents", nbEvents, requestedEvents.size()); assertTrue("isCompleted", request.isCompleted()); assertFalse("isCancelled", request.isCancelled()); // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < NB_EVENTS; i++) { + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", startTime + i, requestedEvents.get(i).getTimestamp().getValue()); } } - @SuppressWarnings("hiding") + @Test public void testProcessDataRequestForSomeEvents() throws InterruptedException { final int startIndex = 100; - final int NB_EVENTS = 1000; + final int nbEvents = 1000; final Vector requestedEvents = new Vector(); - final TmfDataRequest request = new TmfDataRequest(ITmfEvent.class, startIndex, NB_EVENTS) { + final TmfDataRequest request = new TmfDataRequest(ITmfEvent.class, startIndex, nbEvents) { @Override public void handleData(final ITmfEvent event) { super.handleData(event); @@ -1354,13 +1370,13 @@ public class TmfTraceTest extends TestCase { providers[0].sendRequest(request); request.waitForCompletion(); - assertEquals("nbEvents", NB_EVENTS, requestedEvents.size()); + assertEquals("nbEvents", nbEvents, requestedEvents.size()); assertTrue("isCompleted", request.isCompleted()); assertFalse("isCancelled", request.isCancelled()); // Ensure that we have distinct events. // Don't go overboard: we are not validating the stub! - for (int i = 0; i < NB_EVENTS; i++) { + for (int i = 0; i < nbEvents; i++) { assertEquals("Distinct events", startIndex + 1 + i, requestedEvents.get(i).getTimestamp().getValue()); } } @@ -1369,6 +1385,7 @@ public class TmfTraceTest extends TestCase { // cancel // ------------------------------------------------------------------------ + @Test public void testCancel() throws InterruptedException { final Vector requestedEvents = new Vector(); @@ -1397,6 +1414,7 @@ public class TmfTraceTest extends TestCase { // toString // ------------------------------------------------------------------------ + @Test public void testDefaultTmfTraceStub() { assertFalse ("Open trace", fTrace == null); assertEquals("getType", ITmfEvent.class, fTrace.getType()); @@ -1421,6 +1439,8 @@ public class TmfTraceTest extends TestCase { // ------------------------------------------------------------------------ // getInitialRangeOffset, getCurrentRange, getCurrentTime // ------------------------------------------------------------------------ + + @Test @SuppressWarnings("null") public void testCurrentTimeValues() throws TmfTraceException { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/AllTests.java index a2bda98da9..0fb01f8e78 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/AllTests.java @@ -1,29 +1,28 @@ -package org.eclipse.linuxtools.tmf.core.tests.uml2sd; +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Port to JUnit4 + *******************************************************************************/ -import junit.framework.Test; -import junit.framework.TestSuite; +package org.eclipse.linuxtools.tmf.core.tests.uml2sd; -import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** - * AllTests - *

- * Implement me. Please. - *

+ * Unit tests for tmf.core.uml2sd */ -@SuppressWarnings({ "nls" }) +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TmfAsyncSequenceDiagramEventTest.class, + TmfSyncSequenceDiagramEventTest.class +}) public class AllTests { - /** - * @return the test suite - */ - public static Test suite() { - TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".uml2sd"); //$NON-NLS-1$); - //$JUnit-BEGIN$ - suite.addTestSuite(TmfSyncSequenceDiagramEventTest.class); - suite.addTestSuite(TmfAsyncSequenceDiagramEventTest.class); - //$JUnit-END$ - return suite; - } - } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfAsyncSequenceDiagramEventTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfAsyncSequenceDiagramEventTest.java index b1b80b1158..a3e43c5339 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfAsyncSequenceDiagramEventTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfAsyncSequenceDiagramEventTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Ericsson + * Copyright (c) 2011, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,10 +8,14 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ + package org.eclipse.linuxtools.tmf.core.tests.uml2sd; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; @@ -22,14 +26,13 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEventType; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.uml2sd.TmfAsyncSequenceDiagramEvent; +import org.junit.Test; + /** - * TmfAsyncSequenceDiagramEventTest - *

- * Implement me. Please. - *

+ * TmfAsyncSequenceDiagramEventTest */ -@SuppressWarnings({"nls","javadoc"}) -public class TmfAsyncSequenceDiagramEventTest extends TestCase { +@SuppressWarnings("nls") +public class TmfAsyncSequenceDiagramEventTest { private final String fContext = ITmfEventType.DEFAULT_CONTEXT_ID; private final String fTypeId = "Some type"; @@ -48,7 +51,9 @@ public class TmfAsyncSequenceDiagramEventTest extends TestCase { private final TmfEventField fContent1; private final TmfEventField fContent2; - + /** + * Constructor for the test case + */ public TmfAsyncSequenceDiagramEventTest() { fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some content"); fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType, fContent1, fReference); @@ -57,14 +62,10 @@ public class TmfAsyncSequenceDiagramEventTest extends TestCase { fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType, fContent2, fReference); } - @Override - public void setUp() throws Exception { - } - - @Override - public void tearDown() throws Exception { - } - + /** + * Main test + */ + @Test public void testTmfAsyncSequenceDiagramEvent() { TmfAsyncSequenceDiagramEvent event = null; diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfSyncSequenceDiagramEventTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfSyncSequenceDiagramEventTest.java index 5f1f44d07a..f14840f744 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfSyncSequenceDiagramEventTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/uml2sd/TmfSyncSequenceDiagramEventTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Ericsson + * Copyright (c) 2011, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,10 +8,14 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ + package org.eclipse.linuxtools.tmf.core.tests.uml2sd; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; @@ -22,14 +26,13 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEventType; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.uml2sd.TmfSyncSequenceDiagramEvent; +import org.junit.Test; + /** - * TmfSyncSequenceDiagramEventTest - *

- * Implement me. Please. - *

+ * TmfSyncSequenceDiagramEventTest */ -@SuppressWarnings({"nls","javadoc"}) -public class TmfSyncSequenceDiagramEventTest extends TestCase { +@SuppressWarnings("nls") +public class TmfSyncSequenceDiagramEventTest { private final String fContext = ITmfEventType.DEFAULT_CONTEXT_ID; private final String fTypeId = "Some type"; @@ -45,19 +48,18 @@ public class TmfSyncSequenceDiagramEventTest extends TestCase { private final ITmfEvent fEvent1; private final TmfEventField fContent1; - public TmfSyncSequenceDiagramEventTest () { + /** + * Constructor for the test case + */ + public TmfSyncSequenceDiagramEventTest() { fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some content"); fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType, fContent1, fReference); } - @Override - public void setUp() throws Exception { - } - - @Override - public void tearDown() throws Exception { - } - + /** + * Main test + */ + @Test public void testTmfSyncSequenceDiagramEvent() { TmfSyncSequenceDiagramEvent event = null; try { diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/AllTests.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/AllTests.java index 3f49f21119..172d2b44a1 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/AllTests.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/AllTests.java @@ -1,26 +1,27 @@ -package org.eclipse.linuxtools.tmf.core.tests.util; +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Port to JUnit4 + *******************************************************************************/ -import junit.framework.Test; -import junit.framework.TestSuite; +package org.eclipse.linuxtools.tmf.core.tests.util; -import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; /** - * AllTests - *

- *

+ * Unit tests for tmf.core.util */ -@SuppressWarnings({ "nls" }) +@RunWith(Suite.class) +@Suite.SuiteClasses({ + PairTest.class +}) public class AllTests { - /** - * @return the test suite - */ - public static Test suite() { - TestSuite suite = new TestSuite("Test suite for " + Activator.PLUGIN_ID + ".util"); //$NON-NLS-1$); - //$JUnit-BEGIN$ - suite.addTestSuite(PairTest.class); - //$JUnit-END$ - return suite; - } } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/PairTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/PairTest.java index 23ec715eab..d717939924 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/PairTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/util/PairTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Ericsson + * Copyright (c) 2011, 2013 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,13 +8,16 @@ * * Contributors: * Bernd Hufmann - Initial design and implementation + * Alexandre Montplaisir - Port to JUnit4 *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.util; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.eclipse.linuxtools.tmf.core.util.Pair; +import org.junit.Test; /** * Test case for Pair class. @@ -22,32 +25,20 @@ import org.eclipse.linuxtools.tmf.core.util.Pair; * @author Bernd Hufmann */ @SuppressWarnings({ "nls", "javadoc" }) -public class PairTest extends TestCase { +public class PairTest { // ------------------------------------------------------------------------ // Field(s) // ------------------------------------------------------------------------ + Pair fPair1 = new Pair("String 1", 1L); Pair fPair2 = new Pair("String 2", 2L); - // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------------------------------ // to String // ------------------------------------------------------------------------ + @Test public void testToString() { String result = fPair1.toString(); assertEquals("(String 1, 1)", result); @@ -57,6 +48,7 @@ public class PairTest extends TestCase { // Setters/Getters // ------------------------------------------------------------------------ + @Test public void testAccessors() { Pair myPair = new Pair("String 1", 1L); assertEquals("String 1", myPair.getFirst()); @@ -73,6 +65,7 @@ public class PairTest extends TestCase { // equals // ------------------------------------------------------------------------ + @Test public void testEqualsReflexivity() { assertTrue("equals", fPair1.equals(fPair1)); assertTrue("equals", fPair2.equals(fPair2)); @@ -81,6 +74,7 @@ public class PairTest extends TestCase { assertTrue("equals", !fPair2.equals(fPair1)); } + @Test public void testEqualsSymmetry() { Pair info1 = new Pair(fPair1.getFirst(), fPair1.getSecond().longValue()); Pair info2 = new Pair(fPair2.getFirst(), fPair2.getSecond().longValue()); @@ -92,6 +86,7 @@ public class PairTest extends TestCase { assertTrue("equals", fPair2.equals(info2)); } + @Test public void testEqualsTransivity() { Pair info1 = new Pair(fPair1.getFirst(), fPair1.getSecond().longValue()); Pair info2 = new Pair(fPair1.getFirst(), fPair1.getSecond().longValue()); @@ -102,11 +97,13 @@ public class PairTest extends TestCase { assertTrue("equals", info1.equals(info3)); } + @Test public void testEqualsNull() { assertTrue("equals", !fPair1.equals(null)); assertTrue("equals", !fPair2.equals(null)); } + @Test public void testEqualsDifferentObj() { Pair info = new Pair(1L, "String1"); assertTrue("equals", !fPair1.equals(info)); @@ -116,6 +113,7 @@ public class PairTest extends TestCase { // hashCode // ------------------------------------------------------------------------ + @Test public void testHashCode() { Pair info1 = new Pair(fPair1.getFirst(), fPair1.getSecond().longValue()); Pair info2 = new Pair(fPair2.getFirst(), fPair2.getSecond().longValue()); -- 2.34.1