@Test public void packageManagerIsBroken() throws Persistence.PersistenceException, DeviceInfoHelper.DeviceInfoException { /* Setup mocking to make device properties generation fail. */ when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenThrow(new DeviceInfoHelper.DeviceInfoException("mock", new PackageManager.NameNotFoundException())); Persistence persistence = mock(Persistence.class); @SuppressWarnings("ConstantConditions") DefaultChannel channel = new DefaultChannel(mock(Context.class), null, persistence, mock(AppCenterIngestion.class), mAppCenterHandler); channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null); Channel.Listener listener = mock(Channel.Listener.class); channel.addListener(listener); /* Enqueue a log: listener is called before but then attaching device properties fails before saving the log. */ Log log = mock(Log.class); channel.enqueue(log, TEST_GROUP, Flags.DEFAULTS); verify(listener).onPreparingLog(log, TEST_GROUP); verify(listener, never()).shouldFilter(log); verify(persistence, never()).putLog(eq(log), eq(TEST_GROUP), anyInt()); }
} catch (Exception e) { AppCenterLog.error(AppCenter.LOG_TAG, "Cannot retrieve package info", e); throw new DeviceInfoException("Cannot retrieve package info", e);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenThrow(new DeviceInfoHelper.DeviceInfoException("mock", new PackageManager.NameNotFoundException()));
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenThrow(new DeviceInfoHelper.DeviceInfoException("mock", new PackageManager.NameNotFoundException()));