• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.configuration;
6 
7 import org.mockito.ReturnValues;
8 import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;
9 import org.mockito.stubbing.Answer;
10 
11 /**
12  * Use it to configure Mockito. For now there are not many configuration options but it may change in future.
13  * <p>
14  * In most cases you don't really need to configure Mockito. For example in case of working with legacy code,
15  * when you might want to have different 'mocking style' this interface might be helpful.
16  * A reason of configuring Mockito might be if you disagree with the {@link ReturnsEmptyValues} unstubbed mocks return.
17  * <p>
18  * To configure Mockito create exactly <b>org.mockito.configuration.MockitoConfiguration</b> class that implements this interface.
19  * <p>
20  * Configuring Mockito is completely <b>optional</b> - nothing happens if there isn't any <b>org.mockito.configuration.MockitoConfiguration</b> on the classpath.
21  * <p>
22  * <b>org.mockito.configuration.MockitoConfiguration</b> must implement IMockitoConfiguration or extend {@link DefaultMockitoConfiguration}
23  * <p>
24  * Mockito will store single instance of org.mockito.configuration.MockitoConfiguration per thread (using ThreadLocal).
25  * For sanity of your tests, don't make the implementation stateful.
26  * <p>
27  * If you have comments on Mockito configuration feature don't hesitate to write to mockito@googlegroups.com
28  */
29 @SuppressWarnings("deprecation")//supressed until ReturnValues are removed
30 public interface IMockitoConfiguration {
31 
32     /**
33      * @deprecated
34      * <b>Please use {@link IMockitoConfiguration#getDefaultAnswer()}</b>
35      * <p>
36      * Steps:
37      * <p>
38      * 1. Leave the implementation of getReturnValues() method empty - it's not going to be used anyway.
39      * <p>
40      * 2. Implement getDefaultAnswer() instead.
41      * <p>
42      * In rare cases your code might not compile with recent deprecation & changes.
43      * Very sorry for inconvenience but it had to be done in order to keep framework consistent.
44      * <p>
45      * See javadoc {@link ReturnValues} for info why this method was deprecated
46      * <p>
47      * Allows configuring the default return values of unstubbed invocations
48      * <p>
49      * See javadoc for {@link IMockitoConfiguration}
50      */
51     @Deprecated
getReturnValues()52     ReturnValues getReturnValues();
53 
54     /**
55      * Allows configuring the default answers of unstubbed invocations
56      * <p>
57      * See javadoc for {@link IMockitoConfiguration}
58      */
getDefaultAnswer()59     Answer<Object> getDefaultAnswer();
60 
61     /**
62      * Configures annotations for mocks
63      * <p>
64      * See javadoc for {@link IMockitoConfiguration}
65      */
getAnnotationEngine()66     AnnotationEngine getAnnotationEngine();
67 
68     /**
69      * This should be turned on unless you're a Mockito developer and you wish
70      * to have verbose (read: messy) stack traces that only few understand (eg:
71      * Mockito developers)
72      * <p>
73      * See javadoc for {@link IMockitoConfiguration}
74      *
75      * @return if Mockito should clean stack traces
76      */
cleansStackTrace()77     boolean cleansStackTrace();
78 
79     /**
80      * Allow objenesis to cache classes. If you're in an environment where classes
81      * are dynamically reloaded, you can disable this to avoid classcast exceptions.
82      */
enableClassCache()83     boolean enableClassCache();
84 }