Open tomg246 opened 1 year ago
For the second best solution: the annotation @org.jetbrains.annotations.Contract(pure=true) at a method seems to activate the "result of ... is ignored" warning
Yes, this is a design flaw of the inline assertion API. I think a good solution would be, to warn for unfulfilled BinaryAssertions
in the finalize()
method.
public void finalize() {
if (!_fullfilled) {
log().warn(createFailMessage(" was not fulfilled"));
}
}
I've stumbled across this situation as well. Another possible annotation I would suggest, is @CheckReturnValue
as provided by jsr305, SpotBugs or Error Prone. While jsr305 is not actively maintained anymore, it is already pulled in as implicit dependency by TestNG and Guava. It also has out-of-the-box-support in IntelliJ .
Yes, this is a design flaw of the inline assertion API. I think a good solution would be, to warn for unfulfilled
BinaryAssertions
in thefinalize()
method.public void finalize() { if (!_fullfilled) { log().warn(createFailMessage(" was not fulfilled")); } }
Do you mean a finalize()
in DefaultBinaryAssertion
? Some notes for that:
finalize()
is deprecated since Java 9. Alternative should be the Cleaner API (increased the complexity).StringAssertion
or QuantityAssertion
extends from BinaryAssertion
. Just a simple getActual
of a String attribute "calls" the finalize()
. Therefor there is needed a complex check if a is
call is needed or not.The best way but with the biggest pain is to clean the Assertion API, maybe the removal of is
.
Other helpers like @org.jetbrains.annotations.Contract
are vendor based.
Problem. This does an assertion:
uiElement.assertThat().text().is("text");
This reads and feels the same but does nothing:uiElement.assertThat().text().contains("sisdfn");
The main problem is that i won't notice my mistake which leads to tests that don't do the assertions i expect them to do.
Solution Best would be an implicit
.is(true)
when no assertion is done. Second best seems the addition of a compiler warning or something alike, to increase my chance of noticing my mistake, see e.g.