Experiment implements Named { public Experiment removeTreatment(String name) { final Treatment treatment = treatments.get(name); if (treatment == null) { return this; } removeOverrides(name); allocations.deallocate(treatment, Allocations.NUM_BINS); treatments.remove(name); return this; } private  Experiment(Experiments owner,
                       String name,
                       int seed,
                       String description,
                       FilterExpression filter,
                       Set<String> hashAttributes,
                       boolean active,
                       DateTime created,
                       DateTime modified,
                       DateTime activated,
                       DateTime deactivated,
                       Map<String, Treatment> treatments,
                       Iterable<TreatmentOverride> overrides,
                       Iterable<Allocation> allocations); protected  Experiment(Experiments owner, String name); private  Experiment(Experiment toCopy); static Experiment copyOf(Experiment experiment); String getName(); String getDescription(); Experiment setDescription(String description); FilterExpression getFilter(); Set<String> getHashAttributes(); Experiment setFilter(FilterExpression filter); Experiment setHashAttributes(Set<String> hashAttributes); Experiment setHashAttributes(String ... hashAttributes); Experiment setSeed(int seed); int getSeed(); boolean isActive(); DateTime getCreated(); DateTime getModified(); DateTime getActivated(); DateTime getDeactivated(); List<Allocation> getAllocations(); List<Treatment> getTreatments(); Treatment getTreatment(String treatmentName); List<TreatmentOverride> getOverrides(); TreatmentOverride getOverride(String overrideName); Experiment activate(); Experiment deactivate(); Experiment addTreatment(String name); Experiment addTreatment(String name, String description); Experiment clearTreatments(); Experiment clearOverrides(); Experiment addOverride(String overrideName, String treatmentName, String filter); Experiment removeOverride(String overrideName); Experiment removeOverrides(String treatmentName); Experiment removeTreatment(String name); Experiment save(); void delete(); Experiment allocate(String treatmentName, int size); Experiment deallocate(String treatmentName, int size); Experiment reallocate(String sourceTreatmentName, String destinationTreatmentName, int size); Experiment deallocateAll(); Treatment getTreatment(Identity identity, AttributesMap attributes); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testRemoveTreatment() throws ValidationException { doReturn(0L).when(identity).computeHash(anyInt(), Mockito.<Set<String>>any(), any(AttributesMap.class)); final Experiment experiment = new Experiment(null, "foo") .addTreatment("control") .addTreatment("cake") .addTreatment("pie") .allocate("control", 10) .allocate("cake", 10) .allocate("pie", 10) .allocate("control", 10) .allocate("cake", 10) .allocate("pie", 10) .addOverride("control_override", "control", "true"); List<Treatment> treatments = Lists.newArrayList(experiment.getTreatments()); assertEquals("should contain expected number of treatments", 3, treatments.size()); List<Allocation> allocations = Lists.newArrayList(experiment.getAllocations()); assertEquals("should contain expected number of allocations", 6, allocations.size()); List<TreatmentOverride> overrides = Lists.newArrayList(experiment.getOverrides()); assertEquals("should contain override", 1, overrides.size()); experiment.removeTreatment("pie"); treatments = Lists.newArrayList(experiment.getTreatments()); assertEquals("should contain fewer treatments", 2, treatments.size()); allocations = Lists.newArrayList(experiment.getAllocations()); assertEquals("should contain fewer allocations", 4, allocations.size()); overrides = Lists.newArrayList(experiment.getOverrides()); assertEquals("should contain same override", 1, overrides.size()); experiment.removeTreatment("control"); treatments = Lists.newArrayList(experiment.getTreatments()); assertEquals("should contain fewer treatments", 1, treatments.size()); allocations = Lists.newArrayList(experiment.getAllocations()); assertEquals("should contain fewer allocations", 1, allocations.size()); overrides = Lists.newArrayList(experiment.getOverrides()); assertEquals("should contain no overrides", 0, overrides.size()); }