PageableCollectionBase extends PropertyChangeSupportedBase implements PageableCollection<T_ITEM> { @Override public Selection<T_ITEM> getSelection() { return getSelectionHandler().getSelection(); } PageableCollectionBase(QueryOptions queryOptions); @Override final QueryParams getQueryParams(); @Override QueryOptions getQueryOptions(); @Override int getPageSize(); @Override void setPageSize(int newSize); @Override long getPageIdx(); @Override void setPageIdx(long pageIdx); @Override Selection<T_ITEM> getSelection(); @Override Modifications<T_ITEM> getModifications();  }
@Test public void testIterateEmptySelection() { resetCallCounter(); Selection<T> selection = collection.getSelection(); assertEquals("Empty selection returns no items.", "[]", IterableUtil.shallowCopy(selection).toString()); }
@Test public void testIterateSingleSelection() { doSelect(collection, 0, 0, true, "a"); resetCallCounter(); assertEquals("[a]", IterableUtil.asCollection(collection.getSelection()).toString()); }
@Test public void testSelectItems() { collection.getSelectionHandler().setSelectMode(SelectMode.MULTI); assertEquals(SelectMode.MULTI, collection.getSelectionHandler().getSelectMode()); assertEquals(0, collection.getSelectionHandler().getSelection().getSize()); assertTrue(collection.getSelectionHandler().selectAll(true)); assertEquals(6, collection.getSelectionHandler().getSelection().getSize()); assertTrue(collection.getSelectionHandler().select(false, collection.getItemsOnPage().get(0))); assertEquals(5, collection.getSelectionHandler().getSelection().getSize()); assertTrue(collection.getSelectionHandler().invertSelection()); assertEquals(1, collection.getSelectionHandler().getSelection().getSize()); assertEquals("Add event count", 0, pclAdd.getPropChangeEventCount()); assertEquals("Update event count", 0, pclUpdate.getPropChangeEventCount()); assertEquals("Remove event count", 0, pclRemove.getPropChangeEventCount()); assertEquals("Set page index event count", 0, pclPageIdx.getPropChangeEventCount()); assertEquals("Set page size event count", 0, pclPageSize.getPropChangeEventCount()); assertEquals(3, pclSelChange.getPropChangeEventCount()); }
@Test public void testSelectedItemsStayInQueryOrderForPositiveSelection() { PageableCollection<T> largeCollection = makeLargePageableCollection(); doSelect(largeCollection, 0, 2, true, " "); assertTrue(largeCollection.getModificationHandler().removeSelectedItems()); doSelect(largeCollection, 0, 0, true, "a"); doSelect(largeCollection, 2, 3, true, "n"); doSelect(largeCollection, 1, 4, true, "j"); doSelect(largeCollection, 2, 0, true, "k"); assertEquals(4, largeCollection.getSelectionHandler().getSelection().getSize()); String selection = iteratorAsList(largeCollection.getSelection().iterator()).toString(); assertEquals("[a, j, k, n]" , selection); doInvertSelection(largeCollection); assertEquals(12, largeCollection.getSelectionHandler().getSelection().getSize()); String invertedSelection = iteratorAsList(largeCollection.getSelection().iterator()).toString(); assertEquals("[b, c, d, e, f, g, h, i, l, m, o, p]" , invertedSelection); }
@Test public void testSelectedItemsStayInQueryOrderForNegativeSelection() { PageableCollection<T> largeCollection = makeLargePageableCollection(); doSelect(largeCollection, 0, 2, true, " "); assertTrue(largeCollection.getModificationHandler().removeSelectedItems()); doSelectAll(largeCollection); doSelect(largeCollection, 0, 0, false, "a"); doSelect(largeCollection, 2, 3, false, "n"); doSelect(largeCollection, 1, 4, false, "j"); doSelect(largeCollection, 2, 0, false, "k"); assertEquals(12, largeCollection.getSelectionHandler().getSelection().getSize()); String selection = iteratorAsList(largeCollection.getSelection().iterator()).toString(); assertEquals("[b, c, d, e, f, g, h, i, l, m, o, p]" , selection); doInvertSelection(largeCollection); assertEquals(4, largeCollection.getSelectionHandler().getSelection().getSize()); String invertedSelection = iteratorAsList(largeCollection.getSelection().iterator()).toString(); assertEquals("[a, j, k, n]" , invertedSelection); }
@Test public void testSelectInvertAndDeselect() { collection.getSelectionHandler().setSelectMode(SelectMode.MULTI); T firstItem = collection.getItemsOnPage().get(0); T secondItem = collection.getItemsOnPage().get(1); assertEquals("initially no item is selected", 0, collection.getSelection().getSize()); assertTrue("select the first item", collection.getSelectionHandler().select(true, firstItem) ); assertEquals("one item is selected", 1, collection.getSelection().getSize()); assertEquals("the first item is selected", true, collection.getSelection().contains(firstItem)); assertEquals("the second item is not selected", false, collection.getSelection().contains(secondItem)); assertEquals(1, pclSelChange.getPropChangeEventCount()); assertEquals("invert the selection", true, collection.getSelectionHandler().invertSelection()); assertEquals("the first item is not selected", false, collection.getSelection().contains(firstItem)); assertEquals("the second item is selected", true, collection.getSelection().contains(secondItem)); assertEquals("5 items are selected", 5, collection.getSelection().getSize()); assertEquals(2, pclSelChange.getPropChangeEventCount()); assertEquals("deselect the second item", true, collection.getSelectionHandler().select(false, secondItem)); assertEquals("the first item is not selected", false, collection.getSelection().contains(firstItem)); assertEquals("the second item is not selected", false, collection.getSelection().contains(secondItem)); assertEquals("4 items are selected", 4, collection.getSelection().getSize()); assertEquals(3, pclSelChange.getPropChangeEventCount()); assertEquals("invert the selection", true, collection.getSelectionHandler().invertSelection()); assertEquals("the first item is selected", true, collection.getSelection().contains(firstItem)); assertEquals("the second item is selected", true, collection.getSelection().contains(secondItem)); assertEquals("2 items are selected", 2, collection.getSelection().getSize()); assertEquals(4, pclSelChange.getPropChangeEventCount()); }
@Test public void testSingleSelection() { collection.getSelectionHandler().setSelectMode(SelectMode.SINGLE); collection.getSelectionHandler().select(true, collection.getItemsOnPage().get(0)); assertEquals(true, collection.getSelectionHandler().getSelection().getSize() == 1); collection.getSelectionHandler().select(false, collection.getItemsOnPage().get(1)); assertEquals(true, collection.getSelectionHandler().getSelection().getSize() == 1); collection.getSelectionHandler().select(false, collection.getItemsOnPage().get(0)); assertEquals(true, collection.getSelectionHandler().getSelection().getSize() == 0); }
@Test public void testIterateAllSelectionMinusOneWithBlockSize2() { collection.getSelectionHandler().setSelectMode(SelectMode.MULTI); collection.getSelectionHandler().selectAll(true); collection.getSelectionHandler().select(false, collection.getItemsOnPage().get(1)); Selection<T> selection = collection.getSelection(); selection.setIteratorBlockSizeHint(2); resetCallCounter(); assertEquals("All items minus one selection iteration result", "[a, c, d, e, f]", IterableUtil.shallowCopy(selection).toString()); }