/*
 * Copyright (c) 2010-2017. Axon Framework
 *
 * 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.
 */

package org.axonframework.common;

import java.util.function.Supplier;

/**
 * Utility class (inspired by Springs Assert class) for doing assertions on parameters and object state. To remove the
 * need for explicit dependencies on Spring, the functionality of that class is migrated to this class.
 *
 * @author Allard Buijze
 * @since 0.3
 */
public abstract class Assert {

    private Assert() {
        // utility class
    }

    /**
     * Asserts that the value of {@code state} is true. If not, an IllegalStateException is thrown.
     *
     * @param state           the state validation expression
     * @param messageSupplier Supplier of the exception message if state evaluates to false
     */
    public static void state(boolean state, Supplier<String> messageSupplier) {
        if (!state) {
            throw new IllegalStateException(messageSupplier.get());
        }
    }

    /**
     * Asserts that the given {@code expression} is true. If not, an IllegalArgumentException is thrown.
     *
     * @param expression      the state validation expression
     * @param messageSupplier Supplier of the exception message if the expression evaluates to false
     */
    public static void isTrue(boolean expression, Supplier<String> messageSupplier) {
        if (!expression) {
            throw new IllegalArgumentException(messageSupplier.get());
        }
    }

    /**
     * Asserts that the given {@code expression} is false. If not, an IllegalArgumentException is thrown.
     *
     * @param expression      the state validation expression
     * @param messageSupplier Supplier of the exception message if the expression evaluates to true
     */
    public static void isFalse(boolean expression, Supplier<String> messageSupplier) {
        if (expression) {
            throw new IllegalArgumentException(messageSupplier.get());
        }
    }

    /**
     * Assert that the given {@code value} is not {@code null}. If not, an IllegalArgumentException is
     * thrown.
     *
     * @param value           the value not to be {@code null}
     * @param messageSupplier Supplier of the exception message if the assertion fails
     */
    public static void notNull(Object value, Supplier<String> messageSupplier) {
        isTrue(value != null, messageSupplier);
    }

    /**
     * Assert that the given {@code value} is not {@code null}. If not, an IllegalArgumentException is
     * thrown.
     *
     * @param value           the value not to be {@code null}
     * @param messageSupplier Supplier of the exception message if the assertion fails
     * @return the provided {@code value}
     */
    public static <T> T nonNull(T value, Supplier<String> messageSupplier) {
        isTrue(value != null, messageSupplier);
        return value;
    }

}

@@ -637,16 +637,53 @@
 ommon;%0A%0A
+import java.util.function.Predicate;%0A
 import j
@@ -3433,10 +3433,1186 @@
 %0A    %7D%0A%0A
+    /**%0A     * Assert that the given %7B@code value%7D will result to %7B@code true%7D through the %7B@code assertion%7D  %7B@link Predicate%7D.%0A     * If not, the %7B@code exceptionSupplier%7D provides an exception%0A     * to be thrown.%0A     *%0A     * @param value             a %7B@code T%7D specifying the value to assert%0A     * @param assertion         a %7B@link Predicate%7D to test %7B@code value%7D against%0A     * @param exceptionSupplier a %7B@link Supplier%7D of the exception %7B@code X%7D if %7B@code assertion%7D evaluates to false%0A     * @param %3CT%3E               a generic specifying the type of the %7B@code value%7D, which is the input for the%0A     *                          %7B@code assertion%7D%0A     * @param %3CX%3E               a generic extending %7B@link Throwable%7D which will be provided by the%0A     *                          %7B@code exceptionSupplier%7D%0A     */%0A    public static %3CT, X extends Throwable%3E void assertThat(T value,%0A                                                           Predicate%3CT%3E assertion,%0A                                                           Supplier%3C? extends X%3E exceptionSupplier) %7B%0A        if (!assertion.test(value)) %7B%0A            throw exceptionSupplier.get();%0A        %7D%0A    %7D%0A
 %7D%0A

Introduce lenient assertThat() function