[Bug309042] Improved test code coverage and other mundane issues.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / src / org / eclipse / linuxtools / tmf / tests / event / TmfEventTest.java
index ee6abecc83b3ee7d75d5a8e4a0a2e1e2c5b5afd0..6198588e43bd3e7ab78aa12692c25c8b2a952e99 100644 (file)
@@ -12,6 +12,8 @@
 
 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;
@@ -19,15 +21,17 @@ import org.eclipse.linuxtools.tmf.event.TmfEventSource;
 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";
@@ -45,10 +49,13 @@ public class TmfEventTest extends TestCase {
        private final TmfEventContent fContent1;
        private final TmfEventContent fContent2;
        
-       // ========================================================================
+       // ------------------------------------------------------------------------
        // Housekeeping
-       // ========================================================================
+       // ------------------------------------------------------------------------
 
+       /**
+        * @param name the test name
+        */
        public TmfEventTest(String name) {
                super(name);
 
@@ -71,9 +78,9 @@ public class TmfEventTest extends TestCase {
                super.tearDown();
        }
 
-       // ========================================================================
+       // ------------------------------------------------------------------------
        // Constructors
-       // ========================================================================
+       // ------------------------------------------------------------------------
 
        public void testTmfEvent() {
                assertEquals("getTimestamp",         fTimestamp1, fEvent1.getTimestamp());
@@ -93,6 +100,32 @@ public class TmfEventTest extends TestCase {
                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());
@@ -103,36 +136,90 @@ public class TmfEventTest extends TestCase {
                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());
+       }
 
 }
This page took 0.026708 seconds and 5 git commands to generate.