### Question:
RandomCollection { public void add(double weight, E result) { if (weight <= 0) { throw new IllegalArgumentException("Cannot add negative weight (" + weight + ") to random collection."); } total += weight; map.put(total, result); } RandomCollection(Random random); void add(double weight, E result); E next();  }### Answer:
@Test public void testAddInvalidNegativeWeight() { RandomCollection<Integer> rc = new RandomCollection<>(random); boolean thrown = false; try { rc.add(-0.0001, 894); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); }