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