Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public class WeightedStep implements Comparable<WeightedStep>, HasHTMLComment {
public final StepCandidate stepCandidate;
public final float weight;

public WeightedStep(StepCandidate stepCandidate, float weight) {
public WeightedStep(final StepCandidate stepCandidate, final float weight) {
this.stepCandidate = stepCandidate;
this.weight = weight;
}

@Override
public int compareTo(WeightedStep o) {
return (weight > o.weight) ? 1 : -1;
public int compareTo(final WeightedStep o) {
return Float.compare(weight, o.weight);
}

private String htmlComment;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jbehave.eclipse.editor.step;

import static org.junit.Assert.assertEquals;

import java.util.Collections;
import java.util.List;

import org.junit.Test;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

public class WeightedStepTest {

@Test
public void testSorting() {
WeightedStep s1 = new WeightedStep(null, 1.1f);
WeightedStep s1Also = new WeightedStep(null, 1.1f);
WeightedStep s2 = new WeightedStep(null, 1.2f);
WeightedStep s3 = new WeightedStep(null, 1.3f);

List<WeightedStep> list = Lists.newArrayList(s1, s3, s2, s1Also);
Collections.sort(list);

// Note we expect the relative ordering of s1Also and s1 to be preserved as they're equal
List<WeightedStep> expectedSortOrder = ImmutableList.of(s1, s1Also, s2, s3);
assertEquals(expectedSortOrder, list);

assertEquals(0, s1.compareTo(s1Also));
}

}