MetricNamesGenerator { public String getCPUUsageMetricName(boolean isInBackground) { return MetricRegistry.name(appendCrossMetricInfo(CPU_USAGE, 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 cpuUsageMetricNameShouldContainExactly10FieldsSeparatedByDots() { String cpuUsage = generator.getCPUUsageMetricName(ANY_IN_IN_BACKGROUND_VALUE); assertEquals(11, MetricNameUtils.split(cpuUsage).length); }
@Test public void cpuUsageMetricNameShouldContainTheCrossMetricInfoName() { String cpuUsage = generator.getCPUUsageMetricName(ANY_IN_IN_BACKGROUND_VALUE); assertContainsCrossMetricInfoName(cpuUsage); }
@Test public void cpuUsageContainsTheMetricNameInTheCorrectPosition() { String cpuUsage = generator.getCPUUsageMetricName(ANY_IN_IN_BACKGROUND_VALUE); String[] parts = MetricNameUtils.split(cpuUsage); assertEquals("cpuUsage", parts[10]); }
@Test public void cpuMetricsNameInBackgroundOrForegroundHaveToBeDifferent() { String foreground = generator.getCPUUsageMetricName(false); String background = generator.getCPUUsageMetricName(true); assertFalse(foreground.equals(background)); }