|
|
@@ -15,8 +15,10 @@ import java.lang.reflect.ParameterizedType;
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.SortedSet;
|
|
|
import java.util.TreeSet;
|
|
|
import java.util.function.Function;
|
|
|
@@ -39,6 +41,8 @@ public class InterfaceSuite {
|
|
|
|
|
|
private final List<TesterWrapper> testers = new ArrayList<>();
|
|
|
|
|
|
+ private final Set<String> ignored = new HashSet<>();
|
|
|
+
|
|
|
private final PrintStream output;
|
|
|
|
|
|
private boolean debug;
|
|
|
@@ -51,6 +55,11 @@ public class InterfaceSuite {
|
|
|
this.debug = value;
|
|
|
return this;
|
|
|
}
|
|
|
+
|
|
|
+ public InterfaceSuite ignore(String method) {
|
|
|
+ this.ignored.add(method);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
public InterfaceSuite append(Object tester) {
|
|
|
testers.add(new TesterWrapper(tester));
|
|
|
@@ -96,23 +105,36 @@ public class InterfaceSuite {
|
|
|
private boolean irun(TGenerator generator) {
|
|
|
Class<?> type = generator.get().getClass();
|
|
|
Counter counter = new Counter();
|
|
|
- List<Throwable> errors = new ArrayList<>();
|
|
|
+ List<String> failed = new ArrayList<>();
|
|
|
methods.stream().filter((m)->m.accept(type)).forEach((m)->{
|
|
|
try {
|
|
|
m.run(counter, generator);
|
|
|
} catch(Throwable cause) {
|
|
|
- errors.add(cause);
|
|
|
+ failed.add(m.label);
|
|
|
+ cause.printStackTrace(output);
|
|
|
}
|
|
|
});
|
|
|
- errors.stream().forEach((cause) -> {
|
|
|
- cause.printStackTrace(new PrintStream(output));
|
|
|
- });
|
|
|
- if(!errors.isEmpty()) {
|
|
|
- Assert.fail("Failed interface tests: " + errors.size() + "/"+counter.value);
|
|
|
+ ireset();
|
|
|
+ if(!failed.isEmpty()) {
|
|
|
+ output.println();
|
|
|
+ output.println("Failed interface tests: ");
|
|
|
+ for(String f : failed) {
|
|
|
+ output.print(f);
|
|
|
+ }
|
|
|
+ output.println();
|
|
|
+ Assert.fail("Failed interface tests: " + failed.size() + "/"+counter.value);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private void ireset() {
|
|
|
+ debug = false;
|
|
|
+ ignored.clear();
|
|
|
+ for(TesterWrapper tester : testers) {
|
|
|
+ tester.resetParams();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private MethodRunner runner(Object that, Method method) {
|
|
|
if( method.getParameterTypes()[0].equals(Supplier.class) ) {
|
|
|
return new SMethodRunner(that, method);
|
|
|
@@ -153,17 +175,22 @@ public class InterfaceSuite {
|
|
|
|
|
|
protected final String uid;
|
|
|
|
|
|
+ protected final String nid;
|
|
|
+
|
|
|
protected final Class<?> type;
|
|
|
|
|
|
protected final Object that;
|
|
|
|
|
|
protected final Method method;
|
|
|
+
|
|
|
+ protected String label;
|
|
|
|
|
|
public MethodRunner(Object that, Method method) {
|
|
|
this.type = typeof(method);
|
|
|
this.that = that;
|
|
|
this.method = method;
|
|
|
this.uid = type.getName()+"#"+method.getDeclaringClass().getName() +"#" + method.getName();
|
|
|
+ this.nid = method.getDeclaringClass().getSimpleName() + "." + method.getName();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -178,6 +205,10 @@ public class InterfaceSuite {
|
|
|
protected abstract void invoke(TGenerator argument) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException;
|
|
|
|
|
|
public void run(Counter counter, TGenerator param) throws RuntimeException {
|
|
|
+ if( ignored.contains(nid) ) {
|
|
|
+ printf(type, counter.next(), method, "IGNORED");
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
invoke(param);
|
|
|
printf(type, counter.next(), method, "");
|
|
|
@@ -187,12 +218,14 @@ public class InterfaceSuite {
|
|
|
if(ex.getTargetException() instanceof UnsupportedOperationException) {
|
|
|
UnsupportedOperationException uoe = (UnsupportedOperationException)ex.getTargetException();
|
|
|
|
|
|
- if( !"TEST.SILENT".equals(uoe.getMessage())) {
|
|
|
+ if( "NO TEST".equals(uoe.getMessage())) {
|
|
|
+ printf(type, counter.next(), method, "UNSUPPORTED");
|
|
|
if(debug) {
|
|
|
ex.printStackTrace(output);
|
|
|
}
|
|
|
- String comment = "TEST.IGNORE".equals(uoe.getMessage()) ? "IGNORED" : "UNSUPPORTED";
|
|
|
- printf(type, counter.next(), method, comment);
|
|
|
+ } else {
|
|
|
+ printf(type, counter.next(), method, "FAILED");
|
|
|
+ throw NewAssert.rethrow(ex.getTargetException());
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
@@ -208,13 +241,14 @@ public class InterfaceSuite {
|
|
|
} else {
|
|
|
comment = " - " + comment;
|
|
|
}
|
|
|
- output.printf(" - SUITE: %s [%d] %s.%s%s%n",
|
|
|
+ label = String.format(" - SUITE: %s [%d] %s.%s%s%n",
|
|
|
type.getName(),
|
|
|
index,
|
|
|
method.getDeclaringClass().getSimpleName(),
|
|
|
method.getName(),
|
|
|
comment
|
|
|
);
|
|
|
+ output.print(label);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -278,7 +312,7 @@ public class InterfaceSuite {
|
|
|
private static final class TesterWrapper {
|
|
|
|
|
|
private final Object object;
|
|
|
- private final Map<String, Field> resources = new HashMap<>();
|
|
|
+ private final Map<String, IParam> resources = new HashMap<>();
|
|
|
|
|
|
public TesterWrapper(Object object) {
|
|
|
this.object = object;
|
|
|
@@ -291,21 +325,22 @@ public class InterfaceSuite {
|
|
|
name = f.getName();
|
|
|
}
|
|
|
f.setAccessible(true);
|
|
|
- resources.put(name, f);
|
|
|
+ resources.put(name, new IParam(object, f));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void param(String name, Object value) {
|
|
|
- if( !resources.containsKey(name) ) {
|
|
|
- return;
|
|
|
+ if( resources.containsKey(name) ) {
|
|
|
+ resources.get(name).set(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void resetParams() {
|
|
|
+ for(IParam param : resources.values()) {
|
|
|
+ param.reset();
|
|
|
}
|
|
|
- try {
|
|
|
- resources.get(name).set(object, value);
|
|
|
- } catch (ReflectiveOperationException ex) {
|
|
|
- throw NewAssert.rethrow(ex);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -351,5 +386,38 @@ public class InterfaceSuite {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private static final class IParam {
|
|
|
+ private final Object object;
|
|
|
+ private final Field field;
|
|
|
+ private final Object value;
|
|
|
+
|
|
|
+ public IParam(Object object, Field field) {
|
|
|
+ try {
|
|
|
+ this.object = object;
|
|
|
+ this.field = field;
|
|
|
+ this.value = field.get(object);
|
|
|
+ } catch(ReflectiveOperationException cause) {
|
|
|
+ throw NewAssert.rethrow(cause);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void set(Object value) {
|
|
|
+ try {
|
|
|
+ field.set(object, value);
|
|
|
+ } catch(ReflectiveOperationException cause) {
|
|
|
+ throw NewAssert.rethrow(cause);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reset() {
|
|
|
+ try {
|
|
|
+ field.set(object, value);
|
|
|
+ } catch(ReflectiveOperationException cause) {
|
|
|
+ throw NewAssert.rethrow(cause);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|