Skip to content

Commit 374eb3c

Browse files
committed
A unit test to check that enum ids in recursive models are consistent
1 parent e29923f commit 374eb3c

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.utbot.framework.plugin.api.samples;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
public class InnerClassWithEnums {
6+
private SampleEnum a;
7+
private SampleEnum b;
8+
9+
public InnerClassWithEnums(SampleEnum a, SampleEnum b) {
10+
this.a = a;
11+
this.b = b;
12+
}
13+
14+
public SampleEnum getA() {
15+
return a;
16+
}
17+
18+
public void setA(SampleEnum a) {
19+
this.a = a;
20+
}
21+
22+
public SampleEnum getB() {
23+
return b;
24+
}
25+
26+
public void setB(SampleEnum b) {
27+
this.b = b;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.utbot.framework.plugin.api.samples;
2+
3+
public class OuterClassWithEnums {
4+
private SampleEnum value;
5+
private final InnerClassWithEnums left;
6+
private final InnerClassWithEnums right;
7+
8+
public OuterClassWithEnums(SampleEnum value, InnerClassWithEnums left, InnerClassWithEnums right) {
9+
this.value = value;
10+
this.left = left;
11+
this.right = right;
12+
}
13+
14+
public void setValue(SampleEnum value) {
15+
this.value = value;
16+
}
17+
18+
public SampleEnum getA() {
19+
if (value == SampleEnum.LEFT && left != null) {
20+
return left.getA();
21+
} else if (value == SampleEnum.RIGHT && right != null) {
22+
return right.getA();
23+
} else {
24+
return null;
25+
}
26+
}
27+
28+
public SampleEnum getB() {
29+
if (value == SampleEnum.LEFT && left != null) {
30+
return left.getB();
31+
} else if (value == SampleEnum.RIGHT && right != null) {
32+
return right.getB();
33+
} else {
34+
return null;
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.utbot.framework.plugin.api.samples;
2+
3+
public enum SampleEnum {
4+
LEFT,
5+
RIGHT
6+
}

utbot-fuzzers/src/test/kotlin/org/utbot/framework/plugin/api/ModelProviderTest.kt

+40
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import org.utbot.fuzzer.providers.StringConstantModelProvider
2424
import org.junit.jupiter.api.Assertions.*
2525
import org.junit.jupiter.api.Test
2626
import org.utbot.framework.plugin.api.samples.FieldSetterClass
27+
import org.utbot.framework.plugin.api.samples.OuterClassWithEnums
2728
import org.utbot.framework.plugin.api.samples.PackagePrivateFieldAndClass
29+
import org.utbot.framework.plugin.api.samples.SampleEnum
2830
import org.utbot.framework.plugin.api.util.primitiveByWrapper
2931
import org.utbot.framework.plugin.api.util.primitiveWrappers
3032
import org.utbot.framework.plugin.api.util.voidWrapperClassId
@@ -523,6 +525,44 @@ class ModelProviderTest {
523525
}
524526
}
525527

528+
@Test
529+
fun `test that enum models in a recursive object model are consistent`() {
530+
withUtContext(UtContext(this::class.java.classLoader)) {
531+
val idGenerator = ReferencePreservingIntIdGenerator()
532+
val expectedIds = SampleEnum.values().associateWith { idGenerator.getOrCreateIdForValue(it) }
533+
534+
val result = collect(
535+
ObjectModelProvider(idGenerator),
536+
parameters = listOf(OuterClassWithEnums::class.java.id)
537+
)
538+
539+
assertEquals(1, result.size)
540+
val models = result[0] ?: fail("Inconsistent result")
541+
542+
for (model in models) {
543+
val outerModel = (model as? UtAssembleModel)
544+
?.finalInstantiationModel as? UtExecutableCallModel
545+
?: fail("No final instantiation model found for the outer class")
546+
for (param in outerModel.params) {
547+
when (param) {
548+
is UtEnumConstantModel -> {
549+
assertEquals(expectedIds[param.value], param.id)
550+
}
551+
is UtAssembleModel -> {
552+
for (enumParam in (param.finalInstantiationModel as UtExecutableCallModel).params) {
553+
enumParam as UtEnumConstantModel
554+
assertEquals(expectedIds[enumParam.value], enumParam.id)
555+
}
556+
}
557+
else -> {
558+
fail("Unexpected parameter model: $param")
559+
}
560+
}
561+
}
562+
}
563+
}
564+
}
565+
526566
private fun collect(
527567
modelProvider: ModelProvider,
528568
name: String = "testMethod",

0 commit comments

Comments
 (0)