BoundedArchive extends AbstractArchive { public void setCapacity(int capacity) { if (capacity < 0) { throw new IllegalArgumentException("Invalid capacity: " + capacity); } this.capacity = capacity; } @Inject  BoundedArchive(int capacity); void setCapacity(int capacity); int getCapacity(); @Override boolean addCheckedIndividual(Individual individual); @Override boolean addCheckedIndividuals(Collection<? extends Individual> c);  }
@Test public void setCapacity() { BoundedArchive archive = new BoundedArchive(10) { @Override protected boolean updateWithNondominated(Collection<Individual> candidates) { Assert.fail(); return false; } }; Assert.assertEquals(10, archive.getCapacity()); archive.setCapacity(20); Assert.assertEquals(20, archive.getCapacity()); }
@Test(expected = IllegalArgumentException.class) public void setCapacityIllegalCapacity() { BoundedArchive archive = new BoundedArchive(10) { @Override protected boolean updateWithNondominated(Collection<Individual> candidates) { Assert.fail(); return false; } }; archive.setCapacity(-1); }