Skip to content

Issue #13109: Kill mutation for CustomImportOrderCheck 4#13212

Merged
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:cic4
Jun 19, 2023
Merged

Issue #13109: Kill mutation for CustomImportOrderCheck 4#13212
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:cic4

Conversation

@Kevin222004
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 commented Jun 13, 2023

Issue #13109: Kill mutation for CustomImportOrderCheck 4


check

https://checkstyle.org/config_imports.html#CustomImportOrder


Mutation

<mutation unstable="false">
<sourceFile>CustomImportOrderCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck</mutatedClass>
<mutatedMethod>setCustomImportOrderRules</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable customImportOrderRules</description>
<lineContent>customImportOrderRules = inputCustomImportOrder;</lineContent>
</mutation>


Explaination

This is setter for


which is
public final void setCustomImportOrderRules(final String inputCustomImportOrder) {
if (!customImportOrderRules.equals(inputCustomImportOrder)) {
for (String currentState : GROUP_SEPARATOR_PATTERN.split(inputCustomImportOrder)) {
addRulesToList(currentState);
}
customOrderRules.add(NON_GROUP_RULE_GROUP);
}
customImportOrderRules = inputCustomImportOrder;
}

we are not directly using this property hence all the rule will be first stored in
private final List<String> customOrderRules = new ArrayList<>();

hence in all the code wherever we define the property all the logic has been written using

private final List<String> customOrderRules = new ArrayList<>();

so no test case is possible


Regression

Diff Regression config: https://gist.githubusercontent.com/Kevin222004/2463f07cae06e0317712d3aae38b3d0b/raw/42a3cd2e7a12eb3b02ccac0906aace21ddaa02ce/custom.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/9600f179b602d4c971bdb0a050099005/raw/360a95ed7bb60d7a0956e531199d484c4d6f6617/test-projects.properties
Report label: Report 1

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@Kevin222004 Kevin222004 marked this pull request as ready for review June 14, 2023 07:51
@github-actions
Copy link
Copy Markdown
Contributor

@romani
Copy link
Copy Markdown
Member

romani commented Jun 14, 2023

Yes, we do not use user defined values, as we convert it to collection, and use only collection in logic.
Previously I considered as good practice to store value as it is defined by user. But I am ok to sacrifice this practice in favor of pitest.

Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to merge

*/
public final void setCustomImportOrderRules(final String inputCustomImportOrder) {
if (!customImportOrderRules.equals(inputCustomImportOrder)) {
if (!CUSTOM_IMPORT_ORDER_RULES.equals(inputCustomImportOrder)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it :) Why do we need CUSTOM_IMPORT_ORDER_RULES when we just compare the input with empty string in this place only?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have fields as constants for default values of all users accessible properties.
But I agree it looked weird even for me.

If expression as inputCustomImportOrder.isEmpty will looks better.

Naming constant as DEFAULT_xxxxxx would make it more clear, but all other default value constants are not named like this. Should we rename all of them to be more explicit?

But end up in gray area of ... What is default value of property for this module, as for user it is String.
https://checkstyle.org/config_imports.html#CustomImportOrder_Properties

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so it's a Checkstyle's requirement that the user's property field must be present even though it is not actually used. This allows setter to be called and use incoming value in the way we want.

I don't see we use DEFAULT_xxx that much in other checks, but I agree that DEFAULT_CUSTOM_IMPORT_ORDER_RULES.equals(inputCustomImportOrder) is more readable than CUSTOM_IMPORT_ORDER_RULES.equals(inputCustomImportOrder)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then I have changed name as DEFAULT_CUSTOM_IMPORT_ORDER_RULES

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a requirement, but end up our pattern for most of Checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rdiachenko rdiachenko assigned Vyom-Yadav and unassigned rdiachenko Jun 16, 2023
Copy link
Copy Markdown
Member

@Vyom-Yadav Vyom-Yadav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Vyom-Yadav Vyom-Yadav assigned romani and unassigned Vyom-Yadav Jun 16, 2023
@romani romani merged commit 7d35a52 into checkstyle:master Jun 19, 2023
smita1078 added a commit to smita1078/checkstyle that referenced this pull request Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants