Skip to content
Browse files

findbugs/eclipse warnings fixed

  • Loading branch information...
1 parent c478a53 commit 9d91bcb8d2d6342f005752bd6dc0be858164b1ea aclement committed
View
80 testing-drivers/src/org/aspectj/testing/drivers/Harness.java
@@ -54,18 +54,6 @@
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.StringTokenizer;
/**
* Test harness for running AjcTest.Suite test suites.
@@ -240,7 +228,7 @@ public void runMain(String[] args, List resultList) {
return;
}
String[] globalOptions = (String[]) globals.toArray(new String[0]);
- String[][] globalOptionVariants = LangUtil.optionVariants(globalOptions);
+ String[][] globalOptionVariants = optionVariants(globalOptions);
AbstractRunSpec.RT runtime = new AbstractRunSpec.RT();
if (verboseHarness) {
runtime.setVerbose(true);
@@ -298,7 +286,7 @@ public void runMain(String[] args, List resultList) {
} finally {
doEndSuite(suiteFile,elapsed);
}
- if (exitOnFailure && (null != result)) {
+ if (exitOnFailure) {
int numFailures = RunUtils.numFailures(result.status, true);
if (0 < numFailures) {
System.exit(numFailures);
@@ -329,6 +317,64 @@ private void doEndSuite(File suiteFile, long elapsed) {
}
}
}
+ /**
+ * Generate variants of String[] options by creating an extra set for
+ * each option that ends with "-". If none end with "-", then an
+ * array equal to <code>new String[][] { options }</code> is returned;
+ * if one ends with "-", then two sets are returned,
+ * three causes eight sets, etc.
+ * @return String[][] with each option set.
+ * @throws IllegalArgumentException if any option is null or empty.
+ */
+ public static String[][] optionVariants(String[] options) {
+ if ((null == options) || (0 == options.length)) {
+ return new String[][] { new String[0]};
+ }
+ // be nice, don't stomp input
+ String[] temp = new String[options.length];
+ System.arraycopy(options, 0, temp, 0, temp.length);
+ options = temp;
+ boolean[] dup = new boolean[options.length];
+ int numDups = 0;
+
+ for (int i = 0; i < options.length; i++) {
+ String option = options[i];
+ if (LangUtil.isEmpty(option)) {
+ throw new IllegalArgumentException("empty option at " + i);
+ }
+ if (option.endsWith("-")) {
+ options[i] = option.substring(0, option.length()-1);
+ dup[i] = true;
+ numDups++;
+ }
+ }
+ final String[] NONE = new String[0];
+ final int variants = exp(2, numDups);
+ final String[][] result = new String[variants][];
+ // variant is a bitmap wrt doing extra value when dup[k]=true
+ for (int variant = 0; variant < variants; variant++) {
+ ArrayList next = new ArrayList();
+ int nextOption = 0;
+ for (int k = 0; k < options.length; k++) {
+ if (!dup[k] || (0 != (variant & (1 << (nextOption++))))) {
+ next.add(options[k]);
+ }
+ }
+ result[variant] = (String[]) next.toArray(NONE);
+ }
+ return result;
+ }
+
+ private static int exp(int base, int power) { // not in Math?
+ if (0 > power) {
+ throw new IllegalArgumentException("negative power: " + power);
+ }
+ int result = 1;
+ while (0 < power--) {
+ result *= base;
+ }
+ return result;
+ }
/**
* @param suiteFile
@@ -1255,7 +1301,7 @@ public void doRunCompleted(IRunStatus run, StreamsHandler.Result result) {
*/
class JUnitXMLLogger extends TestCompleteListener {
- private File suite;
+// private File suite;
private StringBuffer junitOutput;
private long startTimeMillis;
private int numTests = 0;
@@ -1277,7 +1323,7 @@ public void doRunCompleted(IRunStatus run, Result result) {
long duration = System.currentTimeMillis() - startTimeMillis;
numTests++;
junitOutput.append("<testcase name=\"" + run.getIdentifier() + "\" ");
- junitOutput.append("time=\"" + timeFormatter.format(((float)duration)/1000.0) + "\"");
+ junitOutput.append("time=\"" + timeFormatter.format((duration)/1000.0f) + "\"");
junitOutput.append(">");
if (!run.runResult()) {
numFails++;
@@ -1321,7 +1367,7 @@ protected void doEndSuite(File suite, long duration) {
*/
protected void doStartSuite(File suite) {
super.doStartSuite(suite);
- this.suite = suite;
+// this.suite = suite;
numTests = 0;
numFails = 0;
junitOutput = new StringBuffer();
View
40 testing-drivers/testsrc/org/aspectj/testing/drivers/AjctestsAdapter.java
@@ -80,7 +80,7 @@ public static AjctestsAdapter make(String suitePath, String[] options) {
log("loading " + tests.length + " tests in " + suitePath);
}
for (int i = 0; i < tests.length; i++) {
- AjcTest.Spec ajcTest = (AjcTest.Spec) tests[i];
+ AjcTest.Spec ajcTest = tests[i];
result.addTest(new AjcTestSpecAsTest(ajcTest, result));
}
return result;
@@ -244,9 +244,9 @@ private Sandbox getSandbox() {
public static class SpecTests {
private static final HashMap TESTS = new HashMap();
- private static void putSpecTestsFor(String id, SpecTests tests) {
- TESTS.put(id, tests);
- }
+// private static void putSpecTestsFor(String id, SpecTests tests) {
+// TESTS.put(id, tests);
+// }
private static SpecTests getSpecTestsFor(String id) {
SpecTests result = (SpecTests) TESTS.get(id);
@@ -255,35 +255,7 @@ private static SpecTests getSpecTestsFor(String id) {
}
return result;
}
-
- private static String safeName(String name) {
- return HarnessJUnitUtil.cleanTestName(name);
- }
-
- private static String filename(String path) {
- if (null == path) {
- throw new IllegalArgumentException("null path");
- }
- int loc = path.lastIndexOf(File.pathSeparator);
- if (-1 != loc) {
- path = path.substring(loc+1);
- }
- loc = path.lastIndexOf('/');
- if (-1 != loc) {
- path = path.substring(loc+1);
- }
- loc = path.lastIndexOf(".");
- if (-1 != loc) {
- path = path.substring(0, loc);
- }
- return path;
- }
-
- private static String classnameToPath(String classname) {
- return classname.replace('.', File.separatorChar) + ".class";
- }
-
-
+
// ------------------------------------
final AjctestsAdapter mAjctestsAdapter;
@@ -296,7 +268,7 @@ private SpecTests(AjctestsAdapter ajctestsAdapter, AjcTest.Spec[] tests) {
for (int i = 0; i < tests.length; i++) {
map.put(tests[i].getDescription(), tests[i]);
}
- ;
+
mDescriptionToAjcTestSpec = Collections.unmodifiableMap(map);
}
View
2 testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessJUnitUtil.java
@@ -149,7 +149,7 @@ private static int reportResultToJUnit(String description, boolean isError, bool
String m = safeTestName(test) + " " + description;
throw new Error(m);
} else if (isFailure) {
- String m = safeTestName(test) + " " + description;
+// String m = safeTestName(test) + " " + description;
throw new AssertionFailedError(description);
} // no need to log success
}

0 comments on commit 9d91bcb

Please sign in to comment.
Something went wrong with that request. Please try again.