Пример #1
0
 @Test
 public void testItemsRemoveRange() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   // items we expect to appear in removed
   List removedItems = new ArrayList();
   removedItems.add(3);
   removedItems.add(5);
   report.clear();
   // remove items at 3...5, inclusive
   items.remove(3, 6);
   assertEquals(1, indicesList.size());
   //        report.prettyPrint();
   indices = new int[] {1};
   for (int i = 0; i < indices.length; i++) {
     assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
   }
   assertEquals(1, report.getEventCount());
   assertTrue(
       "expected single replaced but was" + report.getLastChange(),
       wasSingleRemoved(report.getLastChange()));
   Change c = report.getLastChange();
   c.next();
   assertEquals(2, c.getRemovedSize());
   assertEquals(removedItems, c.getRemoved());
 }
Пример #2
0
 /**
  * Test get if index off range. Changed implementation to throw IndexOOB (off range access is
  * always a programming error)
  */
 @Test(expected = IndexOutOfBoundsException.class)
 public void testGetOffRange() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   assertEquals(indices.length, indicesList.size());
   assertEquals(-1, indicesList.get(-1).intValue());
   assertEquals(-1, indicesList.get(indices.length).intValue());
 }
Пример #3
0
 @Test
 public void testAddSingle() {
   int index = 3;
   indicesList.addIndices(index);
   assertEquals(1, indicesList.size());
   assertEquals(index, indicesList.get(0).intValue());
   assertEquals(1, report.getEventCount());
 }
Пример #4
0
 @Test
 public void testItemSetAt() {
   int index = 3;
   indicesList.setIndices(index);
   report.clear();
   items.set(index, "replaced-element-at-3");
   assertEquals(1, indicesList.size());
   assertEquals(index, indicesList.get(0).intValue());
   assertEquals(0, report.getEventCount());
 }
Пример #5
0
 /** Source index is same as get, kind of. */
 @Test
 public void testSourceIndexInRange() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   assertEquals(indices.length, indicesList.size());
   Arrays.sort(indices);
   for (int i = 0; i < indices.length; i++) {
     assertEquals("sourceIndex " + i, indices[i], indicesList.getSourceIndex(i));
   }
 }
Пример #6
0
 /**
  * Test notification on setAll if there are already set indices. Changed implementation due to
  * RT-39776, test assumption incorrect.
  */
 @Test
 public void testSetAllNotificationIfHasSet() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   indicesList.setAllIndices();
   //        report.prettyPrint();
   assertEquals(items.size(), indicesList.size());
   assertEquals(1, report.getEventCount());
   Change c = report.getLastChange();
   assertEquals(4, getChangeCount(c, ChangeType.ADDED));
 }
Пример #7
0
 @Test
 public void testAddMultiple() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   assertEquals(indices.length, indicesList.size());
   Arrays.sort(indices);
   for (int i = 0; i < indices.length; i++) {
     assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
   }
   assertEquals(1, report.getEventCount());
   assertTrue("got a single added", wasSingleAdded(report.getLastChange()));
 }
Пример #8
0
  @Test
  public void testItemsSetAll() {
    int[] indices = new int[] {3, 5, 1};
    indicesList.addIndices(indices);
    report.clear();

    items.setAll("one", "two", "three");
    //        LOG.info("setAll" + report.getLastChange());

    assertEquals("all cleared", 0, indicesList.size());
    assertEquals(1, report.getEventCount());
    assertTrue(
        "expected single removed, but was " + report.getLastChange(),
        wasSingleRemoved(report.getLastChange()));
  }
Пример #9
0
 @Test
 public void testClearSomeIndicesNotification() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   int[] clear = new int[] {5, 1};
   //        new PrintingListChangeListener("clearSomeNotification", indicesList);
   indicesList.clearIndices(clear);
   assertEquals(1, indicesList.size());
   assertEquals(1, report.getEventCount());
   assertEquals(
       "must be 2 disjoint removes",
       2,
       getChangeCount(report.getLastChange(), ChangeType.REMOVED));
 }
Пример #10
0
  @Test
  public void testItemsSetAllSmallerSize() {
    int[] indices = new int[] {3, 5, 1};
    indicesList.addIndices(indices);
    report.clear();

    ObservableList<String> other = createObservableList(true);
    other.remove(1);
    items.setAll(other);

    assertEquals("all cleared", 0, indicesList.size());
    assertEquals(1, report.getEventCount());
    assertTrue(
        "expected single removed, but was " + report.getLastChange(),
        wasSingleRemoved(report.getLastChange()));
  }
Пример #11
0
  @Test
  public void testItemsSetAllSameSize() {
    int[] indices = new int[] {3, 5, 1};
    indicesList.addIndices(indices);
    report.clear();
    //        new PrintingListChangeListener("SetAll Same size", indicesList);
    ObservableList<String> other = createObservableList(true);
    // make it not equal
    other.set(0, "otherItem");
    items.setAll(other);

    assertEquals("all cleared", 0, indicesList.size());
    assertEquals(1, report.getEventCount());
    assertTrue(
        "expected single removed, but was " + report.getLastChange(),
        wasSingleRemoved(report.getLastChange()));
  }
Пример #12
0
 @Test
 public void testItemsRemovedAtAndBetween() {
   int[] indices = new int[] {1, 3, 5, 7};
   indicesList.addIndices(indices);
   report.clear();
   //        new PrintingListChangeListener("Items removed at 2/4", indicesList);
   items.removeAll(items.get(3), items.get(6));
   indices = new int[] {1, 4, 5};
   assertEquals(indices.length, indicesList.size());
   for (int i = 0; i < indices.length; i++) {
     assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
   }
   assertEquals(1, report.getEventCount());
   assertTrue(
       "expected single replaced but was" + report.getLastChange(),
       wasSingleReplaced(report.getLastChange()));
 }
Пример #13
0
 @Test
 public void testClearIndicesNotification() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   indicesList.clearIndices(indices);
   assertEquals(0, indicesList.size());
   assertEquals(1, report.getEventCount());
   assertTrue("must be single remove", wasSingleRemoved(report.getLastChange()));
   Change c = report.getLastChange();
   c.reset();
   c.next();
   Arrays.sort(indices);
   List base = new ArrayList();
   for (int i = 0; i < indices.length; i++) {
     base.add(indices[i]);
   }
   assertEquals(base, c.getRemoved());
 }
Пример #14
0
 @Test
 public void testSetIndices() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   int[] setIndices = new int[] {2, 4, 6, 7};
   indicesList.setIndices(setIndices);
   assertEquals(setIndices.length, indicesList.size());
   assertEquals(1, report.getEventCount());
   assertTrue(wasSingleReplaced(report.getLastChange()));
   Change c = report.getLastChange();
   c.reset();
   c.next();
   Arrays.sort(indices);
   List base = new ArrayList();
   for (int i = 0; i < indices.length; i++) {
     base.add(indices[i]);
   }
   assertEquals(base, c.getRemoved());
 }
Пример #15
0
 @Test
 public void testItemsRemovedBeforeAndWithFirst() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   //        new PrintingListChangeListener("Items removed at 0/1", indicesList);
   items.removeAll(items.get(0), items.get(1));
   assertEquals(indices.length - 1, indicesList.size());
   Arrays.sort(indices);
   indices = Arrays.copyOfRange(indices, 1, 3);
   for (int i = 0; i < indices.length; i++) {
     indices[i] = indices[i] - 2;
   }
   for (int i = 0; i < indices.length; i++) {
     assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
   }
   assertEquals(1, report.getEventCount());
   assertTrue(
       "expected single replaced, but was " + report.getLastChange(),
       wasSingleReplaced(report.getLastChange()));
 }
Пример #16
0
 /** Remove items in between selected. */
 @Test
 public void testItemsRemovedBetweenReally() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   items.removeAll(items.get(2), items.get(4));
   assertEquals(indices.length, indicesList.size());
   indices = new int[] {1, 2, 3};
   for (int i = 0; i < indices.length; i++) {
     assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
   }
   assertEquals(1, report.getEventCount());
   assertTrue(
       "expected single replaced but was" + report.getLastChange(),
       wasSingleReplaced(report.getLastChange()));
   Change c = report.getLastChange();
   c.next();
   assertEquals(2, c.getAddedSize());
   assertEquals(c.getAddedSize(), c.getRemovedSize());
   //        report.prettyPrint();
 }
Пример #17
0
  @Test
  public void testItemsRemovedAtFirst() {
    int[] indices = new int[] {3, 5, 1};
    indicesList.addIndices(indices);
    report.clear();

    items.remove(1);
    assertEquals(indices.length - 1, indicesList.size());
    Arrays.sort(indices);
    indices = Arrays.copyOfRange(indices, 1, 3);
    // note: since here, the indices are "shortend" at start!
    for (int i = 0; i < indices.length; i++) {
      indices[i] = indices[i] - 1;
    }
    for (int i = 0; i < indices.length; i++) {
      assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
    }
    assertEquals(1, report.getEventCount());
    assertTrue(
        "expected single replaced but was" + report.getLastChange(),
        wasSingleReplaced(report.getLastChange()));
  }
Пример #18
0
 /** Sanity: single remove at index removes indexed */
 @Test
 public void testItemRemovedAt() {
   indicesList.setIndices(3);
   items.remove(3);
   assertEquals(0, indicesList.size());
 }
Пример #19
0
 @Test
 public void testInitial() {
   assertEquals(0, indicesList.size());
 }
Пример #20
0
 @Test
 public void testSetAllIndices() {
   indicesList.setAllIndices();
   assertEquals(items.size(), indicesList.size());
   assertEquals(1, report.getEventCount());
 }