Skip to content

Commit 5e32c19

Browse files
committed
uncommit
1 parent 78473a4 commit 5e32c19

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ val ClassId.denotableType: ClassId
5151
}
5252
}
5353

54+
private val isLambdaRegex = ".*(\\$)lambda_.*".toRegex()
55+
56+
val ClassId.isLambda: Boolean
57+
get() = name matches isLambdaRegex
58+
59+
val ClassId.isFunctionalInterface: Boolean
60+
get() {
61+
// we cannot access jClass of a builtin type, so we have to return false
62+
if (this is BuiltinClassId) return false
63+
// we cannot access jClass for lambdas, but we know that it is not a functional interface anyway
64+
if (this.isLambda) return false
65+
66+
val clazz = this.jClass
67+
if (!clazz.isInterface) return false
68+
69+
val abstractMethods = clazz.methods.filter { java.lang.reflect.Modifier.isAbstract(it.modifiers) }
70+
return abstractMethods.size == 1
71+
}
5472

5573
@Suppress("unused")
5674
val ClassId.enclosingClass: ClassId?

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import kotlinx.collections.immutable.persistentHashMapOf
4848
import org.utbot.engine.pc.UtSolverStatusUNDEFINED
4949
import org.utbot.framework.plugin.api.ExecutableId
5050
import org.utbot.framework.plugin.api.util.executableId
51+
import org.utbot.framework.plugin.api.util.isLambda
5152
import soot.ArrayType
5253
import soot.PrimType
5354
import soot.RefLikeType
@@ -198,10 +199,8 @@ private val isAnonymousRegex = ".*\\$\\d+$".toRegex()
198199
val SootClass.isAnonymous
199200
get() = name matches isAnonymousRegex
200201

201-
private val isLambdaRegex = ".*(\\$)lambda_.*".toRegex()
202-
203202
val SootClass.isLambda: Boolean
204-
get() = name matches isLambdaRegex
203+
get() = this.id.isLambda
205204

206205
val Type.numDimensions get() = if (this is ArrayType) numDimensions else 0
207206

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utbot.engine
22

33
import org.utbot.framework.plugin.api.ClassId
4+
import org.utbot.framework.plugin.api.util.isFunctionalInterface
45

56
/**
67
* Mock strategies.
@@ -17,15 +18,24 @@ enum class MockStrategy {
1718
},
1819

1920
OTHER_PACKAGES {
20-
override fun eligibleToMock(classToMock: ClassId, classUnderTest: ClassId): Boolean =
21-
classToMock != classUnderTest && classToMock.packageName.let {
22-
it != classUnderTest.packageName && !isSystemPackage(it)
23-
}
21+
override fun eligibleToMock(classToMock: ClassId, classUnderTest: ClassId): Boolean {
22+
if (classToMock == classUnderTest) return false
23+
if (classToMock.packageName == classUnderTest.packageName) return false
24+
25+
// we always mock functional interfaces
26+
if (classToMock.isFunctionalInterface) return true
27+
28+
return !isSystemPackage(classToMock.packageName)
29+
}
2430
},
2531

2632
OTHER_CLASSES {
27-
override fun eligibleToMock(classToMock: ClassId, classUnderTest: ClassId): Boolean =
28-
classToMock != classUnderTest && !isSystemPackage(classToMock.packageName)
33+
override fun eligibleToMock(classToMock: ClassId, classUnderTest: ClassId): Boolean {
34+
if (classToMock == classUnderTest) return false
35+
// we always mock functional interfaces
36+
if (classToMock.isFunctionalInterface) return true
37+
return !isSystemPackage(classToMock.packageName)
38+
}
2939
};
3040

3141
/**

0 commit comments

Comments
 (0)