Skip to content

Commit 22f5b42

Browse files
committed
Further improvements of traverser
1 parent 8251e69 commit 22f5b42

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ class Mocker(
203203
}
204204
}
205205

206-
val areMocksAllowed: Boolean = strategy == MockStrategy.NO_MOCKS
207-
208206
private fun checkIfShouldMock(
209207
type: RefType,
210208
mockInfo: UtMockInfo

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,10 +2683,10 @@ class Traverser(
26832683
} ?: findMethodInvocationTargets(types, methodSubSignature)
26842684

26852685
return methodInvocationTargets
2686-
.map { (method, implementationClass, possibleTypes) ->
2686+
.mapNotNull { (method, implementationClass, possibleTypes) ->
26872687
val typeStorage = typeResolver.constructTypeStorage(implementationClass, possibleTypes)
26882688
val mockInfo = memory.mockInfoByAddr(instance.addr)
2689-
val mockedObject = mockInfo?.let {
2689+
val mockedObjectInfo = mockInfo?.let {
26902690
// TODO rewrite to fix JIRA:1611
26912691
val type = Scene.v().getSootClass(mockInfo.classId.name).type
26922692
val ancestorTypes = typeResolver.findOrConstructAncestorsIncludingTypes(type)
@@ -2696,29 +2696,32 @@ class Traverser(
26962696
it.copyWithClassId(classId = implementationClass.id)
26972697
}
26982698

2699-
val mockedObjectInfo = mocker.mock(implementationClass, updatedMockInfo)
2700-
mockedObjectInfo.value
2701-
}
2702-
2703-
if (mockedObject == null) {
2704-
// Above we might get implementationClass that has to be substituted.
2705-
// For example, for a call "Collection.size()" such classes will be produced.
2706-
val wrapperOrInstance = wrapper(implementationClass, instance.addr)
2707-
?: instance.copy(typeStorage = typeStorage)
2708-
2709-
val typeConstraint = typeRegistry.typeConstraint(instance.addr, wrapperOrInstance.typeStorage)
2710-
val constraints = setOf(typeConstraint.isOrNullConstraint())
2699+
mocker.mock(implementationClass, updatedMockInfo)
2700+
} ?: NoMock
27112701

2712-
// TODO add memory updated for types JIRA:1523
2702+
when (mockedObjectInfo) {
2703+
is NoMock -> {
2704+
// Above we might get implementationClass that has to be substituted.
2705+
// For example, for a call "Collection.size()" such classes will be produced.
2706+
val wrapperOrInstance = wrapper(implementationClass, instance.addr)
2707+
?: instance.copy(typeStorage = typeStorage)
27132708

2714-
InvocationTarget(wrapperOrInstance, method, constraints)
2715-
} else {
2716-
val typeConstraint = typeRegistry.typeConstraint(mockedObject.addr, mockedObject.typeStorage)
2717-
val constraints = setOf(typeConstraint.isOrNullConstraint())
2709+
val typeConstraint = typeRegistry.typeConstraint(instance.addr, wrapperOrInstance.typeStorage)
2710+
val constraints = setOf(typeConstraint.isOrNullConstraint())
27182711

2719-
// TODO add memory updated for types JIRA:1523
2720-
// TODO isMock????
2721-
InvocationTarget(mockedObject, method, constraints)
2712+
// TODO add memory updated for types JIRA:1523
2713+
InvocationTarget(wrapperOrInstance, method, constraints)
2714+
}
2715+
is ExpectedMock -> {
2716+
val mockedObject = mockedObjectInfo.value!!
2717+
val typeConstraint = typeRegistry.typeConstraint(mockedObject.addr, mockedObject.typeStorage)
2718+
val constraints = setOf(typeConstraint.isOrNullConstraint())
2719+
2720+
// TODO add memory updated for types JIRA:1523
2721+
// TODO isMock????
2722+
InvocationTarget(mockedObject, method, constraints)
2723+
}
2724+
is UnexpectedMock -> null
27222725
}
27232726
}
27242727
}

0 commit comments

Comments
 (0)