Search in sources :

Example 1 with CellInfoCallback

use of android.telephony.TelephonyManager.CellInfoCallback in project robolectric by robolectric.

the class ShadowTelephonyManagerTest method shouldGiveCellInfoUpdate.

@Test
@Config(minSdk = Q)
public void shouldGiveCellInfoUpdate() throws Exception {
    List<CellInfo> callbackCellInfo = Collections.singletonList(mock(CellInfo.class));
    shadowOf(telephonyManager).setCallbackCellInfos(callbackCellInfo);
    assertNotEquals(callbackCellInfo, telephonyManager.getAllCellInfo());
    CountDownLatch callbackLatch = new CountDownLatch(1);
    shadowOf(telephonyManager).requestCellInfoUpdate(new Executor() {

        @Override
        public void execute(Runnable r) {
            r.run();
        }
    }, new CellInfoCallback() {

        @Override
        public void onCellInfo(List<CellInfo> list) {
            assertEquals(callbackCellInfo, list);
            callbackLatch.countDown();
        }
    });
    assertTrue(callbackLatch.await(5000, TimeUnit.MILLISECONDS));
}
Also used : MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Executor(java.util.concurrent.Executor) CellInfo(android.telephony.CellInfo) CountDownLatch(java.util.concurrent.CountDownLatch) CellInfoCallback(android.telephony.TelephonyManager.CellInfoCallback) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

CellInfo (android.telephony.CellInfo)1 CellInfoCallback (android.telephony.TelephonyManager.CellInfoCallback)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executor (java.util.concurrent.Executor)1 Test (org.junit.Test)1 Config (org.robolectric.annotation.Config)1