Skip to content

Fix awt #883

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

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix review
SBOne-Kenobi committed Oct 10, 2022
commit 507c64078d8736eac02c6e16af81f6e3af53c222
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ fun buildAnswer(
methodToValues: Map<out ExecutableId, List<Any?>>
) : Answer<Any?> {
val pointers = methodToValues.mapValues { (_, _) -> 0 }.toMutableMap()
return Answer { invocation ->
val answer = Answer { invocation ->
with(invocation.method) {
pointers[executableId].let { pointer ->
methodToValues[executableId].let { values ->
@@ -28,4 +28,5 @@ fun buildAnswer(
}
}
}
return answer
}
Original file line number Diff line number Diff line change
@@ -199,7 +199,7 @@ class MockValueConstructor : Closeable {
return classInstance
}

private fun generateMockitoAnswer(methodToValues: Map<out ExecutableId, List<UtModel>>): Answer<*> {
private fun generateMockitoAnswer(methodToValues: Map<ExecutableId, List<UtModel>>): Answer<*> {
val concreteValues = methodToValues.mapValues { (_, models) ->
models.map { model ->
val mockId = MockId("mock${++mockCounter}")
@@ -215,15 +215,15 @@ class MockValueConstructor : Closeable {
return Mockito.mock(clazz, generateMockitoAnswer(mocks))
}

private fun <T : ExecutableId> computeConcreteValuesForMethods(
methodToValues: Map<T, List<UtModel>>,
): Map<T, List<Any?>> = methodToValues.mapValues { (_, models) ->
private fun computeConcreteValuesForMethods(
methodToValues: Map<ExecutableId, List<UtModel>>,
): Map<ExecutableId, List<Any?>> = methodToValues.mapValues { (_, models) ->
models.map { mockAndGet(it) }
}

private fun <T : ExecutableId> groupByClass(
methodToModels: Map<T, List<UtModel>>
): Map<ClassId, Map<T, List<UtModel>>> =
private fun groupByClass(
methodToModels: Map<ExecutableId, List<UtModel>>
): Map<ClassId, Map<ExecutableId, List<UtModel>>> =
methodToModels
.asIterable()
.groupBy { it.key.classId }
@@ -237,10 +237,10 @@ class MockValueConstructor : Closeable {
fun mockStaticMethods(
instrumentations: List<UtStaticMethodInstrumentation>,
) {
val methodToModels = instrumentations.associate { it.methodId to it.values }
val methodToModels = instrumentations.associate { (it.methodId as ExecutableId) to it.values }
val methodToModelsGroupedByClass = groupByClass(methodToModels)
controllers += methodToModelsGroupedByClass.map { (classId, m2m) ->
val methodToValues = computeConcreteValuesForMethods(m2m)
controllers += methodToModelsGroupedByClass.map { (classId, method2modelValues) ->
val methodToValues = computeConcreteValuesForMethods(method2modelValues)
StaticMethodMockController(classId.jClass, methodToValues)
}
}
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import org.utbot.framework.plugin.api.ExecutableId
*/
class StaticMethodMockController(
private val clazz: Class<*>,
private val methodToValues: Map<out ExecutableId, List<Any?>>
private val methodToValues: Map<ExecutableId, List<Any?>>
) : MockController {

override fun init() {