Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make order features applied in consistent #1177

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pitest/src/main/java/org/pitest/plugin/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Locale;
import java.util.Objects;

public final class Feature {
public final class Feature implements Comparable<Feature> {

private final boolean onByDefault;
private final boolean isInternal;
Expand All @@ -20,7 +20,6 @@ private Feature(boolean onByDefault, boolean isInternal, String name, String des
this.name = name;
this.description = description;
this.params = params;

}

public static Feature named(String name) {
Expand Down Expand Up @@ -83,4 +82,8 @@ public boolean equals(Object obj) {
}


@Override
public int compareTo(Feature o) {
return name.compareTo(o.name);
}
}
2 changes: 2 additions & 0 deletions pitest/src/main/java/org/pitest/plugin/FeatureSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -61,6 +62,7 @@ private List<T> selectFeatures(List<FeatureSetting> features, Collection<T> filt
}

return active.stream()
.sorted(Comparator.comparing(ProvidesFeature::provides))
.collect(Collectors.toList());
}

Expand Down
15 changes: 15 additions & 0 deletions pitest/src/test/java/org/pitest/plugin/FeatureSelectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public void doesNotDuplicateFeatures() {
assertThat(this.testee.getActiveFeatures()).hasSize(1);
}

@Test
public void ordersFeaturesConsistently() {
final FeatureSetting fooConfig = new FeatureSetting("bar", ToggleStatus.ACTIVATE, new HashMap<>());
this.testee = new FeatureSelector<>(Arrays.asList(fooConfig), features(this.onByDefault, this.offByDefault));

assertThat(this.testee.getActiveFeatures()).containsExactly(offByDefault, onByDefault);

// swap order
this.testee = new FeatureSelector<>(Arrays.asList(fooConfig), features(this.offByDefault, this.onByDefault));

assertThat(this.testee.getActiveFeatures()).containsExactly(offByDefault, onByDefault);

}


private List<FeatureSetting> noSettings() {
return Collections.emptyList();
}
Expand Down
14 changes: 14 additions & 0 deletions pitest/src/test/java/org/pitest/plugin/FeatureTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.pitest.plugin;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;

import java.util.List;

public class FeatureTest {

@Test
Expand All @@ -27,4 +30,15 @@ public void nameEqualityIsCaseInsensitive() {
.isEqualTo(Feature.named("FOO"));
}

@Test
public void ordersByName() {
Feature a = Feature.named("a");
Feature b = Feature.named("b");
Feature c = Feature.named("c");
Feature d = Feature.named("d");
List<Feature> features = asList(c, a, b, d);

assertThat(features.stream().sorted()).containsExactly(a, b, c, d);
}

}