Skip to content

Fixed wrong targets for virtual invokes #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,13 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
}

@Test
@Disabled("TODO unsat type constraints https://github.com/UnitTestBot/UTBotJava/issues/253")
fun testCustomCollectionStreamExample() {
check(
BaseStreamExample::customCollectionStreamExample,
ignoreExecutionsNumber,
{ c, r -> c.isEmpty() && r == 0L },
{ c, r -> c.isNotEmpty() && c.size.toLong() == r },
coverage = DoNotCalculate
coverage = DoNotCalculate // TODO failed coverage calculation
)
}

Expand Down
11 changes: 9 additions & 2 deletions utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2346,8 +2346,15 @@ class Traverser(
// for objects (especially objects with type equals to type parameter of generic)
// better than engine.
val types = instanceOfConstraint?.typeStorage?.possibleConcreteTypes ?: instance.possibleConcreteTypes
val methodInvocationTargets = findLibraryTargets(instance.type, methodSubSignature)
?: findMethodInvocationTargets(types, methodSubSignature)

val allPossibleConcreteTypes = typeResolver
.constructTypeStorage(instance.type, useConcreteType = false)
.possibleConcreteTypes

val methodInvocationTargets = findLibraryTargets(instance.type, methodSubSignature)?.takeIf {
// we have no specified types, so we can take only library targets (if present) for optimization purposes
types.size == allPossibleConcreteTypes.size
} ?: findMethodInvocationTargets(types, methodSubSignature)

return methodInvocationTargets
.map { (method, implementationClass, possibleTypes) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,16 @@ long closedStreamExample(List<Integer> values) {
}

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

if (customCollection.isEmpty()) {
return customCollection.stream().count();
final Stream<Integer> stream = customCollection.stream();

// simplified example, does not generate branch too
/*customCollection.removeIf(Objects::isNull);
return customCollection.toArray().length;*/
if (customCollection.isEmpty()) {
return stream.count();
} else {
return customCollection.stream().count();

// simplified example, does not generate branch too
/*customCollection.removeIf(Objects::isNull);
return customCollection.toArray().length;*/
return stream.count();
}
}

Expand Down