package org.eclipse.linuxtools.tmf.tests.event;
+import junit.framework.TestCase;
+
import org.eclipse.linuxtools.tmf.event.TmfEvent;
import org.eclipse.linuxtools.tmf.event.TmfEventContent;
import org.eclipse.linuxtools.tmf.event.TmfEventReference;
import org.eclipse.linuxtools.tmf.event.TmfEventType;
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import junit.framework.TestCase;
-
/**
* <b><u>TmfEventTest</u></b>
* <p>
- * TODO: Implement me. Please.
+ * Test suite for the TmfEvent class.
*/
public class TmfEventTest extends TestCase {
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
private final String fTypeId = "Some type";
private final String fLabel0 = "label1";
private final String fLabel1 = "label2";
private final TmfEventContent fContent1;
private final TmfEventContent fContent2;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Housekeeping
- // ========================================================================
+ // ------------------------------------------------------------------------
+ /**
+ * @param name the test name
+ */
public TmfEventTest(String name) {
super(name);
super.tearDown();
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
public void testTmfEvent() {
assertEquals("getTimestamp", fTimestamp1, fEvent1.getTimestamp());
assertEquals("getReference", fReference, fEvent2.getReference());
}
+ public void testTmfEventBadArgs() {
+ try { // Bad timestamp
+ new TmfEvent(null, fSource, fType, fReference);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+
+ try { // Bad source
+ new TmfEvent(fTimestamp1, null, fType, fReference);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+
+ try { // Bad type
+ new TmfEvent(fTimestamp1, fSource, null, fReference);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
public void testTmfEventCopy() {
TmfEvent event = new TmfEvent(fEvent1);
assertEquals("getTimestamp", fTimestamp1, event.getTimestamp());
assertEquals("getReference", fReference, event.getReference());
}
-// public void testTmfEventCloneShallowCopy() {
-// TmfEvent event = fEvent1.clone();
-// assertEquals("getTimestamp", fTimestamp1, event.getTimestamp());
-// assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp());
-// assertEquals("getSource", fSource, event.getSource());
-// assertEquals("getType", fType, event.getType());
-// assertEquals("getContent", fContent1, event.getContent());
-// assertEquals("getReference", fReference, event.getReference());
-// }
-
-// public void testTmfEventCloneDeepCopy() {
-// TmfEvent event = fEvent1.clone();
-// assertEquals("getTimestamp", fTimestamp1, event.getTimestamp());
-// assertEquals("getOriginalTimestamp", fTimestamp1, event.getOriginalTimestamp());
-// assertEquals("getSource", fSource, event.getSource());
-// assertEquals("getType", fType, event.getType());
-// assertEquals("getContent", fContent1, event.getContent());
-// assertEquals("getReference", fReference, event.getReference());
-// }
-
- // ========================================================================
- // Operators
- // ========================================================================
-
-// public void testToString() {
-// String expected1 = "[TmfEventType:" + TmfEventType.DEFAULT_TYPE_ID + "]";
-// assertEquals("toString", expected1, fEvent1.toString());
-//
-// String expected2 = "[TmfEventType:" + fTypeId + "]";
-// assertEquals("toString", expected2, fEvent2.toString());
-// }
+ public void testEventCopy2() throws Exception {
+ try {
+ new TmfEvent(null);
+ fail("null copy");
+ }
+ catch (IllegalArgumentException e) {
+ // Success
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // equals
+ // ------------------------------------------------------------------------
+
+ public void testEqualsReflexivity() throws Exception {
+ assertTrue("equals", fEvent1.equals(fEvent1));
+ assertTrue("equals", fEvent2.equals(fEvent2));
+
+ assertTrue("equals", !fEvent1.equals(fEvent2));
+ assertTrue("equals", !fEvent2.equals(fEvent1));
+ }
+
+ public void testEqualsSymmetry() throws Exception {
+ TmfEvent event1 = new TmfEvent(fEvent1);
+ TmfEvent event2 = new TmfEvent(fEvent2);
+
+ assertTrue("equals", event1.equals(fEvent1));
+ assertTrue("equals", fEvent1.equals(event1));
+
+ assertTrue("equals", event2.equals(fEvent2));
+ assertTrue("equals", fEvent2.equals(event2));
+ }
+
+ public void testEqualsTransivity() throws Exception {
+ TmfEvent event1 = new TmfEvent(fEvent1);
+ TmfEvent event2 = new TmfEvent(fEvent1);
+ TmfEvent event3 = new TmfEvent(fEvent1);
+
+ assertTrue("equals", event1.equals(event2));
+ assertTrue("equals", event2.equals(event3));
+ assertTrue("equals", event1.equals(event3));
+ }
+
+ public void testEqualsConsistency() throws Exception {
+ TmfEvent event1 = new TmfEvent(fEvent1);
+ TmfEvent event2 = new TmfEvent(fEvent2);
+
+ assertTrue("equals", event1.equals(fEvent1));
+ assertTrue("equals", event1.equals(fEvent1));
+
+ assertTrue("equals", event2.equals(fEvent2));
+ assertTrue("equals", event2.equals(fEvent2));
+ }
+
+ public void testEqualsNull() throws Exception {
+ assertTrue("equals", !fEvent1.equals(null));
+ assertTrue("equals", !fEvent2.equals(null));
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
+
+ public void testToString() {
+ String expected1 = "[TmfEvent(" + fTimestamp1 + "," + fSource + "," + fType + "," + fContent1 + ")]";
+ assertEquals("toString", expected1, fEvent1.toString());
+
+ String expected2 = "[TmfEvent(" + fTimestamp2 + "," + fSource + "," + fType + "," + fContent2 + ")]";
+ assertEquals("toString", expected2, fEvent2.toString());
+ }
+
+ // ------------------------------------------------------------------------
+ // setContent
+ // ------------------------------------------------------------------------
+
+ public void testSetContent() {
+ TmfEvent event = new TmfEvent(fEvent1);
+ assertEquals("setContent", fContent1, event.getContent());
+
+ event.setContent(fContent2);
+ assertEquals("setContent", fContent2, event.getContent());
+
+ event.setContent(fContent1);
+ assertEquals("setContent", fContent1, event.getContent());
+ }
}