// -------------- ✁ --------------
package org.kungfoocoder.sonarqube.bugs;
import java.util.Arrays;
import java.util.Iterator;
public class SquidS2589Tests {
public boolean testFalsePositiveSquidS2589(final String... params) {
boolean gotSign = false;
boolean gotOption = false;
int gotLow = 0;
int gotHigh = 0;
for (final Iterator<String> it = Arrays.asList(params).iterator(); it
.hasNext();) {
final String sp = it.next();
final String paramName = sp.toUpperCase();
if ("SIGN".equals(paramName)) {
gotSign = true;
} else if ("OPTION".equals(paramName)) {
gotOption = true;
} else if (paramName.indexOf("LOW") >= 0) {
gotLow++;
if (gotLow > 1) {
return false;
}
} else if (paramName.indexOf("HIGH") >= 0) {
gotHigh++;
if (gotHigh > 1) {
return false;
}
}
}
if (!gotSign || !gotOption) {
return false;
}
if (gotHigh > 0 && gotLow == 0) {
// ^^ Remove this expression which always evaluates to "true"
// we can get here if called as:
// testFalsePositiveSquidS2589("SIGN", "OPTION", "HIGH");
// In this case gotHigh == 1 and gotLow == 0
return false;
}
// we can get here if called as:
// testFalsePositiveSquidS2589("SIGN", "OPTION", "HIGH", "LOW");
// In this case gotHigh == 1 and gotLow == 1
return true;
}
public boolean testFalseNegativeSquidS2589(final String... params) {
int gotHigh = 0;
int gotElse = 0;
for (String sp : Arrays.asList(params)) {
if (sp.indexOf("HIGH") >= 0) {
gotHigh++;
if (gotHigh > 1 || gotElse > 0) {
// ^^ false negative, gotElse is never modified and so cannot be > 0
return false;
}
}
}
return true;
}
}
// -------------- ✃ --------------
--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/11cb390d-c480-4847-afc9-855fa0011046%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tibor Blenessy | SonarSource
SonarJava Developer
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/4f254d30-6950-459e-8edc-44b296bb3cd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.