ListPopulation implements Population { public void addChromosomes(final Collection<Chromosome> chromosomeColl) throws NumberIsTooLargeException { if (chromosomes.size() + chromosomeColl.size() > populationLimit) { throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE, chromosomes.size(), populationLimit, false); } this.chromosomes.addAll(chromosomeColl); } ListPopulation(final int populationLimit);  ListPopulation(final List<Chromosome> chromosomes, final int populationLimit); @Deprecated void setChromosomes(final List<Chromosome> chromosomes); void addChromosomes(final Collection<Chromosome> chromosomeColl); List<Chromosome> getChromosomes(); void addChromosome(final Chromosome chromosome); Chromosome getFittestChromosome(); int getPopulationLimit(); void setPopulationLimit(final int populationLimit); int getPopulationSize(); @Override String toString(); Iterator<Chromosome> iterator();  }
@Test(expected=NumberIsTooLargeException.class) public void testAddTooManyChromosomes() { final ArrayList<Chromosome> chromosomes = new ArrayList<Chromosome> (); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); final ListPopulation population = new ListPopulation(2) { public Population nextGeneration() { return null; } }; population.addChromosomes(chromosomes); }