### Question:
RandomPowerUpFactory extends PowerUpFactory { @Override public PowerUp create() { return cdf.floorEntry(random.nextDouble()).getValue().create(); } RandomPowerUpFactory(Random random, NavigableMap<Double, PowerUpFactory> cdf); @Override PowerUp create();  }### Answer:
@Test public void createA() { NavigableMap<Double, PowerUpFactory> cdf = new TreeMap<>(); cdf.put(0.0, new BonusPowerUpFactory()); cdf.put(0.6, new JokerPowerUpFactory()); PowerUpFactory factory = new RandomPowerUpFactory(random, cdf); when(random.nextDouble()).thenReturn(0.4); assertThat(factory.create()).isInstanceOf(BonusPowerUp.class); }
@Test public void createB() { NavigableMap<Double, PowerUpFactory> cdf = new TreeMap<>(); cdf.put(0.0, new BonusPowerUpFactory()); cdf.put(0.6, new JokerPowerUpFactory()); PowerUpFactory factory = new RandomPowerUpFactory(random, cdf); when(random.nextDouble()).thenReturn(0.7); assertThat(factory.create()).isInstanceOf(JokerPowerUp.class); }