mirror of
https://github.com/go-i2p/gojava.git
synced 2025-07-04 10:16:23 -04:00
Added test for scan directory feature and updated readme.
This commit is contained in:
@ -64,27 +64,54 @@ public class MoreAsserts {
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SeqTest test = new SeqTest();
|
||||
Class c = test.getClass();
|
||||
boolean failed = false;
|
||||
for (Method method : c.getDeclaredMethods()) {
|
||||
if (!method.getName().startsWith("test") || !Pattern.matches(args[0], method.getName())) {
|
||||
continue;
|
||||
}
|
||||
private static boolean failed = false;
|
||||
|
||||
System.out.print(method.getName());
|
||||
try {
|
||||
method.invoke(test);
|
||||
System.out.println(" PASS");
|
||||
} catch (Exception ex) {
|
||||
System.out.println(" FAIL");
|
||||
ex.printStackTrace();
|
||||
failed = true;
|
||||
}
|
||||
private static String pattern = ".*";
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length > 0) {
|
||||
pattern = args[0];
|
||||
}
|
||||
|
||||
new TestRunner(new SeqTest()).runTests();
|
||||
new TestRunner(new ExtraTest()).runTests();
|
||||
|
||||
// NOTE: We need to call System.exit to force all go threads to exit.
|
||||
System.exit(failed ? 1 : 0);
|
||||
}
|
||||
|
||||
private static class TestRunner<T> {
|
||||
private T test;
|
||||
|
||||
public TestRunner(T test) {
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
public void runTests() {
|
||||
Class c = test.getClass();
|
||||
for (Method method : c.getDeclaredMethods()) {
|
||||
if (!method.getName().startsWith("test") || !Pattern.matches(pattern, method.getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.print(method.getName());
|
||||
try {
|
||||
method.invoke(test);
|
||||
System.out.println(" PASS");
|
||||
} catch (Exception ex) {
|
||||
System.out.println(" FAIL");
|
||||
ex.printStackTrace();
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExtraTest {
|
||||
public void testCopyFromScanDir() {
|
||||
Dummy d = new Dummy();
|
||||
assertEquals("Values must match", 42, d.fortyTwo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user