Instead of relying on a comparator, use Hamcrest
lessThan
and greaterThan
matchers. In your step definition:
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
...
if(condition.equals("less than")) {
assertThat(val, lessThan(count));
} else if(condition.equals("greater than")) {
assertThat(val, greaterThan(count));
}
You can enrich that to include all possible conditions:
switch(condition.toLowerCase()) {
case "less than":
case "<":
assertThat(val, lessThan(count));
break;
case "less than or equal to":
case "<=":
assertThat(val, lessThanOrEqualTo(count));
break;
case "greater than":
case ">":
assertThat(val, greaterThan(count));
break;
case "greater than or equal to":
case ">=":
assertThat(val, greaterThanOrEqualTo(count));
break;
...
}
Note that you will need to depend on the Hamcrest library in your project (in case it is not already a dependency).