Use String#lines() rather than String#split()

Use the more predictable behaviour of String#lines() to split the stdout
string as an example of how it should be parsed. String#split() has
slightly surprising behaviour if stdout is empty as it results in an
array containing an empty string.

Test: atest RemoteProvisioningShellCommandTest
Bug: 281584054
Change-Id: I06796772cc58007fefb5d2089ae709965c6576b1
This commit is contained in:
Andrew Scull
2023-05-12 05:11:30 +00:00
parent 3e13eb5a26
commit 06f330a12c
2 changed files with 5 additions and 3 deletions

View File

@@ -31,6 +31,7 @@ android_test {
"service-rkp.impl",
"services.core",
"truth-prebuilt",
"truth-java8-extension-jar",
],
test_suites: [
"device-tests",

View File

@@ -17,6 +17,7 @@
package com.android.server.security.rkp;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -42,7 +43,6 @@ import org.junit.runner.RunWith;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.Base64;
import java.util.Map;
@@ -119,6 +119,7 @@ public class RemoteProvisioningShellCommandTest {
assertThat(res.getErr()).isEmpty();
assertThat(res.getCode()).isEqualTo(0);
assertThat(res.getOut()).isEmpty();
assertThat(res.getOut().lines()).isEmpty();
}
@Test
@@ -128,7 +129,7 @@ public class RemoteProvisioningShellCommandTest {
CommandResult res = exec(cmd, new String[] {"list"});
assertThat(res.getErr()).isEmpty();
assertThat(res.getCode()).isEqualTo(0);
assertThat(Arrays.asList(res.getOut().split("\n"))).containsExactly("default");
assertThat(res.getOut().lines()).containsExactly("default");
}
@Test
@@ -140,7 +141,7 @@ public class RemoteProvisioningShellCommandTest {
CommandResult res = exec(cmd, new String[] {"list"});
assertThat(res.getErr()).isEmpty();
assertThat(res.getCode()).isEqualTo(0);
assertThat(Arrays.asList(res.getOut().split("\n"))).containsExactly("default", "strongbox");
assertThat(res.getOut().lines()).containsExactly("default", "strongbox");
}
@Test