diff options
author | Chiachang Wang <chiachangwang@google.com> | 2019-09-03 05:44:52 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-09-03 05:44:52 -0700 |
commit | 8d6567a96f484d7bf3ee293deaa888a40bc001ec (patch) | |
tree | aaf5e9d4c14079e59b37770f4a9aac38f67e19eb | |
parent | 69f6356c397754a68ccb91639ce2c8df61db8f08 (diff) | |
parent | 6002e86ede90e8758ede975e8fc3613b00e71169 (diff) |
Merge "Add DataStallStatsUtilsTest"
am: 6002e86ede
Change-Id: I257d3da9b47571bdbc4efce54ef5500b7c13a2be
-rw-r--r-- | src/com/android/networkstack/metrics/DataStallStatsUtils.java | 8 | ||||
-rw-r--r-- | tests/unit/src/android/networkstack/metrics/DataStallStatsUtilsTest.kt | 44 |
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) + } +} |