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