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.listeners.InvocationListener; 8 import org.mockito.internal.listeners.StubbingLookupListener; 9 import org.mockito.mock.MockCreationSettings; 10 import org.mockito.mock.MockName; 11 import org.mockito.mock.SerializableMode; 12 import org.mockito.stubbing.Answer; 13 14 import java.io.Serializable; 15 import java.util.ArrayList; 16 import java.util.LinkedHashSet; 17 import java.util.List; 18 import java.util.Set; 19 20 public class CreationSettings<T> implements MockCreationSettings<T>, Serializable { 21 private static final long serialVersionUID = -6789800638070123629L; 22 23 protected Class<T> typeToMock; 24 protected Set<Class<?>> extraInterfaces = new LinkedHashSet<Class<?>>(); 25 protected String name; 26 protected Object spiedInstance; 27 protected Answer<Object> defaultAnswer; 28 protected MockName mockName; 29 protected SerializableMode serializableMode = SerializableMode.NONE; 30 protected List<InvocationListener> invocationListeners = new ArrayList<InvocationListener>(); 31 protected final List<StubbingLookupListener> stubbingLookupListeners = new ArrayList<StubbingLookupListener>(); 32 protected boolean stubOnly; 33 private boolean useConstructor; 34 private Object outerClassInstance; 35 CreationSettings()36 public CreationSettings() {} 37 38 @SuppressWarnings("unchecked") CreationSettings(CreationSettings copy)39 public CreationSettings(CreationSettings copy) { 40 this.typeToMock = copy.typeToMock; 41 this.extraInterfaces = copy.extraInterfaces; 42 this.name = copy.name; 43 this.spiedInstance = copy.spiedInstance; 44 this.defaultAnswer = copy.defaultAnswer; 45 this.mockName = copy.mockName; 46 this.serializableMode = copy.serializableMode; 47 this.invocationListeners = copy.invocationListeners; 48 this.stubOnly = copy.stubOnly; 49 this.useConstructor = copy.isUsingConstructor(); 50 this.outerClassInstance = copy.getOuterClassInstance(); 51 } 52 getTypeToMock()53 public Class<T> getTypeToMock() { 54 return typeToMock; 55 } 56 setTypeToMock(Class<T> typeToMock)57 public CreationSettings<T> setTypeToMock(Class<T> typeToMock) { 58 this.typeToMock = typeToMock; 59 return this; 60 } 61 getExtraInterfaces()62 public Set<Class<?>> getExtraInterfaces() { 63 return extraInterfaces; 64 } 65 setExtraInterfaces(Set<Class<?>> extraInterfaces)66 public CreationSettings<T> setExtraInterfaces(Set<Class<?>> extraInterfaces) { 67 this.extraInterfaces = extraInterfaces; 68 return this; 69 } 70 getName()71 public String getName() { 72 return name; 73 } 74 getSpiedInstance()75 public Object getSpiedInstance() { 76 return spiedInstance; 77 } 78 getDefaultAnswer()79 public Answer<Object> getDefaultAnswer() { 80 return defaultAnswer; 81 } 82 getMockName()83 public MockName getMockName() { 84 return mockName; 85 } 86 setMockName(MockName mockName)87 public CreationSettings<T> setMockName(MockName mockName) { 88 this.mockName = mockName; 89 return this; 90 } 91 isSerializable()92 public boolean isSerializable() { 93 return serializableMode != SerializableMode.NONE; 94 } 95 setSerializableMode(SerializableMode serializableMode)96 public CreationSettings<T> setSerializableMode(SerializableMode serializableMode) { 97 this.serializableMode = serializableMode; 98 return this; 99 } 100 getSerializableMode()101 public SerializableMode getSerializableMode() { 102 return serializableMode; 103 } 104 getInvocationListeners()105 public List<InvocationListener> getInvocationListeners() { 106 return invocationListeners; 107 } 108 getStubbingLookupListeners()109 public List<StubbingLookupListener> getStubbingLookupListeners() { 110 return stubbingLookupListeners; 111 } 112 isUsingConstructor()113 public boolean isUsingConstructor() { 114 return useConstructor; 115 } 116 getOuterClassInstance()117 public Object getOuterClassInstance() { 118 return outerClassInstance; 119 } 120 isStubOnly()121 public boolean isStubOnly() { 122 return stubOnly; 123 } 124 125 } 126