Matcher: greaterThan flacky
osyanin opened this issue · comments
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
String balanceCurrency = somePage.balance("currency").shouldNotHave(text("----")).getText();
assertThat("Balance in not enough: ", balanceCurrency, is(greaterThan("100000000000.0000")));
Actual balance is: 7603.5911
Assert should be False and describe why, but it not fails.
But if I change "100000000000.0000" to "99999999999999999999999999999999999999999999999999999.0000" it now will fail with proper message.
the variable balanceCurrency
is a java.lang.String
, hamcrest does not magically covert strings that look like numbers.
You'll need to change it to a Float or Double depending what range and precision you need for this field.
Double balanceCurrency = Double.valueOf("7603.5911"); assertThat("Balance in not enough: ", balanceCurrency, is(greaterThan(Double.valueOf("100000000000.0000"))));
Hamcrest should probably thrown and exception for this use case as it doesn't make sense for an end user the combination of string and greaterThan.
Hamcrest should probably thrown and exception for this use case as it doesn't make sense for an end user the combination of string and greaterThan.
greaterThan
makes perfect sense for anything that implements Comparable
, including String
.
I certainly agree with the invalid
label on this issue - can someone just close this please?