• 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.stubbing.Answer;
8 
9 /**
10  * Use it to configure Mockito. For now there are not many configuration options but it may change in future.
11  *
12  * <p>
13  * In most cases you don't really need to configure Mockito. For example in case of working with legacy code,
14  * when you might want to have different 'mocking style' this interface might be helpful.
15  * A reason of configuring Mockito might be if you disagree with the {@link org.mockito.Answers#RETURNS_DEFAULTS}
16  * unstubbed mocks return.
17  *
18  * <p>
19  * To configure Mockito create exactly <b>org.mockito.configuration.MockitoConfiguration</b> class
20  * that implements this interface.
21  *
22  * <p>
23  * Configuring Mockito is completely <b>optional</b> - nothing happens if there isn't any
24  * <b>org.mockito.configuration.MockitoConfiguration</b> on the classpath.
25  *
26  * <p>
27  * <b>org.mockito.configuration.MockitoConfiguration</b> must implement <code>IMockitoConfiguration</code> or
28  * extend {@link DefaultMockitoConfiguration}
29  *
30  * <p>
31  * Mockito will store single instance of <code>org.mockito.configuration.MockitoConfiguration</code>
32  * per thread (using <code>ThreadLocal</code>).
33  * For sanity of your tests, don't make the implementation stateful.
34  *
35  * <p>
36  * If you have comments on Mockito configuration feature don't hesitate to write to mockito@googlegroups.com.
37  */
38 public interface IMockitoConfiguration {
39 
40     /**
41      * Allows configuring the default answers of unstubbed invocations
42      * <p>
43      * See javadoc for {@link IMockitoConfiguration}
44      */
getDefaultAnswer()45     Answer<Object> getDefaultAnswer();
46 
47     /**
48      * Configures annotations for mocks.
49      *
50      * <p>
51      * This method will have lower priority that the new extension mechanism.
52      * That is if it exists on the classpath both a class <code>org.mockito.configuration.MockitoConfiguration</code>
53      * and a file <code>mockito-extensions/org.mockito.plugins.AnnotationEngine</code> then the implementation of
54      * <code>org.mockito.configuration.MockitoConfiguration</code> will be chosen instead of the one in the file.
55      *
56      * <p>
57      * See javadoc for {@link IMockitoConfiguration}
58      *
59      * @deprecated Please use the extension mechanism {@link org.mockito.plugins.AnnotationEngine} instead,
60      *             this method will probably be removed in mockito 3.
61      */
62     @Deprecated
getAnnotationEngine()63     AnnotationEngine getAnnotationEngine();
64 
65     /**
66      * This should be turned on unless you're a Mockito developer and you wish
67      * to have verbose (read: messy) stack traces that only few understand (eg:
68      * Mockito developers)
69      * <p>
70      * See javadoc for {@link IMockitoConfiguration}
71      *
72      * @return if Mockito should clean stack traces
73      */
cleansStackTrace()74     boolean cleansStackTrace();
75 
76     /**
77      * Allow objenesis to cache classes. If you're in an environment where classes
78      * are dynamically reloaded, you can disable this to avoid classcast exceptions.
79      */
enableClassCache()80     boolean enableClassCache();
81 }
82