/*
 * Copyright 2019, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.testing.server.model;

import io.spine.server.model.Model;

import java.lang.reflect.Method;
import java.util.Arrays;

import static io.spine.util.Exceptions.newIllegalStateException;

/**
 * Utilities for tests that deal with {@link Model}.
 *
 * @implNote The full name of this class is used by {@link Model#dropAllModels()} via a
 *           string literal for security check.
 * @author Alexander Yevsyukov
 */
public final class ModelTests {

    /** Prevents instantiation of this utility class. */
    private ModelTests() {
    }

    /**
     * Clears all models.
     *
     * @implNote This method is the only way to drop models because {@link Model#dropAllModels()}
     * verifies the name of the class which calls the method.
     * It must be {@linkplain ModelTests this class}.
     */
    public static void dropAllModels() {
        Model.dropAllModels();
    }

    /**
     * Obtains a method declared in the passed class with the given name.
     * @throws IllegalStateException if the class does not have such a method.
     */
    public static Method getMethod(Class<?> cls, String methodName) {
        Method[] methods = cls.getDeclaredMethods();

        Method result =
                Arrays.stream(methods)
                      .filter(method -> methodName.equals(method.getName()))
                      .findFirst()
                      .orElseThrow(
                              () -> newIllegalStateException(
                                      "No method named `%s` found in class `%s`",
                                      methodName,
                                      cls.getName()
                              )
                      );

        return result;
    }
}

@@ -1788,17 +1788,12 @@
 e %7B@
-linkplain
+code
  Mod
@@ -2545,16 +2545,17 @@
 ass %60%25s%60
+.
 %22,%0A     

Remove redundant Javadoc link