/*******************************************************************************
- * 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
* 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;
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
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
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testDefaultConstructor() {
final ITmfEvent event = new TmfEvent();
assertNull("getTrace", event.getTrace());
assertNull("getReference", event.getReference());
}
- /**
- *
- */
+ @Test
public void testFullConstructor() {
assertNull("getTrace", fEvent1.getTrace());
assertEquals("getRank", 0, fEvent1.getRank());
assertEquals("getReference", fReference2, fEvent2.getReference());
}
- /**
- *
- */
+ @Test
public void testNoRankConstructor() {
final ITmfEvent event = new TmfEvent(null, fTimestamp1, fSource, fType, fContent1, fReference1);
assertNull("getTrace", event.getTrace());
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);
trace.dispose();
}
- /**
- *
- */
+ @Test
public void testTmfEventCopy() {
final ITmfEvent event = new TmfEvent(fEvent1);
assertNull("getTrace", event.getTrace());
assertEquals("getReference", fReference1, event.getReference());
}
- /**
- *
- */
+ @Test
public void testEventCopy2() {
try {
new TmfEvent(null);
// hashCode
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testHashCode() {
ITmfEvent event1 = new TmfEvent();
ITmfEvent event2 = new TmfEvent();
// equals
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testEqualsReflexivity() {
assertTrue("equals", fEvent1.equals(fEvent1));
assertTrue("equals", fEvent2.equals(fEvent2));
assertFalse("equals", fEvent2.equals(fEvent1));
}
- /**
- *
- */
+ @Test
public void testEqualsSymmetry() {
final ITmfEvent event1 = new TmfEvent(fEvent1);
final ITmfEvent event2 = new TmfEvent(fEvent2);
assertTrue("equals", fEvent2.equals(event2));
}
- /**
- *
- */
+ @Test
public void testEqualsTransivity() {
final ITmfEvent event1 = new TmfEvent(fEvent1);
final ITmfEvent event2 = new TmfEvent(fEvent1);
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();
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);
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);
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);
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);
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);
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);
// toString
// ------------------------------------------------------------------------
- /**
- *
- */
+ @Test
public void testToString() {
final String expected1 = "TmfEvent [fTimestamp=" + fTimestamp1 + ", fTrace=null, fRank=0, fSource=" + fSource
+ ", fType=" + fType + ", fContent=" + fContent1 + ", fReference=" + fReference1 + "]";