Experiments implements Closeable { public void save(Experiment experiment) throws ValidationException { experiment.validateName(); experiment.getTreatments().forEach(Treatment::validateName); experiment.getOverrides().forEach(TreatmentOverride::validateName); store.save(experiment); strategy.onSave(experiment, context); } private  Experiments(ExperimentsStoreProvider provider,
                        CacheStrategy strategy,
                        ExecutorService executorService); static Builder using(ExperimentsStoreProvider provider); Treatment getActiveTreatment(String experimentName, Identity identity); Iterable<Experiment> getActiveExperiments(); Map<Experiment, Treatment> getActiveTreatments(Identity identity); Iterable<Experiment> find(Filter filter); Iterable<Experiment> find(); Experiment get(String experimentName); void delete(String experimentName); void save(Experiment experiment); Experiment create(String name); @Override void close();  }
@Test public void testSave() throws ValidationException { final Experiment experiment = experiments.create("foo").save(); verify(store).save(eq(experiment)); verifyZeroInteractions(cache); }
@Test public void testValidateOnSave() { final Treatment treatment = mock(Treatment.class); final TreatmentOverride override = mock(TreatmentOverride.class); final Experiment experiment = mock(Experiment.class); doReturn(Collections.singletonList(treatment)).when(experiment).getTreatments(); doReturn(Collections.singletonList(override)).when(experiment).getOverrides(); experiments.save(experiment); verify(experiment).validateName(); verify(treatment).validateName(); verify(override).validateName(); }