Skip to content

Commit 31f8a64

Browse files
kluevercopybara-androidxtest
authored andcommitted
Automated Code Change
PiperOrigin-RevId: 879196974
1 parent b609087 commit 31f8a64

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

runner/android_junit_runner/java/androidx/test/internal/runner/TestExecutor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package androidx.test.internal.runner;
1717

1818
import static androidx.test.internal.util.Checks.checkNotNull;
19+
import static java.nio.charset.StandardCharsets.UTF_8;
1920

2021
import android.app.Instrumentation;
2122
import android.os.Bundle;
@@ -53,7 +54,7 @@ private TestExecutor(Builder builder) {
5354
* <p>If an error occurred during the test execution, the exception will be thrown, and it's the
5455
* caller's responsibility to handle the exception properly.
5556
*/
56-
public Bundle execute(Request request) throws UnsupportedEncodingException {
57+
public Bundle execute(Request request) {
5758
Trace.beginSection("execute tests");
5859
try {
5960
return execute(new JUnitCore(), request);
@@ -62,7 +63,7 @@ public Bundle execute(Request request) throws UnsupportedEncodingException {
6263
}
6364
}
6465

65-
Bundle execute(JUnitCore junitRunner, Request request) throws UnsupportedEncodingException {
66+
Bundle execute(JUnitCore junitRunner, Request request) {
6667
Bundle resultBundle = new Bundle();
6768
setUpListeners(junitRunner);
6869
Result junitResults = junitRunner.run(request);
@@ -72,10 +73,15 @@ Bundle execute(JUnitCore junitRunner, Request request) throws UnsupportedEncodin
7273
try (PrintStream summaryWriter = new PrintStream(summaryStream)) {
7374
reportRunEnded(listeners, summaryWriter, resultBundle, junitResults);
7475
}
75-
String summaryOutput = StackTrimmer.getTrimmedSummary(summaryStream.toString("UTF_8"));
76-
resultBundle.putString(
77-
Instrumentation.REPORT_KEY_STREAMRESULT, String.format("\n%s", summaryOutput));
78-
return resultBundle;
76+
try {
77+
// ByteArrayOutputStream.toString(Charset) requires API level 33
78+
String summaryOutput = StackTrimmer.getTrimmedSummary(summaryStream.toString(UTF_8.name()));
79+
resultBundle.putString(
80+
Instrumentation.REPORT_KEY_STREAMRESULT, String.format("\n%s", summaryOutput));
81+
return resultBundle;
82+
} catch (UnsupportedEncodingException e) {
83+
throw new RuntimeException("UTF-8 encoding not supported?", e);
84+
}
7985
}
8086

8187
/** Initialize listeners and add them to the JUnitCore runner */

runner/android_junit_runner/javatests/androidx/test/internal/runner/TestExecutorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import androidx.test.filters.SmallTest;
2626
import androidx.test.internal.runner.listener.InstrumentationRunListener;
2727
import java.io.PrintStream;
28-
import java.io.UnsupportedEncodingException;
2928
import org.junit.Before;
3029
import org.junit.Test;
3130
import org.junit.runner.Description;
@@ -67,7 +66,7 @@ public void run(RunNotifier notifier) {}
6766

6867
/** Simple normal case execution */
6968
@Test
70-
public void testExecute() throws UnsupportedEncodingException {
69+
public void testExecute() {
7170
executor.execute(mockRequest);
7271
verify(mockListener)
7372
.instrumentationRunFinished(

0 commit comments

Comments
 (0)