OpenAddressedHashTable implements HashTable<E> { @Override public void put(int index, E item) { for (int i = 0; i < capacity; i ++) { final int hash = this.probe.probe(index, capacity, i); boolean add = false; if (slots[hash] == null || slots[hash] == deleted) { size ++; add = true; } else if (slots[hash].getIndex() == index) { add = true; } if (add) { slots[hash] = new HashTableItem<>(index, item); return; } } throw new IllegalStateException("Hash table is full"); } OpenAddressedHashTable(int capacity);  OpenAddressedHashTable(int capacity, HashTableProbe probe); @Override E get(int index); @Override void put(int index, E item); @Override void delete(int index); @Override int getSize(); @Override boolean isEmpty(); @Override int getCapacity();  }
@Test(dataProvider = "hashTableOverflowDataProvider", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "Hash table is full") public void testOverflow(HashTable<Integer> hashTable, Integer[] indices, Integer[] items) throws Exception { final Set<Integer> keys = new HashSet<>(); for (int i = 0; i < indices.length; i++) { final Integer index = indices[i]; final Integer item = items[i]; keys.add(index); try { hashTable.put(index, item); } catch (Exception e) { fail("Unexpected exception occurred: " + e); } } int extra; do { extra = Math.abs(new Random().nextInt()); } while (keys.contains(extra)); hashTable.put(extra, extra); }