Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

@Markoutte
Copy link
Collaborator

@MarkoutteMarkoutte commentedSep 29, 2022
edited
Loading

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

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Automated Testing

org.utbot.framework.plugin.api.MockOfObjectModelProviderTest

Manual Scenario

Reproduce examples from the issue.

Checklist:

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
  • All tests pass locally with my changes

@MarkoutteMarkoutteforce-pushed thepelevin/747_Other_class_is_not_mocked_as_required branch from7a7eeb8 to35408f2CompareOctober 4, 2022 10:07
@MarkoutteMarkoutte marked this pull request as ready for reviewOctober 4, 2022 10:07
Copy link
Member

@CaelmBleiddCaelmBleidd left a 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 {
Copy link
Member

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?

Copy link
CollaboratorAuthor

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()
Copy link
Member

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

Comment on lines 164 to 165
setterAndGetter?.first,
setterAndGetter?.second,
Copy link
Member

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
Copy link
Member

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?

Comment on lines 31 to 59
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)
}
}
Copy link
Member

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 }        }    }}

@MarkoutteMarkoutteforce-pushed thepelevin/747_Other_class_is_not_mocked_as_required branch froma899cec to23dc52aCompareOctober 11, 2022 12:35
@MarkoutteMarkoutte merged commit1ba00d4 intomainOct 11, 2022
@MarkoutteMarkoutte deleted the pelevin/747_Other_class_is_not_mocked_as_required branchOctober 11, 2022 13:40
AbdullinAM pushed a commit to AbdullinAM/UTBotJava that referenced this pull requestOct 17, 2022
AbdullinAM pushed a commit to AbdullinAM/UTBotJava that referenced this pull requestOct 17, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@CaelmBleiddCaelmBleiddCaelmBleidd approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Other class is not mocked as required

3 participants

@Markoutte@CaelmBleidd

[8]ページ先頭

©2009-2025 Movatter.jp