private boolean isConnected() { if (!mConnectivity.isConnected()) return false; switch (mDispatchMode) { case ALWAYS: return true; case WIFI_ONLY: return mConnectivity.getType() == Connectivity.Type.WIFI; default: return false; } }
private boolean isConnected() { if (!mConnectivity.isConnected()) return false; switch (mDispatchMode) { case ALWAYS: return true; case WIFI_ONLY: return mConnectivity.getType() == Connectivity.Type.WIFI; default: return false; } }
@Test public void testConnectivityChange() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); when(mConnectivity.isConnected()).thenReturn(false); mDispatcher.submit(getTestEvent()); mDispatcher.forceDispatch(); verify(mEventCache, timeout(1000)).add(any()); verify(mEventCache, never()).drainTo(Matchers.anyList()); assertThat(dryRunData.size(), is(0)); when(mConnectivity.isConnected()).thenReturn(true); mDispatcher.forceDispatch(); await().atMost(1, TimeUnit.SECONDS).until(() -> dryRunData.size(), is(1)); verify(mEventCache).updateState(true); verify(mEventCache).drainTo(Matchers.anyList()); }
@Test public void testClear_cleanExit() throws InterruptedException { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.submit(getTestEvent()); mDispatcher.forceDispatch(); TestHelper.sleep(100); assertThat(dryRunData.size(), is(1)); dryRunData.clear(); when(mConnectivity.isConnected()).thenReturn(false); mDispatcher.submit(getTestEvent()); TestHelper.sleep(100); assertThat(mEventCacheData.size(), is(1)); mDispatcher.clear(); when(mConnectivity.isConnected()).thenReturn(true); mDispatcher.forceDispatch(); TestHelper.sleep(100); assertThat(dryRunData.size(), is(0)); }
@Test public void testClear_cleanExit() throws InterruptedException { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.submit(getTestEvent()); mDispatcher.forceDispatch(); TestHelper.sleep(100); assertThat(dryRunData.size(), is(1)); dryRunData.clear(); when(mConnectivity.isConnected()).thenReturn(false); mDispatcher.submit(getTestEvent()); TestHelper.sleep(100); assertThat(mEventCacheData.size(), is(1)); mDispatcher.clear(); when(mConnectivity.isConnected()).thenReturn(true); mDispatcher.forceDispatch(); TestHelper.sleep(100); assertThat(dryRunData.size(), is(0)); }
@Test public void testConnectivityChange() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); when(mConnectivity.isConnected()).thenReturn(false); mDispatcher.submit(getTestEvent()); mDispatcher.forceDispatch(); verify(mEventCache, timeout(1000)).add(any()); verify(mEventCache, never()).drainTo(Matchers.anyList()); assertThat(dryRunData.size(), is(0)); when(mConnectivity.isConnected()).thenReturn(true); mDispatcher.forceDispatch(); await().atMost(1, TimeUnit.SECONDS).until(() -> dryRunData.size(), is(1)); verify(mEventCache).updateState(true); verify(mEventCache).drainTo(Matchers.anyList()); }
super.setup(); MockitoAnnotations.initMocks(this); when(mConnectivity.isConnected()).thenReturn(true); when(mConnectivity.getType()).thenReturn(Connectivity.Type.MOBILE);
super.setup(); MockitoAnnotations.initMocks(this); when(mConnectivity.isConnected()).thenReturn(true); when(mConnectivity.getType()).thenReturn(Connectivity.Type.MOBILE);