/** * Common validation for both AppCenter and One Collector, specific validation happens later. */ private boolean isValidValue(Object value) { if (value == null) { AppCenterLog.error(LOG_TAG, VALUE_NULL_ERROR_MESSAGE); return false; } return true; } }
@Override public void onCallFailed(Exception e) { /* Log error and try the next configuration endpoint. */ AppCenterLog.error(LOG_TAG, "Could not get configuration file at " + url, e); getConfiguration(configurationUrlIndex + 1, rumKey, httpClient); } });
private static int getResourceIdFromMetadata(Context context, String metadataName) { Bundle metaData = null; try { metaData = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData; } catch (PackageManager.NameNotFoundException e) { AppCenterLog.error(LOG_TAG, "Package name not found.", e); } if (metaData != null) { return metaData.getInt(metadataName); } return 0; }
@Override public void onCallFailed(Exception e) { AppCenterLog.error(LOG_TAG, "Failed to report measurements at " + finalReportUrl, e); reportNextUrl(); }
/** * Clears the table in the database. */ public void clear() { try { getDatabase().delete(mTable, null, null); } catch (RuntimeException e) { AppCenterLog.error(LOG_TAG, "Failed to clear the table.", e); } }
/** * View release notes. (Using top level method to be able to use whenNew in PowerMock). */ private void viewReleaseNotes(ReleaseDetails releaseDetails) { try { mForegroundActivity.startActivity(new Intent(Intent.ACTION_VIEW, releaseDetails.getReleaseNotesUrl())); } catch (ActivityNotFoundException e) { AppCenterLog.error(LOG_TAG, "Failed to navigate to release notes.", e); } }
/** * Check whether the SDK is ready for use or not. * * @return <code>true</code> if the SDK is ready, <code>false</code> otherwise. */ private synchronized boolean checkPrecondition() { if (isInstanceConfigured()) { return true; } AppCenterLog.error(LOG_TAG, "App Center hasn't been configured. You need to call AppCenter.start with appSecret or AppCenter.configure first."); return false; }
@Test public void deleteMultipleIDsFailed() { DatabaseManager databaseManagerMock = getDatabaseManagerMock(); databaseManagerMock.delete(new ArrayList<Long>()); verifyStatic(never()); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(RuntimeException.class)); databaseManagerMock.delete(Arrays.asList(0L, 1L)); verifyStatic(); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(RuntimeException.class)); }
@Test public void nullApplicationTest() { /* First verify start from application. */ AppCenter.start(null, DUMMY_APP_SECRET, DummyService.class); verify(DummyService.getInstance(), never()).onStarted(any(Context.class), any(Channel.class), anyString(), anyString(), anyBoolean()); verifyStatic(); AppCenterLog.error(eq(LOG_TAG), anyString()); }
@Test public void nullApplicationTest() { AppCenter.startFromLibrary(null, DummyService.class); verify(DummyService.getInstance(), never()).onStarted(any(Context.class), any(Channel.class), anyString(), anyString(), anyBoolean()); verifyStatic(); AppCenterLog.error(eq(LOG_TAG), anyString()); }
@Test public void deleteFailed() { DatabaseManager databaseManagerMock = getDatabaseManagerMock(); databaseManagerMock.delete(0); verifyStatic(); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(RuntimeException.class)); }
@Test public void clearFailed() { DatabaseManager databaseManagerMock = getDatabaseManagerMock(); databaseManagerMock.clear(); verifyStatic(); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(RuntimeException.class)); }
@Test public void deleteWrapperExceptionDataWithNullId() { /* Delete null does nothing. */ WrapperSdkExceptionManager.deleteWrapperExceptionData(null); verifyStatic(never()); FileManager.delete(any(File.class)); verifyStatic(); AppCenterLog.error(eq(Crashes.LOG_TAG), anyString()); }
@Test public void readErrorAndCloseError() throws Exception { mockStatic(AppCenterLog.class); FileReader fileReader = mock(FileReader.class, new ThrowsException(new IOException())); whenNew(FileReader.class).withAnyArguments().thenReturn(fileReader); assertNull(FileManager.read(new File(""))); verify(fileReader).close(); verifyStatic(); AppCenterLog.error(anyString(), anyString(), any(IOException.class)); }
@Test public void setMaxSizeFailed() { DatabaseManager databaseManagerMock = getDatabaseManagerMock(); assertFalse(databaseManagerMock.setMaxSize(1024 * 1024)); verifyStatic(); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(RuntimeException.class)); }
@Test public void getMaxSizeFailed() { DatabaseManager databaseManagerMock = getDatabaseManagerMock(); assertEquals(-1, databaseManagerMock.getMaxSize()); verifyStatic(); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(RuntimeException.class)); }
@Test public void setBoolean() { String key = "test"; CustomProperties properties = new CustomProperties(); assertEquals(0, properties.getProperties().size()); /* Normal value. */ boolean normalValue = false; properties.set(key, normalValue); assertEquals(1, properties.getProperties().size()); verifyStatic(never()); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString()); }
@Test public void clear() { String key = "test"; CustomProperties properties = new CustomProperties(); assertEquals(0, properties.getProperties().size()); properties.clear(key); assertEquals(1, properties.getProperties().size()); verifyStatic(never()); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString()); }
@Test public void enableBeforeConfiguredTest() { /* Test isEnabled and setEnabled before configure */ assertFalse(AppCenter.isEnabled().get()); AppCenter.setEnabled(true); assertFalse(AppCenter.isEnabled().get()); verifyStatic(times(3)); AppCenterLog.error(eq(LOG_TAG), anyString()); }
@Test public void testGetTransmissionTargetWithNullToken() { mockStatic(AppCenterLog.class); assertNull(Analytics.getTransmissionTarget(null)); /* Verify log. */ verifyStatic(); AppCenterLog.error(anyString(), contains("Transmission target token may not be null or empty.")); }