• 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.internal.creation.settings;
6 
7 import org.mockito.internal.listeners.StubbingLookupListener;
8 import org.mockito.listeners.InvocationListener;
9 import org.mockito.listeners.VerificationStartedListener;
10 import org.mockito.mock.MockCreationSettings;
11 import org.mockito.mock.MockName;
12 import org.mockito.mock.SerializableMode;
13 import org.mockito.stubbing.Answer;
14 
15 import java.io.Serializable;
16 import java.util.ArrayList;
17 import java.util.LinkedHashSet;
18 import java.util.LinkedList;
19 import java.util.List;
20 import java.util.Set;
21 
22 public class CreationSettings<T> implements MockCreationSettings<T>, Serializable {
23     private static final long serialVersionUID = -6789800638070123629L;
24 
25     protected Class<T> typeToMock;
26     protected Set<Class<?>> extraInterfaces = new LinkedHashSet<Class<?>>();
27     protected String name;
28     protected Object spiedInstance;
29     protected Answer<Object> defaultAnswer;
30     protected MockName mockName;
31     protected SerializableMode serializableMode = SerializableMode.NONE;
32     protected List<InvocationListener> invocationListeners = new ArrayList<InvocationListener>();
33     protected final List<StubbingLookupListener> stubbingLookupListeners = new ArrayList<StubbingLookupListener>();
34     protected List<VerificationStartedListener> verificationStartedListeners = new LinkedList<VerificationStartedListener>();
35     protected boolean stubOnly;
36     protected boolean stripAnnotations;
37     private boolean useConstructor;
38     private Object outerClassInstance;
39     private Object[] constructorArgs;
40     protected boolean lenient;
41 
CreationSettings()42     public CreationSettings() {}
43 
44     @SuppressWarnings("unchecked")
CreationSettings(CreationSettings copy)45     public CreationSettings(CreationSettings copy) {
46         this.typeToMock = copy.typeToMock;
47         this.extraInterfaces = copy.extraInterfaces;
48         this.name = copy.name;
49         this.spiedInstance = copy.spiedInstance;
50         this.defaultAnswer = copy.defaultAnswer;
51         this.mockName = copy.mockName;
52         this.serializableMode = copy.serializableMode;
53         this.invocationListeners = copy.invocationListeners;
54         this.verificationStartedListeners = copy.verificationStartedListeners;
55         this.stubOnly = copy.stubOnly;
56         this.useConstructor = copy.isUsingConstructor();
57         this.outerClassInstance = copy.getOuterClassInstance();
58         this.constructorArgs = copy.getConstructorArgs();
59         this.lenient = copy.lenient;
60     }
61 
62     @Override
getTypeToMock()63     public Class<T> getTypeToMock() {
64         return typeToMock;
65     }
66 
setTypeToMock(Class<T> typeToMock)67     public CreationSettings<T> setTypeToMock(Class<T> typeToMock) {
68         this.typeToMock = typeToMock;
69         return this;
70     }
71 
72     @Override
getExtraInterfaces()73     public Set<Class<?>> getExtraInterfaces() {
74         return extraInterfaces;
75     }
76 
setExtraInterfaces(Set<Class<?>> extraInterfaces)77     public CreationSettings<T> setExtraInterfaces(Set<Class<?>> extraInterfaces) {
78         this.extraInterfaces = extraInterfaces;
79         return this;
80     }
81 
getName()82     public String getName() {
83         return name;
84     }
85 
86     @Override
getSpiedInstance()87     public Object getSpiedInstance() {
88         return spiedInstance;
89     }
90 
91     @Override
getDefaultAnswer()92     public Answer<Object> getDefaultAnswer() {
93         return defaultAnswer;
94     }
95 
96     @Override
getMockName()97     public MockName getMockName() {
98         return mockName;
99     }
100 
setMockName(MockName mockName)101     public CreationSettings<T> setMockName(MockName mockName) {
102         this.mockName = mockName;
103         return this;
104     }
105 
isSerializable()106     public boolean isSerializable() {
107         return serializableMode != SerializableMode.NONE;
108     }
109 
setSerializableMode(SerializableMode serializableMode)110     public CreationSettings<T> setSerializableMode(SerializableMode serializableMode) {
111         this.serializableMode = serializableMode;
112         return this;
113     }
114 
115     @Override
getSerializableMode()116     public SerializableMode getSerializableMode() {
117         return serializableMode;
118     }
119 
120     @Override
getInvocationListeners()121     public List<InvocationListener> getInvocationListeners() {
122         return invocationListeners;
123     }
124 
125     @Override
getVerificationStartedListeners()126     public List<VerificationStartedListener> getVerificationStartedListeners() {
127         return verificationStartedListeners;
128     }
129 
getStubbingLookupListeners()130     public List<StubbingLookupListener> getStubbingLookupListeners() {
131         return stubbingLookupListeners;
132     }
133 
134     @Override
isUsingConstructor()135     public boolean isUsingConstructor() {
136         return useConstructor;
137     }
138 
139     @Override
isStripAnnotations()140     public boolean isStripAnnotations() {
141         return stripAnnotations;
142     }
143 
144     @Override
getConstructorArgs()145     public Object[] getConstructorArgs() {
146         return constructorArgs;
147     }
148 
149     @Override
getOuterClassInstance()150     public Object getOuterClassInstance() {
151         return outerClassInstance;
152     }
153 
154     @Override
isStubOnly()155     public boolean isStubOnly() {
156         return stubOnly;
157     }
158 
159     @Override
isLenient()160     public boolean isLenient() {
161         return lenient;
162     }
163 }
164