GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Other class is not mocked as required #747 by Markoutte · Pull Request #1033 · UnitTestBot/UTBotJava Conversation
|
|
|
||
| } | ||
|
|
||
| internal fun MethodId.toFuzzerMockable(block: suspend SequenceScope<Pair<MethodId, List<UtModel>>>.() -> Unit): FuzzerMockableMethodId { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you make a data class for these pairs?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
"Pair" is used as convenient and well-known construction like "key to value". Because this method is used by dsl I'd prefer to keep it this way.
Also, I have some doubt about using data classes for such small pairs. Maybe, typealias is more proper way in these cases?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| constructorId.classId, | ||
| g.name, | ||
| g.returnType.id, | ||
| emptyList() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please, use a named argument here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| setterAndGetter?.first, | ||
| setterAndGetter?.second, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
And here (a data class). From a browser, it's not obvious which one is what.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| values[index].add(model) | ||
| val mock = replaceToMock(model.model, description.shouldMock) | ||
| values[index].add(FuzzedValue(mock, model.createdBy).apply { | ||
| summary = model.summary |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why is it not a part of the constructor?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| fun replaceToMock(assembleModel: UtModel, shouldMock: (ClassId) -> Boolean): UtModel { | ||
| if (assembleModel !is UtAssembleModel) return assembleModel | ||
| if (shouldMock(assembleModel.classId)) { | ||
| return UtCompositeModel(assembleModel.id, assembleModel.classId, true).apply { | ||
| assembleModel.modificationsChain.forEach { | ||
| if (it is UtDirectSetFieldModel) { | ||
| fields[it.fieldId] = replaceToMock(it.fieldModel, shouldMock) | ||
| } | ||
| if (it is UtExecutableCallModel && it.executable is FuzzerMockableMethodId) { | ||
| (it.executable as FuzzerMockableMethodId).mock().forEach { (executionId, models) -> | ||
| mocks[executionId] = models.map { p -> replaceToMock(p, shouldMock) } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| val models = assembleModel.modificationsChain.map { call -> | ||
| var mockedStatementModel: UtStatementModel? = null | ||
| if (call is UtDirectSetFieldModel) { | ||
| val mock = replaceToMock(call.fieldModel, shouldMock) | ||
| if (mock != call.fieldModel) { | ||
| mockedStatementModel = UtDirectSetFieldModel(call.instance, call.fieldId, mock) | ||
| } | ||
| } else if (call is UtExecutableCallModel) { | ||
| val params = call.params.map { m -> replaceToMock(m, shouldMock) } | ||
| if (params != call.params) { | ||
| mockedStatementModel = UtExecutableCallModel(call.instance, call.executable, params) | ||
| } | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As for me, it is hard to read because of missing spaces. My suggestion is something like:
fun replaceToMock(
assembleModel: UtModel,
shouldMock: (ClassId) -> Boolean
): UtModel = with(assembleModel) {
if (this !is UtAssembleModel) return this
if (shouldMock(classId)) {
UtCompositeModel(id, classId, isMock = true).apply {
modificationsChain.forEach {
if (it is UtDirectSetFieldModel) {
fields[it.fieldId] = replaceToMock(it.fieldModel, shouldMock)
}
if (it is UtExecutableCallModel && it.executable is FuzzerMockableMethodId) {
(it.executable as FuzzerMockableMethodId).mock().forEach { (executionId, models) ->
mocks[executionId] = models.map { p -> replaceToMock(p, shouldMock) }
}
}
}
}
} else {
val models = modificationsChain.map { call ->
var mockedStatementModel: UtStatementModel? = null
if (call is UtDirectSetFieldModel) {
val mock = replaceToMock(call.fieldModel, shouldMock)
if (mock != call.fieldModel) {
mockedStatementModel = UtDirectSetFieldModel(call.instance, call.fieldId, mock)
}
} else if (call is UtExecutableCallModel) {
val params = call.params.map { m -> replaceToMock(m, shouldMock) }
if (params != call.params) {
mockedStatementModel = UtExecutableCallModel(call.instance, call.executable, params)
}
}
mockedStatementModel ?: call
}
with(assembleModel) {
UtAssembleModel(id, classId, modelName, instantiationCall, origin) { models }
}
}
}
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a899cec to
23dc52a
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Other class is not mocked as required
There was an error while loading. Please reload this page.