@@ -134,6 +134,11 @@ data class UtStaticMethodMockInfo(
134134sealed class MockedObjectInfo (val value : ObjectValue ? )
135135
136136object 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+ */
137142class ExpectedMock (value : ObjectValue ): MockedObjectInfo(value)
138143
139144/* *
@@ -142,9 +147,6 @@ class ExpectedMock(value: ObjectValue): MockedObjectInfo(value)
142147 */
143148class UnexpectedMock (value : ObjectValue ): MockedObjectInfo(value)
144149
145- fun ObjectValue?.construct (mockDesired : Boolean ): MockedObjectInfo =
146- this ?.let { if (mockDesired) ExpectedMock (it) else UnexpectedMock (it) } ? : NoMock
147-
148150/* *
149151 * Service to mock things. Knows mock strategy, class under test and class hierarchy.
150152 */
@@ -157,6 +159,9 @@ class Mocker(
157159) {
158160 private val mocksDesired: Boolean = strategy != MockStrategy .NO_MOCKS
159161
162+ fun construct (value : ObjectValue ? ): MockedObjectInfo =
163+ value?.let { if (mocksDesired || mockAlways(it.type) ) ExpectedMock (it) else UnexpectedMock (it) } ? : NoMock
164+
160165 /* *
161166 * Creates mocked instance of the [type] using mock info if it should be mocked by the mocker,
162167 * otherwise returns null.
@@ -165,7 +170,7 @@ class Mocker(
165170 */
166171 fun mock (type : RefType , mockInfo : UtMockInfo ): MockedObjectInfo {
167172 val objectValue = if (shouldMock(type, mockInfo)) createMockObject(type, mockInfo) else null
168- return objectValue. construct(mocksDesired )
173+ return construct(objectValue )
169174 }
170175
171176 /* *
@@ -176,7 +181,7 @@ class Mocker(
176181 mockListenerController?.onShouldMock(strategy, mockInfo)
177182
178183 val objectValue = createMockObject(type, mockInfo)
179- return objectValue. construct(mocksDesired )
184+ return construct(objectValue )
180185 }
181186
182187 /* *
0 commit comments