Eric Schwarzenbach | bd44c9e | 2017-09-06 11:53:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | package com.android.settingslib.wifi; |
| 17 | |
| 18 | import static com.google.common.truth.Truth.assertThat; |
| 19 | |
| 20 | import android.net.NetworkKey; |
| 21 | import android.net.ScoredNetwork; |
| 22 | import android.net.WifiKey; |
| 23 | import android.os.Parcel; |
| 24 | |
| 25 | import com.android.settingslib.SettingLibRobolectricTestRunner; |
| 26 | import com.android.settingslib.TestConfig; |
| 27 | import java.util.Date; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.Test; |
| 30 | import org.junit.runner.RunWith; |
| 31 | import org.robolectric.RuntimeEnvironment; |
| 32 | import org.robolectric.annotation.Config; |
| 33 | |
| 34 | @RunWith(SettingLibRobolectricTestRunner.class) |
| 35 | @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) |
| 36 | public class TimestampedScoredNetworkTest { |
| 37 | private TimestampedScoredNetwork impl; |
| 38 | |
| 39 | private ScoredNetwork createTestScoredNetwork(String ssid) { |
| 40 | return new ScoredNetwork( |
| 41 | new NetworkKey(new WifiKey("\"" + ssid + "\"", "00:00:00:00:00:00")), null); |
| 42 | } |
| 43 | |
| 44 | @Before |
| 45 | public void setUp() { |
| 46 | impl = new TimestampedScoredNetwork(createTestScoredNetwork("test"), |
| 47 | 0 /* updatedTimestampMillis */); |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void testUpdate() { |
| 52 | long time = new Date().getTime(); |
| 53 | ScoredNetwork updated = createTestScoredNetwork("updated"); |
| 54 | impl.update(updated, time); |
| 55 | |
| 56 | assertThat(impl.getScore()).isEqualTo(updated); |
| 57 | assertThat(impl.getUpdatedTimestampMillis()).isEqualTo(time); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testParcel() { |
| 62 | Parcel parcel = Parcel.obtain(); |
| 63 | impl.writeToParcel(parcel, 0); |
| 64 | parcel.setDataPosition(0); |
| 65 | |
| 66 | TimestampedScoredNetwork fromParcel = TimestampedScoredNetwork.CREATOR.createFromParcel(parcel); |
| 67 | |
| 68 | assertThat(fromParcel.getScore()).isEqualTo(impl.getScore()); |
| 69 | assertThat(fromParcel.getUpdatedTimestampMillis()).isEqualTo(impl.getUpdatedTimestampMillis()); |
| 70 | } |
| 71 | } |