@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); }
@Override public PowerUp create() { return cdf.floorEntry(random.nextDouble()).getValue().create(); }
RandomPowerUpFactory extends PowerUpFactory { @Override public PowerUp create() { return cdf.floorEntry(random.nextDouble()).getValue().create(); } }
RandomPowerUpFactory extends PowerUpFactory { @Override public PowerUp create() { return cdf.floorEntry(random.nextDouble()).getValue().create(); } RandomPowerUpFactory(Random random, NavigableMap<Double, PowerUpFactory> cdf); }
RandomPowerUpFactory extends PowerUpFactory { @Override public PowerUp create() { return cdf.floorEntry(random.nextDouble()).getValue().create(); } RandomPowerUpFactory(Random random, NavigableMap<Double, PowerUpFactory> cdf); @Override PowerUp create(); }
RandomPowerUpFactory extends PowerUpFactory { @Override public PowerUp create() { return cdf.floorEntry(random.nextDouble()).getValue().create(); } RandomPowerUpFactory(Random random, NavigableMap<Double, PowerUpFactory> cdf); @Override PowerUp create();  }