MetricNamesGenerator { public String getSharedPreferencesWrittenBytes(boolean isInBackground) { return MetricRegistry.name( appendCrossMetricInfo(DISK + SEPARATOR + SHARED_PREFERENCES_WRITTEN_BYTES, isInBackground)); } MetricNamesGenerator(App app, Device device, Time time); String getFrameTimeMetricName(Activity activity); String getOnActivityCreatedMetricName(Activity activity); String getOnActivityStartedMetricName(Activity activity); String getOnActivityResumedMetricName(Activity activity); String getActivityVisibleMetricName(Activity activity); String getOnActivityPausedMetricName(Activity activity); String getOnActivityStoppedMetricName(Activity activity); String getOnActivityDestroyedMetricName(Activity activity); String getBytesDownloadedMetricName(boolean isInBackground); String getBytesUploadedMetricName(boolean isInBackground); String getCPUUsageMetricName(boolean isInBackground); String getMemoryUsageMetricName(boolean forBackground); String getBytesAllocatedMetricName(boolean forBackground); String getInternalStorageWrittenBytes(boolean isInBackground); String getSharedPreferencesWrittenBytes(boolean isInBackground);  }
@Test public void doesNotIdentifyAnInternalStorageWrittenBytesMetricAsSharedPrefsWrittenBytes() { String writtenBytes = generator.getSharedPreferencesWrittenBytes(ANY_IN_IN_BACKGROUND_VALUE); assertFalse(extractor.isBytesAllocatedMetric(writtenBytes)); }
@Test public void sharedPrefsWrittenBytesMetricNameShouldContainExactly11FieldsSeparatedByDots() { String writtenBytes = generator.getSharedPreferencesWrittenBytes(ANY_IN_IN_BACKGROUND_VALUE); assertEquals(12, MetricNameUtils.split(writtenBytes).length); }
@Test public void sharedPrefsWrittenBytesMetricNameShouldContainTheCrossMetricInfoName() { String writtenBytes = generator.getSharedPreferencesWrittenBytes(ANY_IN_IN_BACKGROUND_VALUE); assertContainsCrossMetricInfoName(writtenBytes); }
@Test public void sharedPrefsWrittenBytesContainsTheMetricNameInTheCorrectPosition() { String writtenBytes = generator.getSharedPreferencesWrittenBytes(ANY_IN_IN_BACKGROUND_VALUE); String[] parts = MetricNameUtils.split(writtenBytes); assertEquals("sharedPreferencesStorageWrittenBytes", parts[11]); }
@Test public void identifiesASharedPrefsWrittenBytesMetricProperly() { String writtenBytes = generator.getSharedPreferencesWrittenBytes(ANY_IN_IN_BACKGROUND_VALUE); assertTrue(extractor.isSharedPreferencesAllocatedBytesMetric(writtenBytes)); }
@Test public void doesNotIdentifyASharedPrefsWrittenBytesMetricAsInternalStorageWrittenBytes() { String writtenBytes = generator.getSharedPreferencesWrittenBytes(ANY_IN_IN_BACKGROUND_VALUE); assertFalse(extractor.isInternalStorageAllocatedBytesMetric(writtenBytes)); }