### Question:
PlatformManager { public Optional<Platform> getNextPlatformForExperiment (boolean force) { return getPlatforms().stream() .sorted(comparingLong(platform -> platform.getNextChaosTime().toEpochMilli())) .filter(platform1 -> force || platform1.canExperiment()) .filter(Platform::hasEligibleContainersForExperiments) .findFirst(); } @Autowired  PlatformManager();   PlatformManager(Collection<Platform> platforms); Collection<Platform> getPlatforms(); Optional<Platform> getNextPlatformForExperiment(boolean force);  }### Answer:
@Test public void getNextPlatformForExperiments () { final Optional<Platform> nextPlatformForExperiment = platformManager.getNextPlatformForExperiment(false); assertTrue(nextPlatformForExperiment.isPresent()); assertSame(nextPlatformForExperiment.get(), platform1); }
@Test public void getNextPlatformForExperiments2 () { doReturn(false).when(platform1).hasEligibleContainersForExperiments(); final Optional<Platform> nextPlatformForExperiment = platformManager.getNextPlatformForExperiment(false); assertTrue(nextPlatformForExperiment.isPresent()); assertSame(nextPlatformForExperiment.get(), platform2); }
@Test public void getNextPlatformForExperiments3 () { doReturn(false).when(platform2).canExperiment(); doReturn(false).when(platform1).hasEligibleContainersForExperiments(); final Optional<Platform> nextPlatformForExperiment = platformManager.getNextPlatformForExperiment(false); assertTrue(nextPlatformForExperiment.isEmpty()); }
@Test public void forceGetNextPlatformForExperiments () { doReturn(false).when(platform1).canExperiment(); final Optional<Platform> nextPlatformForExperiment = platformManager.getNextPlatformForExperiment(true); assertTrue(nextPlatformForExperiment.isPresent()); assertSame(nextPlatformForExperiment.get(), platform1); }
@Test public void forceGetNextPlatformForExperiments2 () { doReturn(false).when(platform1).hasEligibleContainersForExperiments(); final Optional<Platform> nextPlatformForExperiment = platformManager.getNextPlatformForExperiment(true); assertTrue(nextPlatformForExperiment.isPresent()); assertSame(nextPlatformForExperiment.get(), platform2); }