Skip to content
Snippets Groups Projects
Commit 8159818a authored by Goik Martin's avatar Goik Martin
Browse files

Simplifying Map object handling

parent ba0482de
No related branches found
No related tags found
No related merge requests found
......@@ -8,15 +8,23 @@ import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
public class MarkingListener extends RunListener {
static <T> T last(T[] array) {
return array[array.length - 1];
}
private Map<String, Values> valuesByClassname = new HashMap<>();
class Values {
int points = 0,
reachablePoints = 0,
currentPoints;
reachablePoints = 0,
currentPoints = 0;
public Values() {}
public Values(int currentPoints) {
this.currentPoints = currentPoints;
}
public int getPoints() {
return points;
}
......@@ -24,6 +32,10 @@ public class MarkingListener extends RunListener {
public int getReachablePoints() {
return reachablePoints;
}
public Values set (int currentPoints){
this.currentPoints = currentPoints;
return this;
}
}
@Override
......@@ -42,31 +54,21 @@ public class MarkingListener extends RunListener {
}
Values addDescription(final Description description) {
// Split fully qualified classname string
final String[] components = description.getClassName().split("\\.");
final String testClassName = last(description.getClassName().split("\\."));
final String testClassName = components[components.length - 1];
Values values = valuesByClassname.get(testClassName);
if (null == values) {
values = new Values();
valuesByClassname.put(testClassName, values);
}
final Marking marking = description.getAnnotation(Marking.class);
if (null == marking) {
values.currentPoints = 1;
} else {
values.currentPoints = marking.points();
}
return values;
final int reacheablePoints = null == marking? 1: marking.points();
return valuesByClassname.compute(testClassName, (c, v) -> {return v == null? new Values(reacheablePoints): v.set(reacheablePoints);});
}
public String getPointSumms() {
final StringBuffer ret = new StringBuffer();
int reachablePointSum = 0,
pointSum = 0;
for (Map.Entry<String, Values> entry: valuesByClassname.entrySet()) {
ret.append(entry.getKey());
ret.append(": ");
......@@ -81,11 +83,11 @@ public class MarkingListener extends RunListener {
ret.append("\nSum (" + pointSum + "/" + reachablePointSum + ")");
return ret.toString();
}
// @Override
// public void testRunStarted(Description description) throws Exception {
// super.testRunStarted(description);
// System.out.println("testRunStarted" + description);
// }
// @Override
// public void testRunStarted(Description description) throws Exception {
// super.testRunStarted(description);
// System.out.println("testRunStarted" + description);
// }
//
// @Override
// public void testRunFinished(Result result) throws Exception {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment