diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt index 0ee5a87163..ac4d25fac8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt @@ -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 ) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt index d5139836bd..bb8fe91e87 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt @@ -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) -> diff --git a/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java b/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java index f8ba8061cb..409cca216b 100644 --- a/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java +++ b/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java @@ -410,21 +410,16 @@ long closedStreamExample(List values) { } @SuppressWarnings({"ReplaceInefficientStreamCount", "ConstantConditions"}) + // TODO wrong generic type for data field https://github.com/UnitTestBot/UTBotJava/issues/730 long customCollectionStreamExample(CustomCollection customCollection) { UtMock.assume(customCollection != null && customCollection.data != null); - if (customCollection.isEmpty()) { - return customCollection.stream().count(); + final Stream 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(); } }