@Test public void containsId_tableAddedItemRemoved_returnsFalse() throws SQLException { Object id = container.addItem(); assertTrue(container.containsId(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); }
@Test public void allIdsFound_table5000RowsLastId_shouldSucceed() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); for (int i = 0; i < 5000; i++) { assertTrue(container.containsId(container.getIdByIndex(i))); } }
@Test public void removeItem_tableOneAddedItem_removesTheAddedItem() throws SQLException { Object id = container.addItem(); int size = container.size(); assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); assertEquals(size - 1, container.size()); }
@Test public void addFilter_tableBufferedItems_alsoFiltersBufferedItems() throws SQLException { // Ville, Kalle, Pelle, Börje assertEquals(4, container.size()); assertEquals("Börje", container.getContainerProperty(container.lastItemId(), NAME).getValue()); Object id1 = container.addItem(); container.getContainerProperty(id1, NAME).setValue("Palle"); Object id2 = container.addItem(); container.getContainerProperty(id2, NAME).setValue("Bengt"); container.addContainerFilter(new Like(NAME, "%lle")); // Ville, Kalle, Pelle, Palle assertEquals(4, container.size()); assertEquals( "Ville", container.getContainerProperty(container.getIdByIndex(0), NAME).getValue()); assertEquals( "Kalle", container.getContainerProperty(container.getIdByIndex(1), NAME).getValue()); assertEquals( "Pelle", container.getContainerProperty(container.getIdByIndex(2), NAME).getValue()); assertEquals( "Palle", container.getContainerProperty(container.getIdByIndex(3), NAME).getValue()); try { container.getIdByIndex(4); Assert.fail( "SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container"); } catch (IndexOutOfBoundsException e) { // should throw exception - item is filtered out } Assert.assertNull(container.nextItemId(container.getIdByIndex(3))); Assert.assertFalse(container.containsId(id2)); Assert.assertFalse(container.getItemIds().contains(id2)); Assert.assertNull(container.getItem(id2)); assertEquals(-1, container.indexOfId(id2)); Assert.assertNotSame(id2, container.lastItemId()); Assert.assertSame(id1, container.lastItemId()); }
@Test public void containsId_tableNewlyAddedItem_returnsTrue() throws SQLException { Object id = container.addItem(); assertTrue(container.containsId(id)); }
@Test public void containerDoesNotContainId() { assertFalse(container.containsId(nonExistingItemId)); }
@Test public void containerContainsId() { assertTrue(container.containsId(existingItemId)); }