Skip to content

Commit dbe889d

Browse files
committed
Correct tests in CommonMockExampleTest, do related fixes
1 parent 22f5b42 commit dbe889d

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@ import org.utbot.testing.DoNotCalculate
77
import org.utbot.testing.UtValueTestCaseChecker
88

99
internal class CommonMocksExampleTest: UtValueTestCaseChecker(testClass = CommonMocksExample::class) {
10+
1011
@Test
11-
fun testMockInterfaceWithoutImplementors() {
12+
fun testMockInterfaceWithoutImplementorsWithNoMocksStrategy() {
13+
checkMocks(
14+
CommonMocksExample::mockInterfaceWithoutImplementors,
15+
eq(1),
16+
{ v, mocks, _ -> v == null && mocks.isEmpty() },
17+
coverage = DoNotCalculate,
18+
mockStrategy = MockStrategyApi.NO_MOCKS,
19+
)
20+
}
21+
22+
@Test
23+
fun testMockInterfaceWithoutImplementorsWithMockingStrategy() {
1224
checkMocks(
1325
CommonMocksExample::mockInterfaceWithoutImplementors,
1426
eq(2),
1527
{ v, mocks, _ -> v == null && mocks.isEmpty() },
1628
{ _, mocks, _ -> mocks.singleOrNull() != null },
17-
coverage = DoNotCalculate
29+
coverage = DoNotCalculate,
30+
mockStrategy = MockStrategyApi.OTHER_CLASSES,
1831
)
1932
}
2033

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ class Traverser(
277277

278278
internal val objectCounter = ObjectCounter(TypeRegistry.objectCounterInitialValue)
279279

280-
281-
282280
private fun findNewAddr(insideStaticInitializer: Boolean): UtAddrExpression {
283281
val newAddr = objectCounter.createNewAddr()
284282
// return negative address for objects created inside static initializer
@@ -1387,7 +1385,7 @@ class Traverser(
13871385

13881386
val mockedObject = mockedObjectInfo.value
13891387
if (mockedObjectInfo is UnexpectedMock) {
1390-
queuedSymbolicStateUpdates += UtFalse.asHardConstraint()
1388+
error("Wrong mocker configuration, it has NO_MOCK stategy, but decided to mock $type object")
13911389
}
13921390

13931391

@@ -1480,7 +1478,8 @@ class Traverser(
14801478

14811479
val mockedObject = mockedObjectInfo.value ?: error("Mocked value cannot be null after force mock")
14821480
if (mockedObjectInfo is UnexpectedMock) {
1483-
queuedSymbolicStateUpdates += UtFalse.asHardConstraint()
1481+
queuedSymbolicStateUpdates += nullEqualityConstraint.asHardConstraint()
1482+
return mockedObject
14841483
}
14851484

14861485
queuedSymbolicStateUpdates += MemoryUpdate(mockInfos = persistentListOf(MockInfoEnriched(mockInfo)))
@@ -2721,7 +2720,7 @@ class Traverser(
27212720
// TODO isMock????
27222721
InvocationTarget(mockedObject, method, constraints)
27232722
}
2724-
is UnexpectedMock -> null
2723+
is UnexpectedMock -> unreachableBranch("If it ever happens, it should be investigated")
27252724
}
27262725
}
27272726
}

0 commit comments

Comments
 (0)