Skip to content

Commit 8d3ee13

Browse files
committed
Fixed wrong types for virtual invokes
1 parent d9b7076 commit 8d3ee13

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,13 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
343343
}
344344

345345
@Test
346-
@Disabled("TODO unsat type constraints https://github.com/UnitTestBot/UTBotJava/issues/253")
347346
fun testCustomCollectionStreamExample() {
348347
check(
349348
BaseStreamExample::customCollectionStreamExample,
350349
ignoreExecutionsNumber,
351350
{ c, r -> c.isEmpty() && r == 0L },
352351
{ c, r -> c.isNotEmpty() && c.size.toLong() == r },
353-
coverage = DoNotCalculate
352+
coverage = DoNotCalculate // TODO failed coverage calculation
354353
)
355354
}
356355

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,8 +2344,15 @@ class Traverser(
23442344
// for objects (especially objects with type equals to type parameter of generic)
23452345
// better than engine.
23462346
val types = instanceOfConstraint?.typeStorage?.possibleConcreteTypes ?: instance.possibleConcreteTypes
2347-
val methodInvocationTargets = findLibraryTargets(instance.type, methodSubSignature)
2348-
?: findMethodInvocationTargets(types, methodSubSignature)
2347+
2348+
val allConcreteInvocationTargets = findMethodInvocationTargets(types, methodSubSignature)
2349+
val libraryTargets = findLibraryTargets(instance.type, methodSubSignature)
2350+
2351+
// to choose only "good" targets take only library targets in case they present in all targets,
2352+
// otherwise take all targets
2353+
val methodInvocationTargets = libraryTargets?.takeIf {
2354+
allConcreteInvocationTargets.containsAll(it)
2355+
} ?: allConcreteInvocationTargets
23492356

23502357
return methodInvocationTargets
23512358
.map { (method, implementationClass, possibleTypes) ->

utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,21 +410,16 @@ long closedStreamExample(List<Integer> values) {
410410
}
411411

412412
@SuppressWarnings({"ReplaceInefficientStreamCount", "ConstantConditions"})
413+
// TODO wrong generic type for data field https://github.com/UnitTestBot/UTBotJava/issues/730
413414
long customCollectionStreamExample(CustomCollection<Integer> customCollection) {
414415
UtMock.assume(customCollection != null && customCollection.data != null);
415416

416-
if (customCollection.isEmpty()) {
417-
return customCollection.stream().count();
417+
final Stream<Integer> stream = customCollection.stream();
418418

419-
// simplified example, does not generate branch too
420-
/*customCollection.removeIf(Objects::isNull);
421-
return customCollection.toArray().length;*/
419+
if (customCollection.isEmpty()) {
420+
return stream.count();
422421
} else {
423-
return customCollection.stream().count();
424-
425-
// simplified example, does not generate branch too
426-
/*customCollection.removeIf(Objects::isNull);
427-
return customCollection.toArray().length;*/
422+
return stream.count();
428423
}
429424
}
430425

0 commit comments

Comments
 (0)