/*******************************************************************************
- * Copyright (c) 2009, 2010, 2012 Ericsson
- *
+ * Copyright (c) 2009, 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
* 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.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.junit.Test;
/**
- * <b><u>TmfTimeRangeTest</u></b>
- * <p>
* Test suite for the TmfTimeRange class.
*/
-@SuppressWarnings("nls")
-public class TmfTimeRangeTest extends TestCase {
-
- // ------------------------------------------------------------------------
- // Housekeeping
- // ------------------------------------------------------------------------
-
- public TmfTimeRangeTest(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+@SuppressWarnings("javadoc")
+public class TmfTimeRangeTest {
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- public void testConstructor() throws Exception {
+ @Test
+ public void testConstructor() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range = new TmfTimeRange(ts1, ts2);
assertEquals("endTime", ts2, range.getEndTime());
}
- public void testBadConstructor() throws Exception {
+ @Test
+ public void testBadConstructor() {
try {
new TmfTimeRange(TmfTimestamp.BIG_BANG, null);
fail("TmfTimeRange: bad end time");
}
}
- public void testOpenRange1() throws Exception {
+ @Test
+ public void testOpenRange1() {
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, ts2);
assertEquals("endTime", ts2, range.getEndTime());
}
- public void testOpenRange2() throws Exception {
+ @Test
+ public void testOpenRange2() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final TmfTimeRange range = new TmfTimeRange(ts1, TmfTimestamp.BIG_CRUNCH);
assertEquals("endTime", TmfTimestamp.BIG_CRUNCH, range.getEndTime());
}
- public void testOpenRange3() throws Exception {
+ @Test
+ public void testOpenRange3() {
final TmfTimeRange range = new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
assertEquals("startTime", TmfTimestamp.BIG_BANG, range.getStartTime());
assertEquals("endTime", TmfTimestamp.BIG_CRUNCH, range.getEndTime());
}
- public void testCopyConstructor() throws Exception {
+ @Test
+ public void testCopyConstructor() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range0 = new TmfTimeRange(ts1, ts2);
assertEquals("endTime", TmfTimestamp.BIG_CRUNCH, range3.getEndTime());
}
- public void testCopyConstructor2() throws Exception {
+ @Test
+ public void testCopyConstructor2() {
try {
new TmfTimeRange(null);
fail("TmfTimeRange: null argument");
}
}
- // ------------------------------------------------------------------------
- // clone
- // ------------------------------------------------------------------------
-
- public void testClone() throws Exception {
- final ITmfTimestamp ts1 = new TmfTimestamp(12345);
- final ITmfTimestamp ts2 = new TmfTimestamp(12350);
-
- final TmfTimeRange range = new TmfTimeRange(ts1, ts2);
- final TmfTimeRange clone = range.clone();
-
- assertTrue("clone", range.clone().equals(range));
- assertTrue("clone", clone.clone().equals(clone));
-
- assertEquals("clone", range, clone);
- assertEquals("clone", ts1, clone.getStartTime());
- assertEquals("clone", ts2, clone.getEndTime());
- }
-
// ------------------------------------------------------------------------
// hashCode
// ------------------------------------------------------------------------
- public void testHashCode() throws Exception {
+ @Test
+ public void testHashCode() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range1 = new TmfTimeRange(ts1, ts2);
// equals
// ------------------------------------------------------------------------
- public void testEqualsReflexivity() throws Exception {
+ @Test
+ public void testEqualsReflexivity() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range1 = new TmfTimeRange(ts1, ts2);
assertTrue("equals", !range2.equals(range1));
}
- public void testEqualsSymmetry() throws Exception {
+ @Test
+ public void testEqualsSymmetry() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range1a = new TmfTimeRange(ts1, ts2);
assertTrue("equals", range2b.equals(range2a));
}
- public void testEqualsTransivity() throws Exception {
+ @Test
+ public void testEqualsTransivity() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range1a = new TmfTimeRange(ts1, ts2);
assertTrue("equals", range1a.equals(range1c));
}
- public void testEqualsNull() throws Exception {
+ @Test
+ public void testEqualsNull() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range1 = new TmfTimeRange(ts1, ts2);
assertTrue("equals", !range1.equals(null));
}
- public void testEqualsBadType() throws Exception {
+ @Test
+ public void testEqualsBadType() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range1 = new TmfTimeRange(ts1, ts2);
assertTrue("equals", !range1.equals(ts1));
}
- public void testEqualStartTime() throws Exception {
+ @Test
+ public void testEqualStartTime() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final ITmfTimestamp ts3 = new TmfTimestamp(12355);
assertTrue("equals", !range1.equals(range3));
}
- public void testEqualsEndTime() throws Exception {
+ @Test
+ public void testEqualsEndTime() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final ITmfTimestamp ts3 = new TmfTimestamp(12355);
// toString
// ------------------------------------------------------------------------
- public void testToString() throws Exception {
+ @Test
+ public void testToString() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range = new TmfTimeRange(ts1, ts2);
// contains
// ------------------------------------------------------------------------
- public void testContainsTimestamp() throws Exception {
+ @Test
+ public void testContainsTimestamp() {
final ITmfTimestamp ts1 = new TmfTimestamp(12345);
final ITmfTimestamp ts2 = new TmfTimestamp(12350);
final TmfTimeRange range = new TmfTimeRange(ts1, ts2);
assertFalse("contains (low value)", range.contains(new TmfTimestamp(12340)));
assertFalse("contains (high value)", range.contains(new TmfTimestamp(12351)));
-
- assertTrue("contains (zero)", range.contains(TmfTimestamp.ZERO));
}
- public void testContainsRange() throws Exception {
+ @Test
+ public void testContainsRange() {
final ITmfTimestamp ts1 = new TmfTimestamp(10);
final ITmfTimestamp ts2 = new TmfTimestamp(20);
final ITmfTimestamp ts3 = new TmfTimestamp(30);
// getIntersection
// ------------------------------------------------------------------------
- public void testGetIntersection() throws Exception {
+ @Test
+ public void testGetIntersection() {
final ITmfTimestamp ts1a = new TmfTimestamp(1000);
final ITmfTimestamp ts1b = new TmfTimestamp(2000);