Search in sources :

Example 6 with InstallException

use of com.android.ddmlib.InstallException in project buck by facebook.

the class AdbHelperTest method testNonQuietShowsOutput.

@Test
public void testNonQuietShowsOutput() throws InterruptedException {
    final File apk = new File("/some/file.apk");
    final AtomicReference<String> apkPath = new AtomicReference<>();
    TestDevice device = new TestDevice() {

        @Override
        public void installPackage(String s, boolean b, String... strings) throws InstallException {
            apkPath.set(s);
        }
    };
    device.setSerialNumber("serial#1");
    device.setName("testDevice");
    final List<IDevice> deviceList = Lists.newArrayList((IDevice) device);
    TestConsole console = new TestConsole();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    AdbHelper adbHelper = new AdbHelper(new AdbOptions(), new TargetDeviceOptions(), TestExecutionContext.newInstance(), console, eventBus, true) {

        @Override
        protected boolean isDeviceTempWritable(IDevice device, String name) {
            return true;
        }

        @Override
        public List<IDevice> getDevices(boolean quiet) {
            return deviceList;
        }
    };
    boolean success = adbHelper.adbCall(new AdbHelper.AdbCallable() {

        @Override
        public boolean call(IDevice device) throws Exception {
            return basicAdbHelper.installApkOnDevice(device, apk, false, false);
        }

        @Override
        public String toString() {
            return "install apk";
        }
    }, false);
    assertTrue(success);
    assertEquals(apk.getAbsolutePath(), apkPath.get());
    assertEquals("", console.getTextWrittenToStdOut());
    assertEquals("Successfully ran install apk on 1 device(s)\n", console.getTextWrittenToStdErr());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) IDevice(com.android.ddmlib.IDevice) AtomicReference(java.util.concurrent.atomic.AtomicReference) AdbOptions(com.facebook.buck.step.AdbOptions) CmdLineException(org.kohsuke.args4j.CmdLineException) InstallException(com.android.ddmlib.InstallException) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) TestConsole(com.facebook.buck.testutil.TestConsole) File(java.io.File) Test(org.junit.Test)

Aggregations

InstallException (com.android.ddmlib.InstallException)6 File (java.io.File)4 Test (org.junit.Test)4 IDevice (com.android.ddmlib.IDevice)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)2 AdbOptions (com.facebook.buck.step.AdbOptions)2 TargetDeviceOptions (com.facebook.buck.step.TargetDeviceOptions)2 TestConsole (com.facebook.buck.testutil.TestConsole)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Nullable (javax.annotation.Nullable)1