Skip to content
Merged
Show file tree
Hide file tree
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 @@ -16,6 +16,7 @@
package androidx.test.internal.runner;

import static androidx.test.internal.util.Checks.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;

import android.app.Instrumentation;
import android.os.Bundle;
Expand Down Expand Up @@ -53,7 +54,7 @@ private TestExecutor(Builder builder) {
* <p>If an error occurred during the test execution, the exception will be thrown, and it's the
* caller's responsibility to handle the exception properly.
*/
public Bundle execute(Request request) throws UnsupportedEncodingException {
public Bundle execute(Request request) {
Trace.beginSection("execute tests");
try {
return execute(new JUnitCore(), request);
Expand All @@ -62,7 +63,7 @@ public Bundle execute(Request request) throws UnsupportedEncodingException {
}
}

Bundle execute(JUnitCore junitRunner, Request request) throws UnsupportedEncodingException {
Bundle execute(JUnitCore junitRunner, Request request) {
Bundle resultBundle = new Bundle();
setUpListeners(junitRunner);
Result junitResults = junitRunner.run(request);
Expand All @@ -72,10 +73,15 @@ Bundle execute(JUnitCore junitRunner, Request request) throws UnsupportedEncodin
try (PrintStream summaryWriter = new PrintStream(summaryStream)) {
reportRunEnded(listeners, summaryWriter, resultBundle, junitResults);
}
String summaryOutput = StackTrimmer.getTrimmedSummary(summaryStream.toString("UTF_8"));
resultBundle.putString(
Instrumentation.REPORT_KEY_STREAMRESULT, String.format("\n%s", summaryOutput));
return resultBundle;
try {
// ByteArrayOutputStream.toString(Charset) requires API level 33
String summaryOutput = StackTrimmer.getTrimmedSummary(summaryStream.toString(UTF_8.name()));
resultBundle.putString(
Instrumentation.REPORT_KEY_STREAMRESULT, String.format("\n%s", summaryOutput));
return resultBundle;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 encoding not supported?", e);
}
}

/** Initialize listeners and add them to the JUnitCore runner */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import androidx.test.filters.SmallTest;
import androidx.test.internal.runner.listener.InstrumentationRunListener;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.Description;
Expand Down Expand Up @@ -67,7 +66,7 @@ public void run(RunNotifier notifier) {}

/** Simple normal case execution */
@Test
public void testExecute() throws UnsupportedEncodingException {
public void testExecute() {
executor.execute(mockRequest);
verify(mockListener)
.instrumentationRunFinished(
Expand Down
Loading