Skip to content

Commit 88d8fac

Browse files
committed
All tests pass somehow, pray for them
1 parent 81a0406 commit 88d8fac

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/Mocks.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ data class UtStaticMethodMockInfo(
134134
sealed class MockedObjectInfo(val value: ObjectValue?)
135135

136136
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+
*/
137142
class ExpectedMock(value: ObjectValue): MockedObjectInfo(value)
138143

139144
/**
@@ -142,9 +147,6 @@ class ExpectedMock(value: ObjectValue): MockedObjectInfo(value)
142147
*/
143148
class 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
/**

utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ class Traverser(
13851385

13861386
val mockedObject = mockedObjectInfo.value
13871387
if (mockedObjectInfo is UnexpectedMock) {
1388-
error("Wrong mocker configuration, it has NO_MOCK stategy, but decided to mock $type object")
1388+
error("Wrong mocker configuration, it decided to mock $type object, although it is unexpected")
13891389
}
13901390

13911391

0 commit comments

Comments
 (0)