Skip to content
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 @@ -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
Expand All @@ -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)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,11 +77,16 @@ class JimpleToASTMap(stmts: Iterable<Unit>, methodDeclaration: MethodDeclaration
alignNonAlignedReturns()
}

/**
* Avoid conflict with java.util.stream.Stream.toList (available since Java 16 only)
*/
private fun <T> Stream<T>.asList(): List<T> = collect(Collectors.toList<T>())

/**
* Function that maps statements inside of ternary conditions to correct AST nodes
*/
private fun mapTernaryConditional(methodDeclaration: MethodDeclaration, stmts: Iterable<Unit>) {
for (condExpr in methodDeclaration.stream().toList().filterIsInstance<ConditionalExpr>()) {
for (condExpr in methodDeclaration.stream().asList().filterIsInstance<ConditionalExpr>()) {
val begin = condExpr.begin.orElse(null)
val end = condExpr.end.orElse(null)
if (begin == null || end == null) continue
Expand Down Expand Up @@ -123,7 +129,7 @@ class JimpleToASTMap(stmts: Iterable<Unit>, 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
}
Expand All @@ -147,17 +153,17 @@ class JimpleToASTMap(stmts: Iterable<Unit>, methodDeclaration: MethodDeclaration
val loopList = mutableListOf<Node>()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2041,3 +2043,8 @@ inline fun <reified T> withSettingsFromTestFrameworkConfiguration(
TestCodeGeneratorPipeline.currentTestFrameworkConfiguration = previousConfig
}
}

/**
* Avoid conflict with java.util.stream.Stream.toList (available since Java 16 only)
*/
fun <T> Stream<T>.asList(): List<T> = collect(Collectors.toList<T>())