Skip to content

Commit

Permalink
refactor the onCanceledItem method for test
Browse files Browse the repository at this point in the history
  • Loading branch information
yashpal2104 committed Jan 11, 2025
1 parent 4692e1c commit 67e4fd9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/jenkins/advancedqueue/sorter/SorterStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ public void onStartedItem(@NonNull LeftItem item, float weight) {}
/**
* Called when a {@link hudson.model.Item} leaves the queue and it is canceled.
*/
public void onCanceledItem(@NonNull LeftItem item) {}
public void onCanceledItem(@NonNull LeftItem item) {
if (item.isCancelled()) {

Check warning on line 70 in src/main/java/jenkins/advancedqueue/sorter/SorterStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 70 is only partially covered, one branch is missing
ExtensionList<SorterStrategy> all = all();
for (SorterStrategy prioritySorterStrategy : all) {

Check warning on line 72 in src/main/java/jenkins/advancedqueue/sorter/SorterStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 72 is only partially covered, one branch is missing
SorterStrategyDescriptor descriptor = prioritySorterStrategy.getDescriptor();
descriptor.getId();

Check warning on line 74 in src/main/java/jenkins/advancedqueue/sorter/SorterStrategy.java

View check run for this annotation

ci.jenkins.io / SpotBugs

RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT

NORMAL: Return value of hudson.model.Descriptor.getId() ignored, but method has no side effect
Raw output
<p>This code calls a method and ignores the return value. However our analysis shows that the method (including its implementations in subclasses if any) does not produce any effect other than return value. Thus this call can be removed. </p> <p>We are trying to reduce the false positives as much as possible, but in some cases this warning might be wrong. Common false-positive cases include:</p> <p>- The method is designed to be overridden and produce a side effect in other projects which are out of the scope of the analysis.</p> <p>- The method is called to trigger the class loading which may have a side effect.</p> <p>- The method is called just to get some exception.</p> <p>If you feel that our assumption is incorrect, you can use a @CheckReturnValue annotation to instruct SpotBugs that ignoring the return value of this method is acceptable. </p>
}

Check warning on line 75 in src/main/java/jenkins/advancedqueue/sorter/SorterStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 73-75 are not covered by tests
}
}
;

/**
Expand Down

0 comments on commit 67e4fd9

Please sign in to comment.