Skip to content

Commit

Permalink
missing tests for feature ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed May 25, 2023
1 parent 9edac2a commit 61fff8e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pitest/src/main/java/org/pitest/plugin/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public int compareTo(Feature o) {
.thenComparing(Feature::name)
.compare(this, o);
}

@Override
public String toString() {
return name;
}
}
28 changes: 28 additions & 0 deletions pitest/src/test/java/org/pitest/plugin/FeatureSelectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ public void ordersFeaturesConsistently() {

}

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

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

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

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

}




private List<FeatureSetting> noSettings() {
return Collections.emptyList();
Expand All @@ -123,6 +140,17 @@ public Feature provides() {

}

class ProvidesFooByDefaultWithOrder1 implements AFeature {

@Override
public Feature provides() {
return Feature.named("foo")
.withOnByDefault(true)
.withOrder(1);
}

}

class ProvidesBarOptionally implements AFeature {

@Override
Expand Down
24 changes: 23 additions & 1 deletion pitest/src/test/java/org/pitest/plugin/FeatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void nameEqualityIsCaseInsensitive() {
}

@Test
public void ordersByName() {
public void ordersByNameWhenOrderValueEqual() {
Feature a = Feature.named("a");
Feature b = Feature.named("b");
Feature c = Feature.named("c");
Expand All @@ -41,4 +41,26 @@ public void ordersByName() {
assertThat(features.stream().sorted()).containsExactly(a, b, c, d);
}

@Test
public void ordersByOrderValueWhenValuesDiffer() {
Feature a = Feature.named("a").withOrder(4);
Feature b = Feature.named("b").withOrder(3);
Feature c = Feature.named("c").withOrder(2);
Feature d = Feature.named("d").withOrder(1);
List<Feature> features = asList(c, a, b, d);

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

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

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

}

0 comments on commit 61fff8e

Please sign in to comment.