- Notifications
You must be signed in to change notification settings - Fork45
Other class is not mocked as required #747#1033
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Other class is not mocked as required #747#1033
Uh oh!
There was an error while loading.Please reload this page.
Conversation
7a7eeb8 to35408f2Compare
CaelmBleidd left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
| } | ||
| internalfun MethodId.toFuzzerMockable(block:suspendSequenceScope<Pair<MethodId,List<UtModel>>>.()->Unit):FuzzerMockableMethodId { |
There was a problem hiding this comment.
Choose a reason for 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?
There was a problem hiding this comment.
Choose a reason for 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?
| constructorId.classId, | ||
| g.name, | ||
| g.returnType.id, | ||
| emptyList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please, use a named argument here
| setterAndGetter?.first, | ||
| setterAndGetter?.second, |
There was a problem hiding this comment.
Choose a reason for 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.
| 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.
Choose a reason for 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?
| funreplaceToMock(assembleModel:UtModel,shouldMock: (ClassId)->Boolean):UtModel { | ||
| if (assembleModel!isUtAssembleModel)return assembleModel | ||
| if (shouldMock(assembleModel.classId)) { | ||
| returnUtCompositeModel(assembleModel.id, assembleModel.classId,true).apply { | ||
| assembleModel.modificationsChain.forEach { | ||
| if (itisUtDirectSetFieldModel) { | ||
| fields[it.fieldId]= replaceToMock(it.fieldModel, shouldMock) | ||
| } | ||
| if (itisUtExecutableCallModel&& it.executableisFuzzerMockableMethodId) { | ||
| (it.executableasFuzzerMockableMethodId).mock().forEach { (executionId, models)-> | ||
| mocks[executionId]= models.map { p-> replaceToMock(p, shouldMock) } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }else { | ||
| val models= assembleModel.modificationsChain.map { call-> | ||
| var mockedStatementModel:UtStatementModel?=null | ||
| if (callisUtDirectSetFieldModel) { | ||
| val mock= replaceToMock(call.fieldModel, shouldMock) | ||
| if (mock!= call.fieldModel) { | ||
| mockedStatementModel=UtDirectSetFieldModel(call.instance, call.fieldId, mock) | ||
| } | ||
| }elseif (callisUtExecutableCallModel) { | ||
| 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.
Choose a reason for 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:
funreplaceToMock(assembleModel:UtModel,shouldMock: (ClassId)->Boolean):UtModel=with(assembleModel) {if (this!isUtAssembleModel)returnthisif (shouldMock(classId)) {UtCompositeModel(id, classId, isMock=true).apply { modificationsChain.forEach {if (itisUtDirectSetFieldModel) { fields[it.fieldId]= replaceToMock(it.fieldModel, shouldMock) }if (itisUtExecutableCallModel&& it.executableisFuzzerMockableMethodId) { (it.executableasFuzzerMockableMethodId).mock().forEach { (executionId, models)-> mocks[executionId]= models.map { p-> replaceToMock(p, shouldMock) } } } } } }else {val models= modificationsChain.map { call->var mockedStatementModel:UtStatementModel?=nullif (callisUtDirectSetFieldModel) {val mock= replaceToMock(call.fieldModel, shouldMock)if (mock!= call.fieldModel) { mockedStatementModel=UtDirectSetFieldModel(call.instance, call.fieldId, mock) } }elseif (callisUtExecutableCallModel) {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 } } }}
a899cec to23dc52aCompare
Uh oh!
There was an error while loading.Please reload this page.
Description
Adds mocks for values that are passed into a method by fuzzer. Note, that fuzzer cannot mock any internal values if they are met in the code block.
Fixes#747
Type of Change
How Has This Been Tested?
Automated Testing
org.utbot.framework.plugin.api.MockOfObjectModelProviderTest
Manual Scenario
Reproduce examples from the issue.
Checklist: