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");
}
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);
}
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");
}
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");
}
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);
}
Aggregations