@@ -2683,10 +2683,10 @@ class Traverser(
2683
2683
} ? : findMethodInvocationTargets(types, methodSubSignature)
2684
2684
2685
2685
return methodInvocationTargets
2686
- .map { (method, implementationClass, possibleTypes) ->
2686
+ .mapNotNull { (method, implementationClass, possibleTypes) ->
2687
2687
val typeStorage = typeResolver.constructTypeStorage(implementationClass, possibleTypes)
2688
2688
val mockInfo = memory.mockInfoByAddr(instance.addr)
2689
- val mockedObject = mockInfo?.let {
2689
+ val mockedObjectInfo = mockInfo?.let {
2690
2690
// TODO rewrite to fix JIRA:1611
2691
2691
val type = Scene .v().getSootClass(mockInfo.classId.name).type
2692
2692
val ancestorTypes = typeResolver.findOrConstructAncestorsIncludingTypes(type)
@@ -2696,29 +2696,32 @@ class Traverser(
2696
2696
it.copyWithClassId(classId = implementationClass.id)
2697
2697
}
2698
2698
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
2711
2701
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)
2713
2708
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())
2718
2711
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
2722
2725
}
2723
2726
}
2724
2727
}
0 commit comments