timing.core: add testing for less used functions in the segment store
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.segmentstore.core.tests / src / org / eclipse / tracecompass / segmentstore / core / tests / AbstractTestSegmentStore.java
index 3fecaf97de70474096c51533b8329a9450eb7770..ac51468ee7934a893a925223792f7f2f7200d48b 100644 (file)
@@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -58,6 +59,16 @@ public abstract class AbstractTestSegmentStore {
      */
     protected abstract ISegmentStore<@NonNull ISegment> getSegmentStore();
 
+    /**
+     * Get the segment store to test with initial data
+     *
+     * @param data
+     *            the data
+     *
+     * @return the segment store
+     */
+    protected abstract ISegmentStore<@NonNull ISegment> getSegmentStore(@NonNull ISegment @NonNull [] data);
+
     private static final @NonNull ISegment SEGMENT_2_6 = new BasicSegment(2, 6);
     private static final @NonNull ISegment SEGMENT_4_6 = new BasicSegment(4, 6);
     private static final @NonNull ISegment SEGMENT_4_8 = new BasicSegment(4, 8);
@@ -103,6 +114,62 @@ public abstract class AbstractTestSegmentStore {
         assertEquals(SEGMENTS.size(), fSegmentStore.size());
     }
 
+    /**
+     * Testing isEmpty() method
+     */
+    @Test
+    public void testIsEmpty() {
+        assertFalse(fSegmentStore.isEmpty());
+        fSegmentStore.clear();
+        assertTrue(fSegmentStore.isEmpty());
+    }
+
+    /**
+     * Testing adding a collection with the addAll method
+     */
+    @Test
+    public void testAddAll() {
+        assertFalse(fSegmentStore.isEmpty());
+        fSegmentStore.clear();
+        assertTrue(fSegmentStore.isEmpty());
+        fSegmentStore.addAll(SEGMENTS);
+        assertTrue(fSegmentStore.containsAll(SEGMENTS));
+    }
+
+    /**
+     * Testing "copy" constructor
+     */
+    @Test
+    public void testAddAllConstructor() {
+        @SuppressWarnings("null")
+        ISegmentStore<@NonNull ISegment> other = getSegmentStore(fSegmentStore.toArray(new ISegment[fSegmentStore.size()]));
+        assertTrue(fSegmentStore.containsAll(other));
+        assertTrue(other.containsAll(fSegmentStore));
+    }
+
+    /**
+     * Testing "copy" constructor out of order
+     */
+    @Test
+    public void testAddAllConstructorOutOfOrder() {
+        @SuppressWarnings("null")
+        ISegmentStore<@NonNull ISegment> other = getSegmentStore(REVERSE_SEGMENTS.toArray(new ISegment[fSegmentStore.size()]));
+        assertTrue(fSegmentStore.containsAll(other));
+        assertTrue(other.containsAll(fSegmentStore));
+    }
+
+    /**
+     * Testing adding an out of order collection with the addAll method
+     */
+    @Test
+    public void testAddAllOutOfOrder() {
+        assertFalse(fSegmentStore.isEmpty());
+        fSegmentStore.clear();
+        assertTrue(fSegmentStore.isEmpty());
+        fSegmentStore.addAll(REVERSE_SEGMENTS);
+        assertTrue(fSegmentStore.containsAll(SEGMENTS));
+    }
+
     /**
      * Test the contains() method.
      */
@@ -115,6 +182,18 @@ public abstract class AbstractTestSegmentStore {
         assertFalse(fSegmentStore.contains(otherSegment));
     }
 
+    /**
+     * Test containsAll() method
+     */
+    public void testContainsAll() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        assertTrue(store.containsAll(Collections.emptyList()));
+        assertTrue(store.containsAll(Collections.singleton(SEGMENT_2_6)));
+        assertFalse(store.containsAll(Collections.singleton(SEGMENT_4_6)));
+    }
+
     /**
      * Test the toArray() method.
      */
@@ -367,7 +446,7 @@ public abstract class AbstractTestSegmentStore {
     }
 
     /**
-     * Test to check ordered iterators
+     *  Test to check ordered iterators
      */
     @Test
     public void testSortedIterator() {
@@ -402,4 +481,37 @@ public abstract class AbstractTestSegmentStore {
             assertTrue(comparator.compare(prev, current) <= 0);
         }
     }
+
+    /**
+     * Test retainAll() contract
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testRetainAll() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        store.retainAll(Collections.emptyList());
+    }
+
+    /**
+     * Test remove() contract
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testRemove() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        store.remove(SEGMENT_2_6);
+    }
+
+    /**
+     * Test removeAll() contract
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testRemoveAll() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        store.removeAll(Collections.emptyList());
+    }
 }
\ No newline at end of file
This page took 0.02694 seconds and 5 git commands to generate.