Skip to content
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

Resolve Pitest Issues - ImportOrderCheck (7) #7878

Closed
rnveach opened this issue Mar 16, 2020 · 11 comments
Closed

Resolve Pitest Issues - ImportOrderCheck (7) #7878

rnveach opened this issue Mar 16, 2020 · 11 comments

Comments

@rnveach
Copy link
Member

rnveach commented Mar 16, 2020

Child issue of #7797 ,

"ImportOrderCheck.java.html:<td class='covered'><pre><span class='survived'> staticImportSeparator = isStatic &#38;&#38; separated;</span></pre></td></tr>"

@aryaniiit002
Copy link
Contributor

i would like to work on this.

@aryaniiit002
Copy link
Contributor

aryaniiit002 commented Jan 18, 2021

i have observed something but not sure if i am correct;
so survived mutation here is
"ImportOrderCheck.java.html:<td class='covered'><pre><span class='survived'> staticImportSeparator = isStatic &#38;&#38; separated;</span></pre></td></tr>"
in ImportOrderCheck.java
method on which mutation surviving is this named needSeparator at line 692.

    /**
     * Checks whether import groups should be separated.
     * @param isStatic whether the token is static or not.
     * @return true if imports groups should be separated.
     */
    private boolean needSeparator(boolean isStatic) {
        final boolean typeImportSeparator = !isStatic && separated;
        final boolean staticImportSeparator;
        if (staticImportsApart) {
            staticImportSeparator = isStatic && separatedStaticGroups;
        }
        else {
            staticImportSeparator = isStatic && separated;
        }
        final boolean separatorBetween = isStatic != lastImportStatic
            && (separated || separatedStaticGroups) && staticImportsApart;

        return typeImportSeparator || staticImportSeparator || separatorBetween;
    }

An import could be either of type or static
if isStatic in above method is false then the result of the needSeparator will be true because there is no test for type imports using property separated with false value and default value of separated value is false so the whole method would results false. Also we need not to look at other variables because those are local variables.
so now, at line 692: isStatic is true and staticImportSeparator now depends on separated, so there is no need to have isStatic in the line.

Please have a look at these images
1st image is old pitest report

Screenshot from 2021-01-18 18-08-35

(at line 859)
new pitest report
with changed code line from
staticImportSeparator = isStatic && separated;
to
staticImportSeparator = separated;

Screenshot from 2021-01-18 18-08-39

I am not sure if i am right please have a look and let me know if there is something i missed or if this is the wrong approach.
Thanks

@strkkk
Copy link
Member

strkkk commented Jan 18, 2021

I am not sure if i am right please have a look and let me know if there is something i missed or if this is the wrong approach.

There is either

  1. Redundant condition
  2. Lack of test case

You need to either add test case that will cover it, or prove that variable can be removed without breaking check logic.

@rnveach
Copy link
Member Author

rnveach commented Jan 18, 2021

@aryaniiit002 Please read parent issue's instructions. All must be provided and will guide you on the best action for this pitest issue.
#7797

For each issue the following steps need to be taken:

@aryaniiit002
Copy link
Contributor

aryaniiit002 commented Jan 19, 2021

You need to either add test case that will cover it, or prove that variable can be removed without breaking check logic.

i don't understand how test cases works exactly.
i was trying to prove removal of variable won't break the logic, so i test all the code example with configs we have here
Issue #7687: Adding code examples for ImportOrder check #9165 in ImportOrderCheck with both
staticImportSeparator = isStatic && separated;
and
staticImportSeparator = separated;
and i can't find any difference in the results.

@aryaniiit002
Copy link
Contributor

Please respond somebody...

@strkkk
Copy link
Member

strkkk commented Jan 20, 2021

@aryaniiit002 tests are passing if you remove this condition - this is exactly the problem in this issue. It is either lack of test to cover this, or this condition is redundant (requires checking of logic)
Have you read link from #7878 (comment)?

@aryaniiit002
Copy link
Contributor

aryaniiit002 commented Jan 20, 2021

Yes i read the link and i am sure i don't understand few lines there and also i think i misunderstood checking of logic . But could you please confirm that you understand what i am trying to do?

checking of logic: i process this like checking/testing all java code example with provided configs for each one separately for both (with ifStatic and without it) and comparing the results.

@nrmancuso
Copy link
Member

nrmancuso commented Jan 22, 2021

To get an idea of the work that needs to be done, see: #7985

Please follow all steps in #7797

Please read about pitest, and make sure that you understand exactly how it works, and why it is used.

@Abhishek-kumar09
Copy link
Contributor

@aryaniiit002
As written in the PR description, you have to understand each variable of the function needSeperator.

See a mutation can be killed if you add a test case that fails when we change the code logic written in the mutation report. in your case (staticImportSeparator = isStatic && separated;).
So you can search or think of a case where the else part is executed and there is change in the test result when that else logic is modified with true/false values.
OR
It is possible that no test cases exist as such to kill the mutation, so you have to modify the code logic that is no more needed, like removing the full else part in your case or modifying the else part's logic in way it is not redundant.

You can always set a breakpoint on the part where your mutatioins are survived and take look at all the variables at that time how they are behaving with different test cases with the debugger.

@pbludov
Copy link
Member

pbludov commented Feb 11, 2021

Fix is merged.

@pbludov pbludov closed this as completed Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants