Skip to content

Commit 744124d

Browse files
committed
Improve equals overrides for Instrumentation.Factory implementations
1 parent 100c1f9 commit 744124d

File tree

26 files changed

+103
-72
lines changed

26 files changed

+103
-72
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,19 +1325,17 @@ sealed class SpringConfiguration(val fullDisplayName: String) {
13251325
}
13261326

13271327
sealed interface SpringSettings {
1328-
class AbsentSpringSettings : SpringSettings {
1329-
// Denotes no configuration and no profile setting
1330-
1331-
// NOTICE:
1332-
// `class` should not be replaced with `object`
1333-
// in order to avoid issues caused by Kryo deserialization
1334-
// that creates new instances breaking `when` expressions
1335-
// that check reference equality instead of type equality
1328+
object AbsentSpringSettings : SpringSettings {
1329+
// NOTE that overriding equals is required just because without it
1330+
// we will lose equality for objects after deserialization
1331+
override fun equals(other: Any?): Boolean = other is AbsentSpringSettings
1332+
1333+
override fun hashCode(): Int = 0
13361334
}
13371335

1338-
class PresentSpringSettings(
1336+
data class PresentSpringSettings(
13391337
val configuration: SpringConfiguration,
1340-
val profiles: Array<String>
1338+
val profiles: List<String>
13411339
) : SpringSettings
13421340
}
13431341

utbot-framework/src/main/kotlin/org/utbot/framework/coverage/CoverageCalculator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlinx.coroutines.runBlocking
1313
fun methodCoverage(executable: ExecutableId, executions: List<UtValueExecution<*>>, classpath: String): Coverage {
1414
val methodSignature = executable.signature
1515
val classId = executable.classId
16-
return ConcreteExecutor(CoverageInstrumentation.Factory(), classpath).let { executor ->
16+
return ConcreteExecutor(CoverageInstrumentation.Factory, classpath).let { executor ->
1717
for (execution in executions) {
1818
val args = execution.stateBefore.params.map { it.value }.toMutableList()
1919
val caller = execution.stateBefore.caller

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestConstructors.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestConstructors {
2828
@Test
2929
fun testDefaultConstructor() {
3030
ConcreteExecutor(
31-
InvokeInstrumentation.Factory(),
31+
InvokeInstrumentation.Factory,
3232
CLASSPATH
3333
).use { executor ->
3434
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -43,7 +43,7 @@ class TestConstructors {
4343
@Test
4444
fun testIntConstructors() {
4545
ConcreteExecutor(
46-
InvokeInstrumentation.Factory(),
46+
InvokeInstrumentation.Factory,
4747
CLASSPATH
4848
).use { executor ->
4949
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -65,7 +65,7 @@ class TestConstructors {
6565
@Test
6666
fun testStringConstructors() {
6767
withInstrumentation(
68-
InvokeInstrumentation.Factory(),
68+
InvokeInstrumentation.Factory,
6969
CLASSPATH
7070
) { executor ->
7171
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -86,7 +86,7 @@ class TestConstructors {
8686
@Test
8787
fun testCoverageConstructor() {
8888
withInstrumentation(
89-
CoverageInstrumentation.Factory(),
89+
CoverageInstrumentation.Factory,
9090
CLASSPATH
9191
) { executor ->
9292
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -106,7 +106,7 @@ class TestConstructors {
106106
@Test
107107
fun testExecutionTraceConstructor() {
108108
withInstrumentation(
109-
ExecutionTraceInstrumentation.Factory(),
109+
ExecutionTraceInstrumentation.Factory,
110110
CLASSPATH
111111
) { executor ->
112112
val constructors = ClassWithMultipleConstructors::class.constructors

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestCoverageInstrumentation.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestCoverageInstrumentation {
2424
@Test
2525
fun testCatchTargetException() {
2626
ConcreteExecutor(
27-
CoverageInstrumentation.Factory(),
27+
CoverageInstrumentation.Factory,
2828
ExampleClass::class.java.protectionDomain.codeSource.location.path
2929
).use {
3030
val testObject = ExampleClass()
@@ -41,7 +41,7 @@ class TestCoverageInstrumentation {
4141
@Test
4242
fun testIfBranches() {
4343
ConcreteExecutor(
44-
CoverageInstrumentation.Factory(),
44+
CoverageInstrumentation.Factory,
4545
ExampleClass::class.java.protectionDomain.codeSource.location.path
4646
).use {
4747
val testObject = ExampleClass()
@@ -63,7 +63,7 @@ class TestCoverageInstrumentation {
6363
@Test
6464
fun testWrongArgumentsException() {
6565
ConcreteExecutor(
66-
CoverageInstrumentation.Factory(),
66+
CoverageInstrumentation.Factory,
6767
ExampleClass::class.java.protectionDomain.codeSource.location.path
6868
).use {
6969
val testObject = ExampleClass()
@@ -86,7 +86,7 @@ class TestCoverageInstrumentation {
8686
@Test
8787
fun testMultipleRunsInsideCoverage() {
8888
ConcreteExecutor(
89-
CoverageInstrumentation.Factory(),
89+
CoverageInstrumentation.Factory,
9090
ExampleClass::class.java.protectionDomain.codeSource.location.path
9191
).use {
9292
val testObject = ExampleClass()
@@ -121,7 +121,7 @@ class TestCoverageInstrumentation {
121121
@Test
122122
fun testSameResult() {
123123
ConcreteExecutor(
124-
CoverageInstrumentation.Factory(),
124+
CoverageInstrumentation.Factory,
125125
ExampleClass::class.java.protectionDomain.codeSource.location.path
126126
).use {
127127
val testObject = ExampleClass()
@@ -143,7 +143,7 @@ class TestCoverageInstrumentation {
143143
@Test
144144
fun testResult() {
145145
ConcreteExecutor(
146-
CoverageInstrumentation.Factory(),
146+
CoverageInstrumentation.Factory,
147147
ExampleClass::class.java.protectionDomain.codeSource.location.path
148148
).use {
149149
val testObject = ExampleClass()
@@ -160,7 +160,7 @@ class TestCoverageInstrumentation {
160160
@Test
161161
fun testEmptyMethod() {
162162
ConcreteExecutor(
163-
CoverageInstrumentation.Factory(),
163+
CoverageInstrumentation.Factory,
164164
ExampleClass::class.java.protectionDomain.codeSource.location.path
165165
).use {
166166
val testObject = ExampleClass()
@@ -176,7 +176,7 @@ class TestCoverageInstrumentation {
176176
@Test
177177
fun testTernaryOperator() {
178178
ConcreteExecutor(
179-
CoverageInstrumentation.Factory(),
179+
CoverageInstrumentation.Factory,
180180
StaticSubstitutionExamples::class.java.protectionDomain.codeSource.location.path
181181
).use {
182182
val testObject = StaticSubstitutionExamples()

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestInvokeInstrumentation.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TestInvokeInstrumentation {
2121
@Test
2222
fun testCatchTargetException() {
2323
ConcreteExecutor(
24-
InvokeInstrumentation.Factory(),
24+
InvokeInstrumentation.Factory,
2525
ExampleClass::class.java.protectionDomain.codeSource.location.path
2626
).use {
2727

@@ -36,7 +36,7 @@ class TestInvokeInstrumentation {
3636
@Test
3737
fun testWrongArgumentsException() {
3838
ConcreteExecutor(
39-
InvokeInstrumentation.Factory(),
39+
InvokeInstrumentation.Factory,
4040
ExampleClass::class.java.protectionDomain.codeSource.location.path
4141
).use {
4242
val testObject = ExampleClass()
@@ -57,7 +57,7 @@ class TestInvokeInstrumentation {
5757
@Test
5858
fun testSameResult() {
5959
ConcreteExecutor(
60-
InvokeInstrumentation.Factory(),
60+
InvokeInstrumentation.Factory,
6161
ExampleClass::class.java.protectionDomain.codeSource.location.path
6262
).use {
6363
val testObject = ExampleClass()
@@ -73,7 +73,7 @@ class TestInvokeInstrumentation {
7373
@Test
7474
fun testEmptyMethod() {
7575
ConcreteExecutor(
76-
InvokeInstrumentation.Factory(),
76+
InvokeInstrumentation.Factory,
7777
ExampleClass::class.java.protectionDomain.codeSource.location.path
7878
).use {
7979
val testObject = ExampleClass()
@@ -87,7 +87,7 @@ class TestInvokeInstrumentation {
8787
@Test
8888
fun testStaticMethodCall() {
8989
ConcreteExecutor(
90-
InvokeInstrumentation.Factory(),
90+
InvokeInstrumentation.Factory,
9191
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
9292
).use {
9393
val res1 = it.execute(StaticExampleClass::inc, arrayOf())
@@ -105,7 +105,7 @@ class TestInvokeInstrumentation {
105105
@Test
106106
fun testNullableMethod() {
107107
ConcreteExecutor(
108-
InvokeInstrumentation.Factory(),
108+
InvokeInstrumentation.Factory,
109109
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
110110
).use {
111111
val res1 = it.execute(
@@ -136,7 +136,7 @@ class TestInvokeInstrumentation {
136136
@Test
137137
fun testDifferentSignaturesButSameMethodNames() {
138138
ConcreteExecutor(
139-
InvokeInstrumentation.Factory(),
139+
InvokeInstrumentation.Factory,
140140
ClassWithSameMethodNames::class.java.protectionDomain.codeSource.location.path
141141
).use {
142142
val clazz = ClassWithSameMethodNames::class

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestInvokeWithStaticsInstrumentation.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TestInvokeWithStaticsInstrumentation {
3535
@Test
3636
fun testIfBranches() {
3737
ConcreteExecutor(
38-
InvokeWithStaticsInstrumentation.Factory(),
38+
InvokeWithStaticsInstrumentation.Factory,
3939
CLASSPATH
4040
).use {
4141
val res = it.execute(StaticExampleClass::inc, arrayOf(), null)
@@ -52,7 +52,7 @@ class TestInvokeWithStaticsInstrumentation {
5252
@Test
5353
fun testHiddenClass1() {
5454
ConcreteExecutor(
55-
InvokeWithStaticsInstrumentation.Factory(),
55+
InvokeWithStaticsInstrumentation.Factory,
5656
CLASSPATH
5757
).use {
5858
val res = it.execute(TestedClass::slomayInts, arrayOf(), null)
@@ -71,7 +71,7 @@ class TestInvokeWithStaticsInstrumentation {
7171
@Test
7272
fun testHiddenClassRepeatCall() {
7373
ConcreteExecutor(
74-
InvokeWithStaticsInstrumentation.Factory(),
74+
InvokeWithStaticsInstrumentation.Factory,
7575
CLASSPATH
7676
).use {
7777
val se = StaticEnvironment(
@@ -89,7 +89,7 @@ class TestInvokeWithStaticsInstrumentation {
8989
@Test
9090
fun testReferenceEquality() {
9191
ConcreteExecutor(
92-
InvokeWithStaticsInstrumentation.Factory(),
92+
InvokeWithStaticsInstrumentation.Factory,
9393
CLASSPATH
9494
).use {
9595

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestIsolated.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TestIsolated {
2121
fun testCatchTargetException() {
2222
val javaClass = ExampleClass::class.java
2323
ConcreteExecutor(
24-
InvokeInstrumentation.Factory(),
24+
InvokeInstrumentation.Factory,
2525
javaClass.protectionDomain.codeSource.location.path
2626
).use {
2727
val testObject = ExampleClass()
@@ -37,7 +37,7 @@ class TestIsolated {
3737
@Test
3838
fun testWrongArgumentsException() {
3939
ConcreteExecutor(
40-
InvokeInstrumentation.Factory(),
40+
InvokeInstrumentation.Factory,
4141
ExampleClass::class.java.protectionDomain.codeSource.location.path
4242
).use {
4343
val testObject = ExampleClass()
@@ -63,7 +63,7 @@ class TestIsolated {
6363
@Test
6464
fun testSameResult() {
6565
ConcreteExecutor(
66-
InvokeInstrumentation.Factory(),
66+
InvokeInstrumentation.Factory,
6767
ExampleClass::class.java.protectionDomain.codeSource.location.path
6868
).use {
6969
val testObject = ExampleClass()
@@ -81,7 +81,7 @@ class TestIsolated {
8181
@Test
8282
fun testEmptyMethod() {
8383
ConcreteExecutor(
84-
InvokeInstrumentation.Factory(),
84+
InvokeInstrumentation.Factory,
8585
ExampleClass::class.java.protectionDomain.codeSource.location.path
8686
).use {
8787
val testObject = ExampleClass()
@@ -97,7 +97,7 @@ class TestIsolated {
9797
@Test
9898
fun testStaticMethodCall() {
9999
ConcreteExecutor(
100-
InvokeInstrumentation.Factory(),
100+
InvokeInstrumentation.Factory,
101101
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
102102
).use {
103103
val isolatedFunctionInc = Isolated(StaticExampleClass::inc, it)
@@ -116,7 +116,7 @@ class TestIsolated {
116116
@Test
117117
fun testNullableMethod() {
118118
ConcreteExecutor(
119-
InvokeInstrumentation.Factory(),
119+
InvokeInstrumentation.Factory,
120120
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
121121
).use {
122122
val isolatedFunction = Isolated(StaticExampleClass::canBeNull, it)

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestStaticMethods.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestStaticMethods {
1717
@Test
1818
fun testStaticMethodCall() {
1919
ConcreteExecutor(
20-
CoverageInstrumentation.Factory(),
20+
CoverageInstrumentation.Factory,
2121
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
2222
).use {
2323
val res1 = it.execute(StaticExampleClass::inc, arrayOf())
@@ -44,7 +44,7 @@ class TestStaticMethods {
4444
@Test
4545
fun testNullableMethod() {
4646
ConcreteExecutor(
47-
CoverageInstrumentation.Factory(),
47+
CoverageInstrumentation.Factory,
4848
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
4949
).use {
5050
val res1 = it.execute(
@@ -75,7 +75,7 @@ class TestStaticMethods {
7575
@Test
7676
fun testNullableMethodWithoutAnnotations() {
7777
ConcreteExecutor(
78-
CoverageInstrumentation.Factory(),
78+
CoverageInstrumentation.Factory,
7979
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
8080
).use {
8181
val res1 = it.execute(

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestWithInstrumentation.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TestWithInstrumentation {
2020
@Test
2121
fun testStaticMethodCall() {
2222
withInstrumentation(
23-
CoverageInstrumentation.Factory(),
23+
CoverageInstrumentation.Factory,
2424
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
2525
) { executor ->
2626
val res1 = executor.execute(StaticExampleClass::inc, arrayOf())
@@ -47,7 +47,7 @@ class TestWithInstrumentation {
4747
@Test
4848
fun testDifferentSignaturesButSameMethodNames() {
4949
withInstrumentation(
50-
InvokeInstrumentation.Factory(),
50+
InvokeInstrumentation.Factory,
5151
ClassWithSameMethodNames::class.java.protectionDomain.codeSource.location.path
5252
) { executor ->
5353
val clazz = ClassWithSameMethodNames::class
@@ -70,7 +70,7 @@ class TestWithInstrumentation {
7070
@Test
7171
fun testInnerClasses() {
7272
withInstrumentation(
73-
CoverageInstrumentation.Factory(),
73+
CoverageInstrumentation.Factory,
7474
ClassWithInnerClasses::class.java.protectionDomain.codeSource.location.path
7575
) { executor ->
7676
val innerClazz = ClassWithInnerClasses.InnerClass::class.java

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/benchmark/Benchmark.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
1212
fun getBasicCoverageTime(count: Int): Double {
1313
var time: Long
1414
ConcreteExecutor(
15-
CoverageInstrumentation.Factory(),
15+
CoverageInstrumentation.Factory,
1616
Repeater::class.java.protectionDomain.codeSource.location.path
1717
).use { executor ->
1818
val dc0 = Repeater(", ")
@@ -51,7 +51,7 @@ fun getNativeCallTime(count: Int): Double {
5151
fun getJustResultTime(count: Int): Double {
5252
var time: Long
5353
ConcreteExecutor(
54-
InvokeInstrumentation.Factory(),
54+
InvokeInstrumentation.Factory,
5555
Repeater::class.java.protectionDomain.codeSource.location.path
5656
).use {
5757
val dc0 = Repeater(", ")

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/benchmark/BenchmarkFibonacci.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlin.system.measureNanoTime
1313
fun getBasicCoverageTime_fib(count: Int): Double {
1414
var time: Long
1515
ConcreteExecutor(
16-
CoverageInstrumentation.Factory(),
16+
CoverageInstrumentation.Factory,
1717
Fibonacci::class.java.protectionDomain.codeSource.location.path
1818
).use {
1919
val fib = Isolated(Fibonacci::calc, it)
@@ -47,7 +47,7 @@ fun getNativeCallTime_fib(count: Int): Double {
4747
fun getJustResultTime_fib(count: Int): Double {
4848
var time: Long
4949
ConcreteExecutor(
50-
InvokeInstrumentation.Factory(),
50+
InvokeInstrumentation.Factory,
5151
Fibonacci::class.java.protectionDomain.codeSource.location.path
5252
).use {
5353
val fib = Isolated(Fibonacci::calc, it)

0 commit comments

Comments
 (0)