1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 6 package org.mockito.mock; 7 8 import org.mockito.Incubating; 9 import org.mockito.MockSettings; 10 import org.mockito.NotExtensible; 11 import org.mockito.listeners.InvocationListener; 12 import org.mockito.listeners.VerificationStartedListener; 13 import org.mockito.quality.Strictness; 14 import org.mockito.stubbing.Answer; 15 16 import java.util.List; 17 import java.util.Set; 18 19 /** 20 * Informs about the mock settings. An immutable view of {@link org.mockito.MockSettings}. 21 */ 22 @NotExtensible 23 public interface MockCreationSettings<T> { 24 25 /** 26 * Mocked type. An interface or class the mock should implement / extend. 27 */ getTypeToMock()28 Class<T> getTypeToMock(); 29 30 /** 31 * the extra interfaces the mock object should implement. 32 */ getExtraInterfaces()33 Set<Class<?>> getExtraInterfaces(); 34 35 /** 36 * the name of this mock, as printed on verification errors; see {@link org.mockito.MockSettings#name}. 37 */ getMockName()38 MockName getMockName(); 39 40 /** 41 * the default answer for this mock, see {@link org.mockito.MockSettings#defaultAnswer}. 42 */ getDefaultAnswer()43 Answer<?> getDefaultAnswer(); 44 45 /** 46 * the spied instance - needed for spies. 47 */ getSpiedInstance()48 Object getSpiedInstance(); 49 50 /** 51 * if the mock is serializable, see {@link org.mockito.MockSettings#serializable}. 52 */ isSerializable()53 boolean isSerializable(); 54 55 /** 56 * @return the serializable mode of this mock 57 */ getSerializableMode()58 SerializableMode getSerializableMode(); 59 60 /** 61 * Whether the mock is only for stubbing, i.e. does not remember 62 * parameters on its invocation and therefore cannot 63 * be used for verification 64 */ isStubOnly()65 boolean isStubOnly(); 66 67 /** 68 * Whether the mock should not make a best effort to preserve annotations. 69 */ isStripAnnotations()70 boolean isStripAnnotations(); 71 72 /** 73 * {@link InvocationListener} instances attached to this mock, see {@link org.mockito.MockSettings#invocationListeners}. 74 */ getInvocationListeners()75 List<InvocationListener> getInvocationListeners(); 76 77 /** 78 * {@link VerificationStartedListener} instances attached to this mock, 79 * see {@link org.mockito.MockSettings#verificationStartedListeners(VerificationStartedListener...)} 80 * 81 * @since 2.11.0 82 */ 83 @Incubating getVerificationStartedListeners()84 List<VerificationStartedListener> getVerificationStartedListeners(); 85 86 /** 87 * Informs whether the mock instance should be created via constructor 88 * 89 * @since 1.10.12 90 */ 91 @Incubating isUsingConstructor()92 boolean isUsingConstructor(); 93 94 /** 95 * Used when arguments should be passed to the mocked object's constructor, regardless of whether these 96 * arguments are supplied directly, or whether they include the outer instance. 97 * 98 * @return An array of arguments that are passed to the mocked object's constructor. If 99 * {@link #getOuterClassInstance()} is available, it is prepended to the passed arguments. 100 * 101 * @since 2.7.14 102 */ 103 @Incubating getConstructorArgs()104 Object[] getConstructorArgs(); 105 106 /** 107 * Used when mocking non-static inner classes in conjunction with {@link #isUsingConstructor()} 108 * 109 * @return the outer class instance used for creation of the mock object via the constructor. 110 * @since 1.10.12 111 */ 112 @Incubating getOuterClassInstance()113 Object getOuterClassInstance(); 114 115 /** 116 * Informs if the mock was created with "lenient" strictness, e.g. having {@link Strictness#LENIENT} characteristic. 117 * For more information about using mocks with lenient strictness, see {@link MockSettings#lenient()}. 118 * 119 * @since 2.20.0 120 */ 121 @Incubating isLenient()122 boolean isLenient(); 123 } 124