11package org.utbot.examples.enums
22
3+ import org.junit.jupiter.api.Disabled
34import org.utbot.examples.enums.ClassWithEnum.StatusEnum.ERROR
45import org.utbot.examples.enums.ClassWithEnum.StatusEnum.READY
56import org.utbot.framework.plugin.api.FieldId
67import org.utbot.framework.plugin.api.util.id
7- import org.junit.jupiter.api.Disabled
88import org.junit.jupiter.api.Test
9+ import org.utbot.examples.enums.ClassWithEnum.StatusEnum
910import org.utbot.framework.plugin.api.util.jField
1011import org.utbot.testcheckers.eq
1112import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete
1213import org.utbot.testcheckers.withoutConcrete
1314import org.utbot.testing.DoNotCalculate
1415import org.utbot.testing.UtValueTestCaseChecker
16+ import org.utbot.testing.between
1517import org.utbot.testing.ignoreExecutionsNumber
1618import org.utbot.testing.isException
1719
@@ -44,19 +46,16 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas
4446 }
4547
4648 @Test
47- @Disabled(" TODO JIRA:1686" )
4849 fun testNullParameter () {
4950 check(
5051 ClassWithEnum ::nullEnumAsParameter,
51- eq( 3 ),
52+ between( 2 .. 3 ),
5253 { e, _ -> e == null },
53- { e, r -> e == READY && r == 0 },
54- { e, r -> e == ERROR && r == - 1 },
54+ { e, r -> e == READY && r == 0 || e == ERROR && r == - 1 },
5555 )
5656 }
5757
5858 @Test
59- @Disabled(" TODO JIRA:1686" )
6059 fun testNullField () {
6160 checkWithException(
6261 ClassWithEnum ::nullField,
@@ -67,22 +66,21 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas
6766 )
6867 }
6968
69+ @Suppress(" KotlinConstantConditions" )
7070 @Test
71- @Disabled(" TODO JIRA:1686" )
7271 fun testChangeEnum () {
7372 checkWithException(
7473 ClassWithEnum ::changeEnum,
75- eq(3 ),
76- { e, r -> e == null && r.isException<NullPointerException >() },
74+ eq(2 ),
7775 { e, r -> e == READY && r.getOrNull()!! == ERROR .ordinal },
78- { e, r -> e == ERROR && r.getOrNull()!! == READY .ordinal },
76+ { e, r -> ( e == ERROR || e == null ) && r.getOrNull()!! == READY .ordinal },
7977 )
8078 }
8179
8280 @Test
8381 fun testChangeMutableField () {
8482 // TODO testing code generation for this method is disabled because we need to restore original field state
85- // should be enabled after solving JIRA:1648
83+ // should be enabled after solving https://github.com/UnitTestBot/UTBotJava/issues/80
8684 withEnabledTestingCodeGeneration(testCodeGeneration = false ) {
8785 checkWithException(
8886 ClassWithEnum ::changeMutableField,
@@ -94,7 +92,7 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas
9492 }
9593
9694 @Test
97- @Disabled(" TODO JIRA:1686 " )
95+ @Disabled(" https://github.com/UnitTestBot/UTBotJava/issues/1745 " )
9896 fun testCheckName () {
9997 check(
10098 ClassWithEnum ::checkName,
@@ -111,21 +109,35 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas
111109 ClassWithEnum ::changingStaticWithEnumInit,
112110 eq(1 ),
113111 { t, staticsAfter, r ->
114- // for some reasons x is inaccessible
115- val x = FieldId (t.javaClass.id, " x" ).jField.get(t) as Int
112+ // We cannot check `x` since it is not a meaningful value since
113+ // it is accessed only in a static initializer.
114+
115+ // For some reasons x is inaccessible
116+ // val x = FieldId(t.javaClass.id, "x").jField.get(t) as Int
116117
117118 val y = staticsAfter[FieldId (ClassWithEnum .ClassWithStaticField ::class .id, " y" )]!! .value as Int
118119
119- val areStaticsCorrect = x == 1 && y == 11
120+ val areStaticsCorrect = /* x == 1 &&*/ y == 11
120121 areStaticsCorrect && r == true
121122 }
122123 )
123124 }
124125
126+ @Test
127+ fun testVirtualFunction () {
128+ check(
129+ ClassWithEnum ::virtualFunction,
130+ eq(3 ),
131+ { parameter, _ -> parameter == null },
132+ { parameter, r -> r == 1 && parameter == ERROR },
133+ { parameter, r -> r == 0 && parameter == READY },
134+ )
135+ }
136+
125137 @Test
126138 fun testEnumValues () {
127139 checkStaticMethod(
128- ClassWithEnum . StatusEnum ::values,
140+ StatusEnum ::values,
129141 eq(1 ),
130142 { r -> r.contentEquals(arrayOf(READY , ERROR )) },
131143 )
@@ -134,7 +146,7 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas
134146 @Test
135147 fun testFromCode () {
136148 checkStaticMethod(
137- ClassWithEnum . StatusEnum ::fromCode,
149+ StatusEnum ::fromCode,
138150 eq(3 ),
139151 { code, r -> code == 10 && r == READY },
140152 { code, r -> code == - 10 && r == ERROR },
@@ -145,22 +157,19 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas
145157 @Test
146158 fun testFromIsReady () {
147159 checkStaticMethod(
148- ClassWithEnum . StatusEnum ::fromIsReady,
160+ StatusEnum ::fromIsReady,
149161 eq(2 ),
150162 { isFirst, r -> isFirst && r == READY },
151163 { isFirst, r -> ! isFirst && r == ERROR },
152164 )
153165 }
154166
155167 @Test
156- @Disabled(" TODO JIRA:1450" )
157168 fun testPublicGetCodeMethod () {
158169 checkWithThis(
159- ClassWithEnum .StatusEnum ::publicGetCode,
160- eq(2 ),
161- { enumInstance, r -> enumInstance == READY && r == 10 },
162- { enumInstance, r -> enumInstance == ERROR && r == - 10 },
163- coverage = DoNotCalculate
170+ StatusEnum ::publicGetCode,
171+ between(1 .. 2 ),
172+ { enumInstance, r -> enumInstance == READY && r == 10 || enumInstance == ERROR && r == - 10 },
164173 )
165174 }
166175
0 commit comments