@@ -134,6 +134,11 @@ data class UtStaticMethodMockInfo(
134
134
sealed class MockedObjectInfo (val value : ObjectValue ? )
135
135
136
136
object NoMock: MockedObjectInfo(value = null )
137
+
138
+ /* *
139
+ * Represents a mock that occurs when mock strategy allows it
140
+ * or when an object type is in a set that requires force mocking.
141
+ */
137
142
class ExpectedMock (value : ObjectValue ): MockedObjectInfo(value)
138
143
139
144
/* *
@@ -142,9 +147,6 @@ class ExpectedMock(value: ObjectValue): MockedObjectInfo(value)
142
147
*/
143
148
class UnexpectedMock (value : ObjectValue ): MockedObjectInfo(value)
144
149
145
- fun ObjectValue?.construct (mockDesired : Boolean ): MockedObjectInfo =
146
- this ?.let { if (mockDesired) ExpectedMock (it) else UnexpectedMock (it) } ? : NoMock
147
-
148
150
/* *
149
151
* Service to mock things. Knows mock strategy, class under test and class hierarchy.
150
152
*/
@@ -157,6 +159,9 @@ class Mocker(
157
159
) {
158
160
private val mocksDesired: Boolean = strategy != MockStrategy .NO_MOCKS
159
161
162
+ fun construct (value : ObjectValue ? ): MockedObjectInfo =
163
+ value?.let { if (mocksDesired || mockAlways(it.type) ) ExpectedMock (it) else UnexpectedMock (it) } ? : NoMock
164
+
160
165
/* *
161
166
* Creates mocked instance of the [type] using mock info if it should be mocked by the mocker,
162
167
* otherwise returns null.
@@ -165,7 +170,7 @@ class Mocker(
165
170
*/
166
171
fun mock (type : RefType , mockInfo : UtMockInfo ): MockedObjectInfo {
167
172
val objectValue = if (shouldMock(type, mockInfo)) createMockObject(type, mockInfo) else null
168
- return objectValue. construct(mocksDesired )
173
+ return construct(objectValue )
169
174
}
170
175
171
176
/* *
@@ -176,7 +181,7 @@ class Mocker(
176
181
mockListenerController?.onShouldMock(strategy, mockInfo)
177
182
178
183
val objectValue = createMockObject(type, mockInfo)
179
- return objectValue. construct(mocksDesired )
184
+ return construct(objectValue )
180
185
}
181
186
182
187
/* *
0 commit comments