“Use assertThat(actual).isGreaterThan(expected) instead.”
You are comparing "foo" and "bar", so actual is "foo" and expected is "bar".
This becomes:
assertThat("foo").isGreaterThan("bar");
Which is the simplified version.
That being said, I understand that the last step can be misunderstood. We tried at one point to provide a precise message, without actual and expected but the real values, but it turns out to be really complex and not even clearer.
In doubt, we expect the user to have a look at the rule description (which is currently broken in SonarCloud by the way, but it’s another problem) and go through examples to see the kind of simplifications are expected.
If you see a better way to report this issue, that would not have confused you, feel free to suggest it here.
In these tests, I am asserting that Comparable.compareTo() as implemented by my class (String in this example) provides the expected output (which is an int). Are you suggesting that the rule is suggesting that instead of directly testing that method, I should be relying on assertj to implicitly call compareTo() in it’s isGreaterThan() and isLessThan() assertions?
You can rely on Assertj to call compareTo() (or equals) in this situation.
In practice though, I would not argue if someone tells me that explicitly calling the method is better.
If you prefer to be explicit, you should resolve the issue as won’t fix. I think this situation is an acceptable corner case and I don’t see any easy improvement to improve it.
If you have ideas to improve the rule or believe the situation is unacceptable, feel free to come back to us with more examples and arguments to help to find a better solution.
Thank you. Looking at it again, it totally makes sense now.
Looking at the rule in SonarCloud, I did not see the reference to compareTo() that is clearly present when viewed in the Rules list on rules.sonarsource.com and which I think would have made sense to me then.