예제 #1
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());
 }
예제 #2
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());
 }
예제 #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
 @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()));
 }
예제 #6
0
  @Test
  public void testItemsReplacedBefore() {
    int[] indices = new int[] {3, 5, 1};
    indicesList.addIndices(indices);
    report.clear();

    items.set(0, "newItem");
    Arrays.sort(indices);
    for (int i = 0; i < indices.length; i++) {
      assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
    }
    assertEquals("selectedIndices unchanged", 0, report.getEventCount());
  }
예제 #7
0
 @Test
 public void testItemsRemovedBefore() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   items.remove(0);
   for (int i = 0; i < indices.length; i++) {
     indices[i] = indices[i] - 1;
   }
   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());
 }
예제 #8
0
 /**
  * The spec is: keep the selected on-replace-item - this means no change to the indicesList, no
  * notification.
  */
 @Test
 public void testItemsReplacedAt() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   ListChangeReport itemsReport = new ListChangeReport(items);
   items.set(3, "newItem");
   //        itemsReport.prettyPrint();
   Arrays.sort(indices);
   for (int i = 0; i < indices.length; i++) {
     assertEquals("expected value at " + i, indices[i], indicesList.get(i).intValue());
   }
   assertEquals("selectedIndices unchanged", 0, report.getEventCount());
   //        report.prettyPrint();
   //        assertTrue("singleReplaced ", wasSingleReplaced(report.getLastChange()));
 }
예제 #9
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()));
 }
예제 #10
0
 @Test
 public void testItemsAddedBefore() {
   int[] indices = new int[] {3, 5, 1};
   indicesList.addIndices(indices);
   report.clear();
   //        new PrintingListChangeListener("Item added at 0", indicesList);
   items.add(0, "newItem");
   for (int i = 0; i < indices.length; i++) {
     indices[i] = indices[i] + 1;
   }
   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(
       "expected single replaced, but was " + report.getLastChange(),
       wasSingleReplaced(report.getLastChange()));
 }
예제 #11
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();
 }
예제 #12
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()));
 }
예제 #13
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()));
  }