Skip to content

Commit

Permalink
Fixes problems caused by @CheckReturnValue (#1310)
Browse files Browse the repository at this point in the history
Allow return value of fail* methods to be ignored with CanIgnoreReturnValue annotation.
  • Loading branch information
epeee authored and joel-costigliola committed Aug 27, 2018
1 parent c2aecaf commit aaefa62
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/assertj/core/api/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import org.assertj.core.presentation.Representation;
import org.assertj.core.presentation.StandardRepresentation;
import org.assertj.core.presentation.UnicodeRepresentation;
import org.assertj.core.util.CanIgnoreReturnValue;
import org.assertj.core.util.CheckReturnValue;
import org.assertj.core.util.Files;
import org.assertj.core.util.URLs;
Expand Down Expand Up @@ -1331,6 +1332,7 @@ public static void setRemoveAssertJRelatedElementsFromStackTrace(boolean removeA
* @return nothing, it's just to be used in doSomething(optional.orElse(() -> fail("boom")));.
* @throws AssertionError with the given message.
*/
@CanIgnoreReturnValue
public static <T> T fail(String failureMessage) {
return Fail.fail(failureMessage);
}
Expand All @@ -1344,6 +1346,7 @@ public static <T> T fail(String failureMessage) {
* @return nothing, it's just to be used in doSomething(optional.orElse(() -&gt; fail("b%s", ""oom)));.
* @throws AssertionError with the given built message.
*/
@CanIgnoreReturnValue
public static <T> T fail(String failureMessage, Object... args) {
return Fail.fail(failureMessage, args);
}
Expand All @@ -1356,6 +1359,7 @@ public static <T> T fail(String failureMessage, Object... args) {
* @return nothing, it's just to be used in doSomething(optional.orElse(() -&gt; fail("boom", cause)));.
* @throws AssertionError with the given message and with the {@link Throwable} that caused the failure.
*/
@CanIgnoreReturnValue
public static <T> T fail(String failureMessage, Throwable realCause) {
return Fail.fail(failureMessage, realCause);
}
Expand All @@ -1373,6 +1377,7 @@ public static <T> T fail(String failureMessage, Throwable realCause) {
* not been.
*
*/
@CanIgnoreReturnValue
public static <T> T failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass) {
return Fail.shouldHaveThrown(throwableClass);
}
Expand All @@ -1386,6 +1391,7 @@ public static <T> T failBecauseExceptionWasNotThrown(Class<? extends Throwable>
* @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had
* not been.
*/
@CanIgnoreReturnValue
public static <T> T shouldHaveThrown(Class<? extends Throwable> throwableClass) {
return Fail.shouldHaveThrown(throwableClass);
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/assertj/core/util/CanIgnoreReturnValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2018 the original author or authors.
*/
package org.assertj.core.util;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation to skip "CheckReturnValue" check.
*/
@Target({
ElementType.CONSTRUCTOR,
ElementType.METHOD,
ElementType.PACKAGE,
ElementType.TYPE,
})
@Retention(RetentionPolicy.CLASS)
public @interface CanIgnoreReturnValue {
}

0 comments on commit aaefa62

Please sign in to comment.