rspec/rules/S3415/java/rule.adoc
2023-10-19 15:48:44 +02:00

49 lines
1.4 KiB
Plaintext

== Why is this an issue?
The standard assertions library methods such as `org.junit.Assert.assertEquals`, and `org.junit.Assert.assertSame`
expect the first argument to be the expected value and the second argument to be the actual value.
For AssertJ instead, the argument of `org.assertj.core.api.Assertions.assertThat` is the actual value,
and the subsequent calls contain the expected values.
include::../impact.adoc[]
include::../howtofix.adoc[]
Supported frameworks:
* https://junit.org/junit4/[JUnit4]
* https://junit.org/junit5/docs/current/user-guide/[JUnit5]
* https://assertj.github.io/doc/[AssertJ]
=== Code examples
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
org.junit.Assert.assertEquals(runner.exitCode(), 0, "Unexpected exit code"); // Noncompliant; Yields error message like: Expected:<-1>. Actual:<0>.
org.assertj.core.api.Assertions.assertThat(0).isEqualTo(runner.exitCode()); // Noncompliant
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
org.junit.Assert.assertEquals(0, runner.exitCode(), "Unexpected exit code");
org.assertj.core.api.Assertions.assertThat(runner.exitCode()).isEqualTo(0);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
endif::env-github,rspecator-view[]