rspec/rules/S2701/java/rule.adoc

47 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
2020-06-30 12:48:07 +02:00
There's no reason to use literal boolean values or nulls in assertions. Instead of using them with _assertEquals_, _assertNotEquals_ and similar methods, you should be using _assertTrue_, _assertFalse_, _assertNull_ or _assertNotNull_ instead (or _isNull_ etc. when using Fest). Using them with assertions unrelated to equality (such as _assertNull_) is most likely a bug.
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
Supported frameworks:
2020-06-30 12:48:07 +02:00
* JUnit3
* JUnit4
* JUnit5
* Fest assert
=== Noncompliant code example
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 12:48:07 +02:00
----
Assert.assertTrue(true); // Noncompliant
assertThat(null).isNull(); // Noncompliant
assertEquals(true, something()); // Noncompliant
assertNotEquals(null, something()); // Noncompliant
----
=== Compliant solution
2020-06-30 12:48:07 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 12:48:07 +02:00
----
assertTrue(something());
assertNotNull(something());
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]