Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06f330a1 authored by Andrew Scull's avatar Andrew Scull
Browse files

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
parent 3e13eb5a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ android_test {
        "service-rkp.impl",
        "services.core",
        "truth-prebuilt",
        "truth-java8-extension-jar",
    ],
    test_suites: [
        "device-tests",
+4 −3
Original line number Diff line number Diff line
@@ -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