File tree Expand file tree Collapse file tree 3 files changed +36
-9
lines changed
utbot-framework/src/main/kotlin/org/utbot/engine
utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util Expand file tree Collapse file tree 3 files changed +36
-9
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,24 @@ val ClassId.denotableType: ClassId
51
51
}
52
52
}
53
53
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
+ }
54
72
55
73
@Suppress(" unused" )
56
74
val ClassId .enclosingClass: ClassId ?
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ import kotlinx.collections.immutable.persistentHashMapOf
48
48
import org.utbot.engine.pc.UtSolverStatusUNDEFINED
49
49
import org.utbot.framework.plugin.api.ExecutableId
50
50
import org.utbot.framework.plugin.api.util.executableId
51
+ import org.utbot.framework.plugin.api.util.isLambda
51
52
import soot.ArrayType
52
53
import soot.PrimType
53
54
import soot.RefLikeType
@@ -198,10 +199,8 @@ private val isAnonymousRegex = ".*\\$\\d+$".toRegex()
198
199
val SootClass .isAnonymous
199
200
get() = name matches isAnonymousRegex
200
201
201
- private val isLambdaRegex = " .*(\\ $)lambda_.*" .toRegex()
202
-
203
202
val SootClass .isLambda: Boolean
204
- get() = name matches isLambdaRegex
203
+ get() = this .id.isLambda
205
204
206
205
val Type .numDimensions get() = if (this is ArrayType ) numDimensions else 0
207
206
Original file line number Diff line number Diff line change 1
1
package org.utbot.engine
2
2
3
3
import org.utbot.framework.plugin.api.ClassId
4
+ import org.utbot.framework.plugin.api.util.isFunctionalInterface
4
5
5
6
/* *
6
7
* Mock strategies.
@@ -17,15 +18,24 @@ enum class MockStrategy {
17
18
},
18
19
19
20
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
+ }
24
30
},
25
31
26
32
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
+ }
29
39
};
30
40
31
41
/* *
You can’t perform that action at this time.
0 commit comments