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 700f39ff83..943469148e 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 @@ -17,7 +17,7 @@ import org.utbot.testing.ignoreExecutionsNumber import org.utbot.testing.isException import java.util.Optional import java.util.stream.Stream -import kotlin.streams.toList +import org.utbot.testing.asList // TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 // TODO failed Kotlin compilation (generics) JIRA:1332 @@ -35,7 +35,7 @@ class BaseStreamExampleTest : UtValueTestCaseChecker( check( BaseStreamExample::returningStreamAsParameterExample, eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, + { s, r -> s != null && s.asList() == r!!.asList() }, coverage = FullWithAssumptions(assumeCallsNumber = 1) ) } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt index a6ca53482e..109383ad87 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt @@ -9,6 +9,7 @@ import org.utbot.testing.FullWithAssumptions import org.utbot.testing.UtValueTestCaseChecker import org.utbot.testing.isException import kotlin.streams.toList +import org.utbot.testing.asList // TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 // TODO failed Kotlin compilation (generics) JIRA:1332 @@ -25,8 +26,8 @@ class StreamsAsMethodResultExampleTest : UtValueTestCaseChecker( check( StreamsAsMethodResultExample::returningStreamExample, eq(2), - { c, r -> c.isEmpty() && c == r!!.toList() }, - { c, r -> c.isNotEmpty() && c == r!!.toList() }, + { c, r -> c.isEmpty() && c == r!!.asList() }, + { c, r -> c.isNotEmpty() && c == r!!.asList() }, coverage = FullWithAssumptions(assumeCallsNumber = 1) ) } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt index 7521038520..5ccb1440bf 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt @@ -29,9 +29,10 @@ import org.utbot.framework.plugin.api.Step import org.utbot.summary.comment.isLoopStatement import java.util.LinkedList import java.util.Queue +import java.util.stream.Collectors +import java.util.stream.Stream import kotlin.Int.Companion.MAX_VALUE import kotlin.math.abs -import kotlin.streams.toList import soot.Unit import soot.Value import soot.jimple.internal.JCaughtExceptionRef @@ -76,11 +77,16 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration alignNonAlignedReturns() } + /** + * Avoid conflict with java.util.stream.Stream.toList (available since Java 16 only) + */ + private fun Stream.asList(): List = collect(Collectors.toList()) + /** * Function that maps statements inside of ternary conditions to correct AST nodes */ private fun mapTernaryConditional(methodDeclaration: MethodDeclaration, stmts: Iterable) { - for (condExpr in methodDeclaration.stream().toList().filterIsInstance()) { + for (condExpr in methodDeclaration.stream().asList().filterIsInstance()) { val begin = condExpr.begin.orElse(null) val end = condExpr.end.orElse(null) if (begin == null || end == null) continue @@ -123,7 +129,7 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration * Node is valid if there is only one return statement inside of it */ private fun validateReturnASTNode(returnNode: Node): Node { - val returns = returnNode.stream().filter { it is ReturnStmt }.toList() + val returns = returnNode.stream().filter { it is ReturnStmt }.asList() if (returns.size == 1) return returns[0] return returnNode } @@ -147,17 +153,17 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration val loopList = mutableListOf() when (loop) { is ForStmt -> { - loopList.addAll(loop.initialization.stream().toList()) - val compare = loop.compare.orElse(null)?.stream()?.toList() + loopList.addAll(loop.initialization.stream().asList()) + val compare = loop.compare.orElse(null)?.stream()?.asList() if (compare != null) loopList.addAll(compare) - loopList.addAll(loop.update.flatMap { it.stream().toList() }) + loopList.addAll(loop.update.flatMap { it.stream().asList() }) } is WhileStmt -> { - loopList.addAll(loop.condition.stream().toList()) + loopList.addAll(loop.condition.stream().asList()) } is ForEachStmt -> { - loopList.addAll(loop.iterable.stream().toList()) - loopList.addAll(loop.variable.stream().toList()) + loopList.addAll(loop.iterable.stream().asList()) + loopList.addAll(loop.variable.stream().asList()) } } for (stmt in stmtToASTNode.filter { it.value in loopList }.map { it.key }) stmtToASTNode[stmt] = loop diff --git a/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt index d78e29ee7d..8a0ae1aa54 100644 --- a/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt +++ b/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt @@ -47,6 +47,8 @@ import org.utbot.testcheckers.ExecutionsNumberMatcher import java.io.File import java.nio.file.Path import java.nio.file.Paths +import java.util.stream.Collectors +import java.util.stream.Stream import kotlin.reflect.KClass import kotlin.reflect.KFunction import kotlin.reflect.KFunction0 @@ -2041,3 +2043,8 @@ inline fun withSettingsFromTestFrameworkConfiguration( TestCodeGeneratorPipeline.currentTestFrameworkConfiguration = previousConfig } } + +/** + * Avoid conflict with java.util.stream.Stream.toList (available since Java 16 only) + */ +fun Stream.asList(): List = collect(Collectors.toList())