UploadHandler extends BaseHandler implements BackgroundTaskHandler { public void setConnected(boolean connected){ try { if (!isNetworkConnected && connected && mConfigManager.isPushEnabled()) { MParticle.getInstance().Messaging().enablePushNotifications(mConfigManager.getPushSenderId()); } }catch (Exception e) { } isNetworkConnected = connected; } UploadHandler(Context context, ConfigManager configManager, AppStateManager appStateManager, MessageManager messageManager, MParticleDBManager mparticleDBManager);  UploadHandler(Context context, Looper looper, ConfigManager configManager, AppStateManager appStateManager, MessageManager messageManager, MParticleDBManager mparticleDBManager); @Override void handleMessageImpl(Message msg); boolean shouldDelete(int statusCode); void setConnected(boolean connected); void fetchSegments(long timeout, String endpointId, SegmentListener listener); @Override void executeNetworkRequest(Runnable runnable); static final int UPLOAD_MESSAGES; static final int UPLOAD_HISTORY; static final int UPDATE_CONFIG; static final int UPLOAD_TRIGGER_MESSAGES; static final int INIT_CONFIG; }
@Test public void testSetConnected() throws Exception { handler.isNetworkConnected = true; final CountDownLatch latch = new CountDownLatch(1); new Thread(new Runnable() { @Override public void run() { assertTrue(handler.isNetworkConnected); handler.setConnected(false); latch.countDown(); } }).start(); latch.await(1000, TimeUnit.MILLISECONDS); assertFalse(handler.isNetworkConnected); handler.isNetworkConnected = true; new Thread(new Runnable() { @Override public void run() { assertTrue(handler.isNetworkConnected); } }).start(); }