Search in sources :

Example 16 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class AdbShellCommandTaskTest method commandExecution_AdbCommandRejectedException.

@Test
public void commandExecution_AdbCommandRejectedException() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    // The AdbCommandRejectedException can't be instantiated outside the package.
    AdbCommandRejectedException exception = Mockito.mock(AdbCommandRejectedException.class);
    fakeDevice.injectShellCommandOutput("getprop", () -> {
        throw exception;
    });
    AdbShellCommandTask task = new AdbShellCommandTask(fakeDevice, "getprop");
    Throwable e = assertThrows(CommandExecutionException.class, () -> task.execute());
    assertThat(e).hasMessageThat().contains("Rejected 'adb shell getprop' command");
}
Also used : AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test)

Example 17 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class AdbShellCommandTaskTest method commandExecution_ShellCommandUnresponsive.

@Test
public void commandExecution_ShellCommandUnresponsive() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    fakeDevice.injectShellCommandOutput("getprop", () -> {
        throw new ShellCommandUnresponsiveException();
    });
    AdbShellCommandTask task = new AdbShellCommandTask(fakeDevice, "getprop");
    Throwable e = assertThrows(CommandExecutionException.class, () -> task.execute());
    assertThat(e).hasMessageThat().contains("Unresponsive shell command while executing 'adb shell");
    assertThat(e).hasCauseThat().isInstanceOf(ShellCommandUnresponsiveException.class);
}
Also used : ShellCommandUnresponsiveException(com.android.ddmlib.ShellCommandUnresponsiveException) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test)

Example 18 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class DeviceAnalyzerTest method extractsGlExtensions.

@Test
public void extractsGlExtensions() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(density(240), locales("en-US"), abis("x86"), sdkVersion(21), glExtensions("GL_EXT_extension1", "GL_EXT_extension2")));
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(fakeDevice));
    fakeAdbServer.init(Paths.get("path/to/adb"));
    DeviceAnalyzer analyzer = new DeviceAnalyzer(fakeAdbServer);
    DeviceSpec deviceSpec = analyzer.getDeviceSpec(Optional.empty());
    assertThat(deviceSpec.getGlExtensionsList()).containsExactly("GL_EXT_extension1", "GL_EXT_extension2");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 19 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class AdbShellCommandTaskTest method commandExecution_output.

@Test
public void commandExecution_output() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    fakeDevice.injectShellCommandOutput("getprop", () -> "test output");
    AdbShellCommandTask task = new AdbShellCommandTask(fakeDevice, "getprop");
    assertThat(task.execute()).containsExactly("test output");
}
Also used : FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test)

Example 20 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class AdbShellCommandTaskTest method commandExecution_timeoutException.

@Test
public void commandExecution_timeoutException() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    fakeDevice.injectShellCommandOutput("getprop", () -> {
        throw new TimeoutException("Timeout");
    });
    // unknown command will cause timeout.
    AdbShellCommandTask task = new AdbShellCommandTask(fakeDevice, "getprop");
    Throwable e = assertThrows(CommandExecutionException.class, () -> task.execute());
    assertThat(e).hasMessageThat().contains("Timeout while executing 'adb shell");
    assertThat(e).hasCauseThat().isInstanceOf(TimeoutException.class);
}
Also used : FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) TimeoutException(com.android.ddmlib.TimeoutException) Test(org.junit.Test)

Aggregations

FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)32 Test (org.junit.Test)32 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)24 AdbServer (com.android.tools.build.bundletool.device.AdbServer)17 Path (java.nio.file.Path)17 ZipPath (com.android.tools.build.bundletool.model.ZipPath)16 BuildApksResult (com.android.bundle.Commands.BuildApksResult)13 DeviceSpec (com.android.bundle.Devices.DeviceSpec)10 ArrayList (java.util.ArrayList)10 Theory (org.junit.experimental.theories.Theory)9 Duration (java.time.Duration)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 DeviceState (com.android.ddmlib.IDevice.DeviceState)1 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 InstallOptions (com.android.tools.build.bundletool.device.Device.InstallOptions)1 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)1 DeviceFactory.lDeviceWithLocales (com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithLocales)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1