Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into gh-3368
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Apr 12, 2024
2 parents a7cb7bb + a1e7669 commit a95df78
Show file tree
Hide file tree
Showing 29 changed files with 1,261 additions and 536 deletions.
10 changes: 5 additions & 5 deletions assertj-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<rootDirectory>${project.basedir}/../</rootDirectory>
<spotless.skip>false</spotless.skip>
<!-- Dependency versions -->
<byte-buddy.version>1.14.12</byte-buddy.version>
<byte-buddy.version>1.14.13</byte-buddy.version>
<hamcrest.version>2.2</hamcrest.version>
<!-- Plugin versions -->
<cdg.pitest.version>1.1.4</cdg.pitest.version>
Expand Down Expand Up @@ -99,7 +99,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.15.1</version>
<version>2.16.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -123,7 +123,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.16</version>
<version>3.16.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -197,7 +197,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.33</version>
<version>5.3.34</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -447,7 +447,7 @@
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.15.8</version>
<version>1.16.0</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static java.util.Objects.requireNonNull;
import static org.assertj.core.error.ClassModifierShouldBe.shouldBeFinal;
import static org.assertj.core.error.ClassModifierShouldBe.shouldBePackagePrivate;
import static org.assertj.core.error.ClassModifierShouldBe.shouldBePrivate;
import static org.assertj.core.error.ClassModifierShouldBe.shouldBeProtected;
import static org.assertj.core.error.ClassModifierShouldBe.shouldBePublic;
import static org.assertj.core.error.ClassModifierShouldBe.shouldBeStatic;
Expand Down Expand Up @@ -508,7 +509,7 @@ private void assertIsProtected() {
}

/**
* Verifies that the actual {@code Class} is package-private (has no modifier).
* Verifies that the actual {@code Class} is package-private (i.e., has no explicit access level modifier).
* <p>
* Example:
* <pre><code class='java'> class MyClass { }
Expand Down Expand Up @@ -539,6 +540,37 @@ private void assertIsPackagePrivate() {
}
}

/**
* Verifies that the actual {@code Class} is private (has {@code private} modifier).
* <p>
* Example:
* <pre><code class='java'> class EnclosingClass {
* private static class PrivateClass { }
* }
*
* // these assertions succeed:
* assertThat(PrivateClass.class).isPrivate();
* assertThat(Class.forName(EnclosingClass.class.getName() + "$PrivateClass")).isPrivate();
*
* // This assertion fails:
* assertThat(String.class).isPrivate();</code></pre>
*
* @return {@code this} assertions object
* @throws AssertionError if {@code actual} is {@code null}.
* @throws AssertionError if the actual {@code Class} is not private.
*
* @since 3.26.0
*/
public SELF isPrivate() {
isNotNull();
assertIsPrivate();
return myself;
}

private void assertIsPrivate() {
if (!Modifier.isPrivate(actual.getModifiers())) throw assertionError(shouldBePrivate(actual));
}

/**
* Verifies that the actual {@code Class} is static (has {@code static} modifier).
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void assertAll() {
*
* @param <T> dummy return value type
* @param failureMessage error message.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail("boom")));}.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> softly.fail("boom")));}.
* @since 2.6.0 / 3.6.0
*/
@CanIgnoreReturnValue
Expand All @@ -63,13 +63,27 @@ public <T> T fail(String failureMessage) {
return null;
}

/**
* Fails with an empty message to be used in code like:
* <pre><code class='java'> doSomething(optional.orElseGet(() -> softly.fail()));</code></pre>
*
* @param <T> dummy return value type
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> softly.fail()));}.
* @since 3.26.0
*/
@CanIgnoreReturnValue
public <T> T fail() {
// pass an empty string because passing null results in a "null" error message.
return fail("");
}

/**
* Fails with the given message built like {@link String#format(String, Object...)}.
*
* @param <T> dummy return value type
* @param failureMessage error message.
* @param args Arguments referenced by the format specifiers in the format string.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail("boom")));}.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> softly.fail("boom")));}.
* @since 2.6.0 / 3.6.0
*/
@CanIgnoreReturnValue
Expand All @@ -83,7 +97,7 @@ public <T> T fail(String failureMessage, Object... args) {
* @param <T> dummy return value type
* @param failureMessage error message.
* @param realCause cause of the error.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail("boom")));}.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> softly.fail("boom")));}.
* @since 2.6.0 / 3.6.0
*/
@CanIgnoreReturnValue
Expand All @@ -94,6 +108,22 @@ public <T> T fail(String failureMessage, Throwable realCause) {
return null;
}

/**
* Fails with the {@link Throwable} that caused the failure and an empty message.
* <p>
* Example:
* <pre><code class='java'> doSomething(optional.orElseGet(() -> softly.fail(cause)));</code></pre>
*
* @param <T> dummy return value type
* @param realCause cause of the error.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> softly.fail(cause)));}.
* @since 3.26.0
*/
@CanIgnoreReturnValue
public <T> T fail(Throwable realCause) {
return fail("", realCause);
}

/**
* Fails with a message explaining that a {@link Throwable} of given class was expected to be thrown
* but had not been.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public SELF usingDefaultComparator() {
* Verifies that the actual value is equal to expected build using {@link String#format(String stringTemplate, Object... args)}.
* <p>
* Note that for this assertion to be called, <b>you must use a format template with parameters</b> otherwise {@link #isEqualTo(Object)} is called which
* does not perform any formatting. For example, it you only use {@code %n} in the template they won't be replaced.
* does not perform any formatting. For example, if you only use {@code %n} in the template they won't be replaced.
* <p>
* Examples:
* <pre><code class='java'> // assertion succeeds
Expand Down
31 changes: 31 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,20 @@ public static <T> T fail(String failureMessage) {
return Fail.fail(failureMessage);
}

/**
* Throws an {@link AssertionError} with an empty message to be used in code like:
* <pre><code class='java'> doSomething(optional.orElseGet(() -> fail()));</code></pre>
*
* @param <T> dummy return value type
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail()));}.
* @throws AssertionError with an empty message.
* @since 3.26.0
*/
@CanIgnoreReturnValue
public static <T> T fail() {
return Fail.fail();
}

/**
* Throws an {@link AssertionError} with the given message built as {@link String#format(String, Object...)}.
*
Expand Down Expand Up @@ -1826,6 +1840,23 @@ public static <T> T fail(String failureMessage, Throwable realCause) {
return Fail.fail(failureMessage, realCause);
}

/**
* Throws an {@link AssertionError} with the {@link Throwable} that caused the failure and an empty message.
* <p>
* Example:
* <pre><code class='java'> doSomething(optional.orElseGet(() -> fail(cause)));</code></pre>
*
* @param <T> dummy return value type
* @param realCause cause of the error.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail(cause)));}.
* @throws AssertionError with the {@link Throwable} that caused the failure.
*/
@CanIgnoreReturnValue
public static <T> T fail(Throwable realCause) {
// pass an empty string because passing null results in a "null" error message.
return fail("", realCause);
}

/**
* Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown
* but had not been.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,16 @@ public static void fail(String failureMessage) {
Fail.fail(failureMessage);
}

/**
* Only delegate to {@link Fail#fail()} so that {@link Assertions} offers a full feature entry point to all Assertj
* features (but you can use {@code Fail} if you prefer).
*
* @throws AssertionError without message.
*/
public static void fail() {
Fail.fail();
}

/**
* Only delegate to {@link Fail#fail(String, Throwable)} so that Assertions offers a full feature entry point to all
* AssertJ features (but you can use Fail if you prefer).
Expand All @@ -983,6 +993,17 @@ public static void fail(String failureMessage, Throwable realCause) {
Fail.fail(failureMessage, realCause);
}

/**
* Only delegate to {@link Fail#fail(Throwable)} so that Assertions offers a full feature entry point to all
* AssertJ features (but you can use Fail if you prefer).
*
* @param realCause cause of the error.
* @throws AssertionError with the {@link Throwable} that caused the failure.
*/
public static void fail(Throwable realCause) {
Fail.fail(realCause);
}

/**
* Only delegate to {@link Fail#failBecauseExceptionWasNotThrown(Class)} so that Assertions offers a full feature
* entry point to all AssertJ features (but you can use Fail if you prefer).
Expand Down
26 changes: 26 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/BDDAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,20 @@ public static <T> T fail(String failureMessage) {
return Assertions.fail(failureMessage);
}

/**
* Throws an {@link AssertionError} with an empty message to be used in code like:
* <pre><code class='java'> doSomething(optional.orElseGet(() -> fail()));</code></pre>
*
* @param <T> dummy return value type
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail()));}.
* @throws AssertionError with an empty message.
* @since 3.26.0
*/
@CanIgnoreReturnValue
public static <T> T fail() {
return Assertions.fail();
}

/**
* Throws an {@link AssertionError} with the given message built as {@link String#format(String, Object...)}.
*
Expand Down Expand Up @@ -2327,6 +2341,18 @@ public static <T> T fail(String failureMessage, Throwable realCause) {
return Assertions.fail(failureMessage, realCause);
}

/**
* Throws an {@link AssertionError} with the {@link Throwable} that caused the failure.
* @param <T> dummy return value type
* @param realCause cause of the error.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail(cause)));}.
* @throws AssertionError with the {@link Throwable} that caused the failure.
*/
@CanIgnoreReturnValue
public static <T> T fail(Throwable realCause) {
return fail(null, realCause);
}

/**
* Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown
* but had not been.
Expand Down
28 changes: 28 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/Fail.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public static <T> T fail(String failureMessage) {
throw Failures.instance().failure(failureMessage);
}

/**
* Throws an {@link AssertionError} with an empty message to be used in code like:
* <pre><code class='java'> doSomething(optional.orElseGet(() -> fail()));</code></pre>
*
* @param <T> dummy return value type
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail()));}.
* @throws AssertionError with an empty message.
* @since 3.26.0
*/
@CanIgnoreReturnValue
public static <T> T fail() {
// pass an empty string because passing null results in a "null" error message.
return fail("");
}

/**
* Throws an {@link AssertionError} with the given message built as {@link String#format(String, Object...)}.
*
Expand Down Expand Up @@ -76,6 +91,19 @@ public static <T> T fail(String failureMessage, Throwable realCause) {
throw error;
}

/**
* Throws an {@link AssertionError} with the {@link Throwable} that caused the failure.
*
* @param <T> dummy return value type
* @param realCause cause of the error.
* @return nothing, it's just to be used in {@code doSomething(optional.orElseGet(() -> fail(cause)));}.
* @throws AssertionError with the {@link Throwable} that caused the failure.
*/
@CanIgnoreReturnValue
public static <T> T fail(Throwable realCause) {
return fail(null, realCause);
}

/**
* Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown
* but had not been.
Expand Down

0 comments on commit a95df78

Please sign in to comment.