All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.landel.utils.assertor.predicate.PredicateAssertorStepThrowable Maven / Gradle / Ivy

/*-
 * #%L
 * utils-assertor
 * %%
 * Copyright (C) 2016 - 2018 Gilles Landel
 * %%
 * 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.
 * #L%
 */
package fr.landel.utils.assertor.predicate;

import java.util.Locale;
import java.util.regex.Pattern;

import fr.landel.utils.assertor.Assertor;
import fr.landel.utils.assertor.StepAssertor;
import fr.landel.utils.assertor.commons.MessageAssertor;
import fr.landel.utils.assertor.helper.HelperStep;
import fr.landel.utils.assertor.utils.AssertorThrowable;

/**
 * This class define methods that can be applied on the checked
 * {@link Throwable} object. To provide a result, it's also provide a chain
 * builder by returning a {@link PredicateAssertorStepThrowable}. The chain looks
 * like:
 * 
 * 
 * {@link PredicateAssertorStepThrowable} > {@link PredicateAssertorStepThrowable} > {@link PredicateAssertorStepThrowable} > {@link PredicateAssertorStepThrowable}...
 * 
* * This chain always starts with a {@link PredicateAssertorStepThrowable} and ends * with {@link PredicateAssertorStepThrowable}. * * @since Aug 3, 2016 * @author Gilles * */ @FunctionalInterface public interface PredicateAssertorStepThrowable extends PredicateAssertorStep, T> { /** * {@inheritDoc} */ @Override default PredicateStepThrowable get(final StepAssertor result) { return () -> result; } /** * {@inheritDoc} */ @Override default PredicateAssertorStepThrowable not() { return () -> HelperStep.not(getStep()); } /** * Asserts that the given {@link Throwable} is an instance of {@code clazz} * and has the specified message. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).isInstanceOf(type, "Internal error").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param throwableMessage * the expected throwable message * @return The operator */ default PredicateStepThrowable isInstanceOf(final Class clazz, final CharSequence throwableMessage) { return this.isInstanceOf(clazz, throwableMessage, (CharSequence) null); } /** * Asserts that the given {@link Throwable} is an instance of {@code clazz} * and has the specified message. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).isInstanceOf(type, "Internal error", "not an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param throwableMessage * the expected throwable message * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isInstanceOf(final Class clazz, final CharSequence throwableMessage, final CharSequence message, final Object... arguments) { return this.isInstanceOf(clazz, throwableMessage, null, message, arguments); } /** * Asserts that the given {@link Throwable} is an instance of {@code clazz} * and has the specified message. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).isInstanceOf(type, "Internal error", Locale.US, "not an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param throwableMessage * the expected throwable message * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isInstanceOf(final Class clazz, final CharSequence throwableMessage, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.isInstanceOf(this.getStep(), clazz, throwableMessage, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} is an instance of {@code clazz} * and matches the pattern. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).isInstanceOf(type, pattern).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @return The operator */ default PredicateStepThrowable isInstanceOf(final Class clazz, final Pattern pattern) { return this.isInstanceOf(clazz, pattern, null); } /** * Asserts that the given {@link Throwable} is an instance of {@code clazz} * and matches the pattern. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).isInstanceOf(type, pattern, "not an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isInstanceOf(final Class clazz, final Pattern pattern, final CharSequence message, final Object... arguments) { return this.isInstanceOf(clazz, pattern, null, message, arguments); } /** * Asserts that the given {@link Throwable} is an instance of {@code clazz} * and matches the pattern. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).isInstanceOf(type, pattern, Locale.US, "not an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isInstanceOf(final Class clazz, final Pattern pattern, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.isInstanceOf(this.getStep(), clazz, pattern, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} is assignable from {@code clazz} * and has the specified message. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).isAssignableFrom(type, "Internal error").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param throwableMessage * the expected throwable message * @return The operator */ default PredicateStepThrowable isAssignableFrom(final Class clazz, final CharSequence throwableMessage) { return this.isAssignableFrom(clazz, throwableMessage, (CharSequence) null); } /** * Asserts that the given {@link Throwable} is assignable from {@code clazz} * and has the specified message. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).isAssignableFrom(type, "Internal error", "not an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param throwableMessage * the expected throwable message * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isAssignableFrom(final Class clazz, final CharSequence throwableMessage, final CharSequence message, final Object... arguments) { return this.isAssignableFrom(clazz, throwableMessage, null, message, arguments); } /** * Asserts that the given {@link Throwable} is assignable from {@code clazz} * and has the specified message. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).isAssignableFrom(type, "Internal error", Locale.US, "not an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param throwableMessage * the expected throwable message * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isAssignableFrom(final Class clazz, final CharSequence throwableMessage, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.isAssignableFrom(this.getStep(), clazz, throwableMessage, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} is assignable from {@code clazz} * and matches the pattern. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).isAssignableFrom(type, pattern).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @return The operator */ default PredicateStepThrowable isAssignableFrom(final Class clazz, final Pattern pattern) { return this.isAssignableFrom(clazz, pattern, null); } /** * Asserts that the given {@link Throwable} is assignable from {@code clazz} * and matches the pattern. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).isAssignableFrom(type, pattern, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isAssignableFrom(final Class clazz, final Pattern pattern, final CharSequence message, final Object... arguments) { return this.isAssignableFrom(clazz, pattern, null, message, arguments); } /** * Asserts that the given {@link Throwable} is assignable from {@code clazz} * and matches the pattern. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).isAssignableFrom(type, pattern, Locale.US, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable isAssignableFrom(final Class clazz, final Pattern pattern, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.isAssignableFrom(this.getStep(), clazz, pattern, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause not {@code null} * *

* precondition: throwable cannot be null *

* *
     * Assertor.that(throwable).hasCauseNotNull().orElseThrow();
     * 
* * @return The operator */ default PredicateStepThrowable hasCauseNotNull() { return this.hasCauseNotNull(null); } /** * Asserts that the given {@link Throwable} has a cause not {@code null} * *

* precondition: throwable cannot be null *

* *
     * Assertor.that(throwable).hasCauseNotNull("cause cannot be null").orElseThrow();
     * 
* * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseNotNull(final CharSequence message, final Object... arguments) { return this.hasCauseNotNull(null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause not {@code null} * *

* precondition: throwable cannot be null *

* *
     * Assertor.that(throwable).hasCauseNotNull(Locale.US, "cause cannot be null").orElseThrow();
     * 
* * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseNotNull(final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseNotNull(this.getStep(), MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause {@code null} * *

* precondition: throwable cannot be null *

* *
     * Assertor.that(throwable).hasCauseNull().orElseThrow();
     * 
* * @return The operator */ default PredicateStepThrowable hasCauseNull() { return this.hasCauseNull(null); } /** * Asserts that the given {@link Throwable} has a cause {@code null} * *

* precondition: throwable cannot be null *

* *
     * Assertor.that(throwable).hasCauseNull("cause must be null").orElseThrow();
     * 
* * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseNull(final CharSequence message, final Object... arguments) { return this.hasCauseNull(null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause {@code null} * *

* precondition: throwable cannot be null *

* *
     * Assertor.that(throwable).hasCauseNull(Locale.US, "cause must be null").orElseThrow();
     * 
* * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseNull(final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseNull(this.getStep(), MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz}. If {@code recursively} is set to true, the method will * check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, true).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final boolean recursively) { return this.hasCauseAssignableFrom(clazz, recursively, null); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz}. If {@code recursively} is set to true, the method will * check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, true, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final boolean recursively, final CharSequence message, final Object... arguments) { return this.hasCauseAssignableFrom(clazz, recursively, null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz}. If {@code recursively} is set to true, the method will * check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, true, Locale.US, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final boolean recursively, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseAssignableFrom(this.getStep(), clazz, recursively, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, exceptionMessage).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param exceptionMessage * the exception message * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final CharSequence exceptionMessage, final boolean recursively) { return this.hasCauseAssignableFrom(clazz, exceptionMessage, recursively, null); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, exceptionMessage, true, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param exceptionMessage * the exception message * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final CharSequence exceptionMessage, final boolean recursively, final CharSequence message, final Object... arguments) { return this.hasCauseAssignableFrom(clazz, exceptionMessage, recursively, null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, exceptionMessage, true, Locale.US, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param exceptionMessage * the exception message * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final CharSequence exceptionMessage, final boolean recursively, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseAssignableFrom(this.getStep(), clazz, exceptionMessage, recursively, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, pattern, true).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final Pattern pattern, final boolean recursively) { return this.hasCauseAssignableFrom(clazz, pattern, recursively, null); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, pattern, true, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final Pattern pattern, final boolean recursively, final CharSequence message, final Object... arguments) { return this.hasCauseAssignableFrom(clazz, pattern, recursively, null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause assignable from * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).hasCauseAssignableFrom(type, pattern, true, Locale.US, "not assignable from").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseAssignableFrom(final Class clazz, final Pattern pattern, final boolean recursively, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseAssignableFrom(this.getStep(), clazz, pattern, recursively, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz}. If {@code recursively} is set to true, the method will * check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, true).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final boolean recursively) { return this.hasCauseInstanceOf(clazz, recursively, null); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz}. If {@code recursively} is set to true, the method will * check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, true, "not with an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final boolean recursively, final CharSequence message, final Object... arguments) { return this.hasCauseInstanceOf(clazz, recursively, null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz}. If {@code recursively} is set to true, the method will * check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, true, Locale.US, "not with an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final boolean recursively, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseInstanceOf(this.getStep(), clazz, recursively, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, exceptionMessage).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param exceptionMessage * the exception message * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final CharSequence exceptionMessage, final boolean recursively) { return this.hasCauseInstanceOf(clazz, exceptionMessage, recursively, null); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, exceptionMessage, true, "not with an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param exceptionMessage * the exception message * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final CharSequence exceptionMessage, final boolean recursively, final CharSequence message, final Object... arguments) { return this.hasCauseInstanceOf(clazz, exceptionMessage, recursively, null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable and clazz cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, exceptionMessage, true, Locale.US, "not with an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param exceptionMessage * the exception message * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final CharSequence exceptionMessage, final boolean recursively, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseInstanceOf(this.getStep(), clazz, exceptionMessage, recursively, MessageAssertor.of(locale, message, arguments)); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, pattern, true).orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final Pattern pattern, final boolean recursively) { return this.hasCauseInstanceOf(clazz, pattern, recursively, null); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, pattern, true, "not with an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final Pattern pattern, final boolean recursively, final CharSequence message, final Object... arguments) { return this.hasCauseInstanceOf(clazz, pattern, recursively, null, message, arguments); } /** * Asserts that the given {@link Throwable} has a cause with an instance of * {@code clazz} and matches the pattern. If {@code recursively} is set to * true, the method will check the cause of cause recursively. * *

* precondition: throwable, clazz and pattern cannot be null *

* *
     * Assertor.that(throwable).hasCauseInstanceOf(type, pattern, true, Locale.US, "not with an instance of").orElseThrow();
     * 
* * @param clazz * The super {@link Class} (super class or interface) * @param pattern * the message pattern * @param recursively * if true, sub causes are checked until a cause has the type and * matches the pattern * @param locale * The locale of the message (only used to format this message, * otherwise use {@link Assertor#setLocale}) * @param message * The message on mismatch * @param arguments * The arguments of the message, use {@link String#format} * @return The operator */ default PredicateStepThrowable hasCauseInstanceOf(final Class clazz, final Pattern pattern, final boolean recursively, final Locale locale, final CharSequence message, final Object... arguments) { return () -> AssertorThrowable.hasCauseInstanceOf(this.getStep(), clazz, pattern, recursively, MessageAssertor.of(locale, message, arguments)); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy