UploadHandler extends BaseHandler implements BackgroundTaskHandler { boolean upload(boolean history) { mParticleDBManager.cleanupUploadMessages(); boolean processingSessionEnd = false; try { List<MParticleDBManager.ReadyUpload> readyUploads = mParticleDBManager.getReadyUploads(); if (readyUploads.size() > 0) { mApiClient.fetchConfig(); } final boolean includeSessionHistory = mConfigManager.getIncludeSessionHistory(); for (MParticleDBManager.ReadyUpload readyUpload : readyUploads) { if (history && !includeSessionHistory) { mParticleDBManager.deleteUpload(readyUpload.getId()); } else { if (!history) { if (!processingSessionEnd && readyUpload.getMessage().contains(containsClause)) { processingSessionEnd = true; } } String message = readyUpload.getMessage(); InternalListenerManager.getListener().onCompositeObjects(readyUpload, message); if (readyUpload.isAliasRequest()) { uploadAliasRequest(readyUpload.getId(), message); } else { uploadMessage(readyUpload.getId(), message); } } } } catch (MParticleApiClientImpl.MPThrottleException e) { } catch (SSLHandshakeException ssle) { Logger.debug("SSL handshake failed while preparing uploads - possible MITM attack detected."); } catch (MParticleApiClientImpl.MPConfigException e) { Logger.error("Bad API request - is the correct API key and secret configured?"); } catch (Exception e) { Logger.error(e, "Error processing batch uploads in mParticle DB."); } return processingSessionEnd; } 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 testDontUploadSessionHistory() throws Exception { handler.handleMessage(null); Mockito.when(mConfigManager.getIncludeSessionHistory()).thenReturn(false); Cursor mockCursor = Mockito.mock(Cursor.class); Mockito.when(mockCursor.moveToNext()).thenReturn(true, false); Mockito.when(mockCursor.getInt(Mockito.anyInt())).thenReturn(123); Mockito.when(mockCursor.getString(Mockito.anyInt())).thenReturn("cool message batch!"); handler.upload(true); }