Search in sources :

Example 36 with FakeAdbServer

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

the class DeviceAnalyzerTest method deviceIdMatch_debuggingNotEnabled_throws.

@Test
public void deviceIdMatch_debuggingNotEnabled_throws() {
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(FakeDevice.inDisconnectedState("a", DeviceState.UNAUTHORIZED)));
    fakeAdbServer.init(Paths.get("path/to/adb"));
    DeviceAnalyzer analyzer = new DeviceAnalyzer(fakeAdbServer);
    Throwable exception = assertThrows(CommandExecutionException.class, () -> analyzer.getDeviceSpec(Optional.of("a")));
    assertThat(exception).hasMessageThat().contains("Device found but not authorized for connecting.");
}
Also used : FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 37 with FakeAdbServer

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

the class AdbRunnerTest method installApks_withDeviceId_connectedDevices_ok.

@Test
public void installApks_withDeviceId_connectedDevices_ok() {
    AdbServer testAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec("device1", DeviceState.ONLINE, lDeviceWithLocales("en-US")), FakeDevice.inDisconnectedState("device2", DeviceState.UNAUTHORIZED)));
    testAdbServer.init(Paths.get("/test/adb"));
    AdbRunner adbRunner = new AdbRunner(testAdbServer);
    adbRunner.run(device -> device.installApks(ImmutableList.of(apkPath), DEFAULT_INSTALL_OPTIONS), "device1");
}
Also used : FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 38 with FakeAdbServer

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

the class AdbRunnerTest method installApks_noDeviceId_noConnectedDevices_throws.

@Test
public void installApks_noDeviceId_noConnectedDevices_throws() {
    AdbServer testAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of());
    testAdbServer.init(Paths.get("/test/adb"));
    AdbRunner adbRunner = new AdbRunner(testAdbServer);
    Throwable exception = assertThrows(CommandExecutionException.class, () -> adbRunner.run(device -> device.installApks(ImmutableList.of(apkPath), DEFAULT_INSTALL_OPTIONS)));
    assertThat(exception).hasMessageThat().contains("Expected to find one connected device, but found none.");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Files(java.nio.file.Files) DeviceState(com.android.ddmlib.IDevice.DeviceState) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) DeviceFactory.lDeviceWithLocales(com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithLocales) InstallOptions(com.android.tools.build.bundletool.device.Device.InstallOptions) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Rule(org.junit.Rule) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Duration(java.time.Duration) Path(java.nio.file.Path) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 39 with FakeAdbServer

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

the class AdbRunnerTest method installApks_noDeviceId_oneConnectedDevice_ok.

@Test
public void installApks_noDeviceId_oneConnectedDevice_ok() {
    AdbServer testAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec("a", DeviceState.ONLINE, lDeviceWithLocales("en-US"))));
    testAdbServer.init(Paths.get("/test/adb"));
    AdbRunner adbRunner = new AdbRunner(testAdbServer);
    adbRunner.run(device -> device.installApks(ImmutableList.of(apkPath), DEFAULT_INSTALL_OPTIONS));
}
Also used : FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 40 with FakeAdbServer

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

the class AdbRunnerTest method installApks_noDeviceId_twoConnectedDevices_throws.

@Test
public void installApks_noDeviceId_twoConnectedDevices_throws() {
    AdbServer testAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec("a", DeviceState.ONLINE, lDeviceWithLocales("en-US")), FakeDevice.inDisconnectedState("b", DeviceState.UNAUTHORIZED)));
    testAdbServer.init(Paths.get("/test/adb"));
    AdbRunner adbRunner = new AdbRunner(testAdbServer);
    Throwable exception = assertThrows(CommandExecutionException.class, () -> adbRunner.run(device -> device.installApks(ImmutableList.of(apkPath), DEFAULT_INSTALL_OPTIONS)));
    assertThat(exception).hasMessageThat().contains("Expected to find one connected device, but found 2.");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Files(java.nio.file.Files) DeviceState(com.android.ddmlib.IDevice.DeviceState) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) DeviceFactory.lDeviceWithLocales(com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithLocales) InstallOptions(com.android.tools.build.bundletool.device.Device.InstallOptions) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Rule(org.junit.Rule) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Duration(java.time.Duration) Path(java.nio.file.Path) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Aggregations

FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)57 Test (org.junit.Test)57 FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)30 Path (java.nio.file.Path)27 AdbServer (com.android.tools.build.bundletool.device.AdbServer)23 BuildApksResult (com.android.bundle.Commands.BuildApksResult)19 ZipPath (com.android.tools.build.bundletool.model.ZipPath)16 DeviceSpec (com.android.bundle.Devices.DeviceSpec)14 ArrayList (java.util.ArrayList)10 Theory (org.junit.experimental.theories.Theory)9 ApkSet (com.android.bundle.Commands.ApkSet)7 Variant (com.android.bundle.Commands.Variant)7 DeviceState (com.android.ddmlib.IDevice.DeviceState)7 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)7 ImmutableList (com.google.common.collect.ImmutableList)7 Truth.assertThat (com.google.common.truth.Truth.assertThat)7 Files (java.nio.file.Files)7 ZipFile (java.util.zip.ZipFile)7 Before (org.junit.Before)7 Rule (org.junit.Rule)7