use of android.content.pm.PackageInstaller in project robolectric by robolectric.
the class ShadowPackageInstallerTest method registerSessionCallback_sessionFails.
@Test
public void registerSessionCallback_sessionFails() throws Exception {
PackageInstaller.SessionCallback mockCallback = mock(PackageInstaller.SessionCallback.class);
packageInstaller.registerSessionCallback(mockCallback, new Handler());
int sessionId = packageInstaller.createSession(createSessionParams("packageName"));
verify(mockCallback).onCreated(sessionId);
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
OutputStream outputStream = session.openWrite("filename", 0, 0);
outputStream.close();
session.commit(new IntentSender(ReflectionHelpers.createNullProxy(IIntentSender.class)));
shadowOf(packageInstaller).setSessionFails(sessionId);
verify(mockCallback).onFinished(sessionId, false);
}
use of android.content.pm.PackageInstaller in project robolectric by robolectric.
the class ShadowPackageInstallerTest method registerSessionCallback_sessionSucceeds.
@Test
public void registerSessionCallback_sessionSucceeds() throws Exception {
PackageInstaller.SessionCallback mockCallback = mock(PackageInstaller.SessionCallback.class);
packageInstaller.registerSessionCallback(mockCallback, new Handler());
int sessionId = packageInstaller.createSession(createSessionParams("packageName"));
verify(mockCallback).onCreated(sessionId);
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
OutputStream outputStream = session.openWrite("filename", 0, 0);
outputStream.close();
session.commit(new IntentSender(ReflectionHelpers.createNullProxy(IIntentSender.class)));
shadowOf(packageInstaller).setSessionProgress(sessionId, 50.0f);
verify(mockCallback).onProgressChanged(sessionId, 50.0f);
shadowOf(packageInstaller).setSessionSucceeds(sessionId);
verify(mockCallback).onFinished(sessionId, true);
}
Aggregations