コンパレータに頼る代わりに、Hamcrest
lessThan
とgreaterThan
マッチャを使用してください。あなたのステップの定義で:
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));
}
あなたはすべての可能な条件含めることを豊かにすることができます:あなたのプロジェクトでHamcrestライブラリに依存する必要があります
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;
...
}
注意を(場合には、それはまだありません依存関係)。