Add test for MetricsFeatureProvider#getAttribution.
Forgot to add tests in previous CL, oops
Bug: 117860032
Test: robotests
Change-Id: If575a6282080bb39ba622e9aa2e84e7473b4bf61
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java
index 7a7f0d4..603f838 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java
@@ -15,11 +15,15 @@
*/
package com.android.settingslib.core.instrumentation;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import android.app.Activity;
+import android.app.settings.SettingsEnums;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -33,6 +37,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
@@ -90,4 +95,28 @@
anyString(),
eq(Pair.create(MetricsEvent.FIELD_CONTEXT, MetricsEvent.SETTINGS_GESTURES)));
}
+
+ @Test
+ public void getAttribution_noActivity_shouldReturnUnknown() {
+ assertThat(mProvider.getAttribution(null /* activity */))
+ .isEqualTo(SettingsEnums.PAGE_UNKNOWN);
+ }
+
+ @Test
+ public void getAttribution_notSet_shouldReturnUnknown() {
+ final Activity activity = Robolectric.setupActivity(Activity.class);
+
+ assertThat(mProvider.getAttribution(activity))
+ .isEqualTo(SettingsEnums.PAGE_UNKNOWN);
+ }
+
+ @Test
+ public void getAttribution_set_shouldReturnAttribution() {
+ final Intent intent = new Intent()
+ .putExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY, 100);
+
+ final Activity activity = Robolectric.buildActivity(Activity.class, intent).create().get();
+
+ assertThat(mProvider.getAttribution(activity)).isEqualTo(100);
+ }
}