### Question:
InventoryPages { public void addNewPage() { Inventory newPage = server.createInventory(null, INVENTORY_SIZE, pageBuilder.pageTitle(Math.max(1, pages.size()), pages.size() + 1)); this.pages.add(newPage); for (int i = 0; i < pages.size() - 1; i++) { this.pageBuilder.rebuildPageByIndex(i); } this.pageBuilder.rebuildPageSwitchers(pages.size() - 2); this.pageBuilder.addSwitchItems(pages.size() - 1, newPage); } InventoryPages(PagesList pages, Server server, PageBuilder pageBuilder); void clearAll(); int getTotalPages(); boolean isEmpty(); Inventory getPage(int page); void addNewPage(); void removePage(int page);  }### Answer:
@Test public void whenAddOnePage() { inventoryPages.addNewPage(); verify(pageBuilder, times(0)).rebuildPageByIndex(anyInt()); verify(pageBuilder).addSwitchItems(eq(0), eq(inventories.get(0))); verify(pageBuilder, times(1)).rebuildPageSwitchers(eq(-1)); assertEquals("1/1", inventories.get(0).getTitle()); }
@Test public void whenAddMultiplePages() { for (int i = 0; i < 4; i++) { inventoryPages.addNewPage(); verify(pageBuilder).addSwitchItems(eq(i), eq(inventories.get(i))); } assertEquals(4, inventories.size()); for (int i = 0; i < 4; i++) { verify(pageBuilder, times(3 - i)).rebuildPageByIndex(eq(i)); } for (int i = 0; i < 3; i++) { verify(pageBuilder, times(1)).rebuildPageSwitchers(eq(i)); } }