hamcrest / JavaHamcrest

Java (and original) version of Hamcrest

Home Page:http://hamcrest.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Matcher: greaterThan flacky

osyanin opened this issue · comments

commented
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?