Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.google.common.io.LineProcessor;
import java.util.List;
import java.util.logging.Logger;
import java.util.Map;


/**
* {@link LineProcessor} for instrumentation test runner output.
Expand Down Expand Up @@ -123,36 +125,14 @@ public boolean processLine(String line) {
}

if (line.startsWith(STATUS_CODE)) {
String statusCode = line.replace(STATUS_CODE, "").trim();
int statusInt = Integer.parseInt(statusCode);

String statusCode = extractContent(line, STATUS_CODE).trim();
int code = Integer.parseInt(statusCode);
try {
switch (statusInt) {
case 1:
currentTest.setStatus(Status.STARTED);
onTestStart(currentTest.build());
break;
case 0:
currentTest.setStatus(Status.PASSED);
break;
case -1:
currentTest.setStatus(Status.ERROR);
break;
case -2:
currentTest.setStatus(Status.FAILED);
break;
case -4:
currentTest.setStatus(Status.ASSUMPTION_FAILURE);
break;
default:
throw new IllegalArgumentException(
String.format("Illegal test instrumentation code: \"%s\"", statusCode));
}
applyStatus(code);
} finally {
onTestFinished(currentTest.build());
currentTest = null;
}

return true;
}

Expand Down Expand Up @@ -190,6 +170,38 @@ public boolean processLine(String line) {
return true;
}

private static final Map<Integer, Status> STATUS_CODE_MAP = Map.of(
1, Status.STARTED,
0, Status.PASSED,
-1, Status.ERROR,
-2, Status.FAILED,
-4, Status.ASSUMPTION_FAILURE
);

private Status statusFromCode(int code) {
Status status = STATUS_CODE_MAP.get(code);
if (status == null) {
throw new IllegalArgumentException(
"Illegal test instrumentation code: \"" + code + "\"");
}
return status;
}

private void applyStatus(int code) {
Status status = statusFromCode(code);
currentTest.setStatus(status);
if (status == Status.STARTED) {
onTestStart(currentTest.build());
}
}
/**
* Returns the content of {@code line} after removing the expected {@code prefix}.
* Assumes the line starts with the given prefix.
*/
private String extractContent(String line, String prefix) {
return line.substring(prefix.length());
}

private void onTestFinished(ExecutedTest executedTest) {
executedTests.add(executedTest);
eventBus.post(executedTest);
Expand Down