cushon / issues-import

0 stars 0 forks source link

Truth's Subject (and subclasses) expose predicates like isEqualTo. ".equals()" is always the wrong thing to call. #238

Open cushon opened 9 years ago

cushon commented 9 years ago

Original issue created by cgruber@google.com on 2014-03-11 at 12:09 AM


When using Truth or FEST, and calling an equivalence test on such things, of the form Truth.ASSERT.that(foo).equals(bar); is wrong. This will return a boolean, not run an assertion. This should be flagged as an error, and suppressed if equals() is properly being used to compare the testing framework's objects.

Examples:

Truth:

import static org.truth0.Truth.ASSERT; ASSERT.that(5).equals(6); // fails to fail.

FEST

assertThat(5).equals(6); // throws UnsupportedOperationException, but shoudl fail at compile time.

cushon commented 9 years ago

Original comment posted by cgruber@google.com on 2014-03-11 at 12:17 AM


Technically at head, Truth would fail, because it delegates equals() to isEqualTo() and is marked @deprecated, but it shoudl still be a compile-time check.

cushon commented 9 years ago

Original comment posted by eaftan@google.com on 2014-04-07 at 10:29 PM


This seems like something the Truth library should provide as an error-prone plugin, which we support inside Google. Come talk to error-prone team for help.


Owner: cgruber@google.com