summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/networkstack/metrics/DataStallStatsUtils.java8
-rw-r--r--tests/unit/src/android/networkstack/metrics/DataStallStatsUtilsTest.kt44
2 files changed, 51 insertions, 1 deletions
diff --git a/src/com/android/networkstack/metrics/DataStallStatsUtils.java b/src/com/android/networkstack/metrics/DataStallStatsUtils.java
index 9308901..59e8fd3 100644
--- a/src/com/android/networkstack/metrics/DataStallStatsUtils.java
+++ b/src/com/android/networkstack/metrics/DataStallStatsUtils.java
@@ -21,6 +21,8 @@ import android.annotation.Nullable;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
+
import com.android.internal.util.HexDump;
import com.android.server.connectivity.nano.DataStallEventProto;
@@ -38,7 +40,11 @@ public class DataStallStatsUtils {
private static final String TAG = DataStallStatsUtils.class.getSimpleName();
private static final boolean DBG = false;
- private static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) {
+ /**
+ * Map {@link CaptivePortalProbeResult} to {@link DataStallEventProto}.
+ */
+ @VisibleForTesting
+ public static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) {
if (result == null) return DataStallEventProto.INVALID;
if (result.isSuccessful()) {
diff --git a/tests/unit/src/android/networkstack/metrics/DataStallStatsUtilsTest.kt b/tests/unit/src/android/networkstack/metrics/DataStallStatsUtilsTest.kt
new file mode 100644
index 0000000..3b53b5f
--- /dev/null
+++ b/tests/unit/src/android/networkstack/metrics/DataStallStatsUtilsTest.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.networkstack.metrics
+
+import android.net.captiveportal.CaptivePortalProbeResult
+import androidx.test.filters.SmallTest
+import androidx.test.runner.AndroidJUnit4
+import com.android.networkstack.metrics.DataStallStatsUtils
+import com.android.server.connectivity.nano.DataStallEventProto
+import org.junit.Assert.assertEquals
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+class DataStallStatsUtilsTest {
+ @Test
+ fun testProbeResultToEnum() {
+ assertEquals(DataStallStatsUtils.probeResultToEnum(null), DataStallEventProto.INVALID)
+ assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.FAILED),
+ DataStallEventProto.INVALID)
+ assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.SUCCESS),
+ DataStallEventProto.VALID)
+ assertEquals(DataStallStatsUtils.probeResultToEnum(CaptivePortalProbeResult.PARTIAL),
+ DataStallEventProto.PARTIAL)
+ assertEquals(DataStallStatsUtils.probeResultToEnum(
+ CaptivePortalProbeResult(CaptivePortalProbeResult.PORTAL_CODE)),
+ DataStallEventProto.PORTAL)
+ }
+}