1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.testsupport.mocking;
7   
8   import edu.umd.cs.findbugs.annotations.NonNull;
9   import edu.umd.cs.findbugs.annotations.Nullable;
10  
11  /**
12   * Provides methods for mocking classes and interfaces for unit testing.
13   */
14  public interface IMockFactory {
15    /**
16     * Create a mock for the given class.
17     * <p>
18     * Automatically generates a name for the mocked object.
19     *
20     * @param <T>
21     *          the Java type to mock
22     * @param clazz
23     *          the class of the Java type to mock
24     * @return the mocked object
25     */
26    @NonNull
27    default <T> T mock(@NonNull Class<T> clazz) {
28      return mock(clazz, null);
29    }
30  
31    /**
32     * Create a mock for the given class.
33     * <p>
34     * Uses the provided name, if not {@code null}, or otherwise automatically
35     * generates a name for the mocked object.
36     *
37     * @param <T>
38     *          the Java type to mock
39     * @param clazz
40     *          the class of the Java type to mock
41     * @param name
42     *          the name to use for the mocked object if not {@code null}
43     * @return the mocked object
44     */
45    @NonNull
46    <T> T mock(@NonNull Class<T> clazz, @Nullable String name);
47  }