Skip to content

Package: EMockSettings

EMockSettings

nameinstructionbranchcomplexitylinemethod
eContents()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.test.common.spi;
15:
16: import java.io.Serializable;
17:
18: import org.eclipse.emf.common.util.ECollections;
19: import org.eclipse.emf.common.util.EList;
20: import org.eclipse.emf.ecore.EClass;
21: import org.eclipse.emf.ecore.EObject;
22: import org.mockito.MockSettings;
23: import org.mockito.listeners.InvocationListener;
24: import org.mockito.stubbing.Answer;
25:
26: /**
27: * Analogue of the {@link MockSettings} interface that configures a mock of {@link EObject} type.
28: * It ensures that all of the interfaces expected by the EMF run-time are
29: * provided, so therefore it does not have the {@link MockSettings#extraInterfaces(Class...)}
30: * settings as it would be unusual to mix in any other interfaces to an EMF model object.
31: * Also, {@link EObject}s are never {@link Serializable}, so that option is not supported.
32: *
33: * @since 1.22
34: * @see EMFMocking#eMock(Class, EMockSettings)
35: * @see EMFMocking#withESettings()
36: */
37: public interface EMockSettings {
38:         /**
39:          * Set a name for the mock. <strong>Note</strong> that mocks injected into fields with
40:          * the {@link EMock @EMock} annotation are automatically named according to the field name,
41:          * or else a name specified in the annotation.
42:          *
43:          * @param name the mock name
44:          * @return myself, for fluency
45:          *
46:          * @see MockSettings#name(String)
47:          */
48:         EMockSettings name(String name);
49:
50:         /**
51:          * Configure a default answer for unstubbed methods.
52:          *
53:          * @param defaultAnswer the mock's default answer
54:          * @return myself, for fluency
55:          *
56:          * @see MockSettings#defaultAnswer(Answer)
57:          */
58:         EMockSettings defaultAnswer(Answer<?> defaultAnswer);
59:
60:         /**
61:          * Enable verbose logging of interactions.
62:          *
63:          * @return myself, for fluency
64:          *
65:          * @see MockSettings#verboseLogging()
66:          */
67:         EMockSettings verboseLogging();
68:
69:         /**
70:          * Add listeners listener to method invocations on the mock.
71:          *
72:          * @param listeners the listeners to add (none may be {@code null})
73:          * @return myself, for fluency
74:          *
75:          * @see MockSettings#invocationListeners(InvocationListener...)
76:          */
77:         EMockSettings invocationListeners(InvocationListener... listeners);
78:
79:         /**
80:          * Set a contents list for the mock. This may be a writable list if the
81:          * test needs that.
82:          *
83:          * @param eContents a list to return from {@link EObject#eContents()}
84:          * @return myself, for fluency
85:          */
86:         default EMockSettings eContents() {
87:                 return eContents(ECollections.emptyEList());
88:         }
89:
90:         /**
91:          * Set an {@link EClass} list for the mock.
92:          *
93:          * @param eClass the {@link EClass} to return from {@link EObject#eClass()}
94:          * @return myself, for fluency
95:          */
96:         EMockSettings eClass(EClass eClass);
97:
98:         /**
99:          * Set a contents list for the mock. This may be a writable list if the
100:          * test needs that.
101:          *
102:          * @param eContents a list to return from {@link EObject#eContents()}
103:          * @return myself, for fluency
104:          */
105:         EMockSettings eContents(EList<? extends EObject> eContents);
106:
107:         /**
108:          * Set a container for the mock.
109:          *
110:          * @param eContainer an object to return from {@link EObject#eContainer()}
111:          * @return myself, for fluency
112:          */
113:         EMockSettings eContainer(EObject eContainer);
114:
115: }