@@ -130,7 +130,7 @@ data class UtStaticMethodMockInfo(
130
130
) : UtMockInfo(methodId.classId, addr)
131
131
132
132
/* *
133
- * A wrapper for [ObjectValue] to store additional onfo .
133
+ * A wrapper for [ObjectValue] to store additional info .
134
134
*/
135
135
sealed class MockedObjectInfo {
136
136
abstract val value: ObjectValue ?
@@ -142,16 +142,18 @@ object NoMock: MockedObjectInfo() {
142
142
143
143
/* *
144
144
* Represents a mock that occurs when mock strategy allows it
145
- * or when an object type is in a set that requires force mocking.
145
+ * or when an object type requires always requires mocking.
146
+ *
147
+ * See [Mocker.mockAlways] for more details.
146
148
*/
147
149
class ExpectedMock (objectValue : ObjectValue ): MockedObjectInfo() {
148
150
override val value: ObjectValue = objectValue
149
151
}
150
152
151
153
/* *
152
- * Represents a mock that occurs when it is not recommended
154
+ * Represents a mock that occurs when it is not allowed.
153
155
* E.g. mock framework is not installed or
154
- * mock startegy is DO_NOT_MOCK and class is not in mockAlways set.
156
+ * mock strategy is [MockStrategy.NO_MOCKS] and class is not in [Mocker. mockAlways] set.
155
157
*/
156
158
class UnexpectedMock (objectValue : ObjectValue ): MockedObjectInfo() {
157
159
override val value: ObjectValue = objectValue
@@ -170,31 +172,6 @@ class Mocker(
170
172
) {
171
173
private val mocksAreDesired: Boolean = strategy != MockStrategy .NO_MOCKS
172
174
173
- /* *
174
- * Constructs [MockedObjectInfo]: enriches given value with
175
- * an information if this mock is expected or not.
176
- */
177
- fun construct (value : ObjectValue ? , mockInfo : UtMockInfo ): MockedObjectInfo {
178
- if (value == null ) {
179
- return NoMock
180
- }
181
-
182
- val mockingIsPossible = when (mockInfo) {
183
- is UtFieldMockInfo ,
184
- is UtObjectMockInfo -> applicationContext.mockFrameworkInstalled
185
- is UtNewInstanceMockInfo ,
186
- is UtStaticMethodMockInfo ,
187
- is UtStaticObjectMockInfo -> applicationContext.staticsMockingIsConfigured
188
- }
189
- val mockingIsForcedAndPossible = mockAlways(value.type) && mockingIsPossible
190
-
191
- return if (mocksAreDesired || mockingIsForcedAndPossible) {
192
- ExpectedMock (value)
193
- } else {
194
- UnexpectedMock (value)
195
- }
196
- }
197
-
198
175
/* *
199
176
* Creates mocked instance (if it should be mocked by the mocker) of the [type] using [mockInfo]
200
177
* otherwise returns [NoMock].
@@ -207,8 +184,7 @@ class Mocker(
207
184
}
208
185
209
186
/* *
210
- * Creates mocked instance of the [type] using [mockInfo]
211
- * it does not check anything and always returns the constructed mock.
187
+ * Unlike to [mock], unconditionally creates a mocked instance of the [type] using [mockInfo].
212
188
*/
213
189
fun forceMock (type : RefType , mockInfo : UtMockInfo ): MockedObjectInfo {
214
190
mockListenerController?.onShouldMock(strategy, mockInfo)
@@ -241,6 +217,30 @@ class Mocker(
241
217
}
242
218
}
243
219
220
+ /* *
221
+ * Constructs [MockedObjectInfo]: enriches given [mockedValue] with an information if mocking is expected or not.
222
+ */
223
+ private fun construct (mockedValue : ObjectValue ? , mockInfo : UtMockInfo ): MockedObjectInfo {
224
+ if (mockedValue == null ) {
225
+ return NoMock
226
+ }
227
+
228
+ val mockingIsPossible = when (mockInfo) {
229
+ is UtFieldMockInfo ,
230
+ is UtObjectMockInfo -> applicationContext.mockFrameworkInstalled
231
+ is UtNewInstanceMockInfo ,
232
+ is UtStaticMethodMockInfo ,
233
+ is UtStaticObjectMockInfo -> applicationContext.staticsMockingIsConfigured
234
+ }
235
+ val mockingIsForcedAndPossible = mockAlways(mockedValue.type) && mockingIsPossible
236
+
237
+ return if (mocksAreDesired || mockingIsForcedAndPossible) {
238
+ ExpectedMock (mockedValue)
239
+ } else {
240
+ UnexpectedMock (mockedValue)
241
+ }
242
+ }
243
+
244
244
private fun checkIfShouldMock (
245
245
type : RefType ,
246
246
mockInfo : UtMockInfo
0 commit comments