1 /*
2  * Copyright (C) 2023 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 
17 package com.android.systemui.statusbar.pipeline.shared.data.model
18 
19 import androidx.test.ext.junit.runners.AndroidJUnit4
20 import androidx.test.filters.SmallTest
21 import com.android.systemui.SysuiTestCase
22 import com.android.systemui.log.LogMessageImpl
23 import com.google.common.truth.Truth.assertThat
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 
27 @SmallTest
28 @RunWith(AndroidJUnit4::class)
29 class DefaultConnectionModelTest : SysuiTestCase() {
30     @Test
messageInitializerAndPrinter_isValidatedFalse_hasCorrectInfonull31     fun messageInitializerAndPrinter_isValidatedFalse_hasCorrectInfo() {
32         val model =
33             DefaultConnectionModel(
34                 DefaultConnectionModel.Wifi(isDefault = false),
35                 DefaultConnectionModel.Mobile(isDefault = true),
36                 DefaultConnectionModel.CarrierMerged(isDefault = true),
37                 DefaultConnectionModel.Ethernet(isDefault = false),
38                 isValidated = false,
39             )
40         val message = LogMessageImpl.create()
41 
42         model.messageInitializer(message)
43         val messageString = model.messagePrinter(message)
44 
45         assertThat(messageString).contains("wifi.isDefault=false")
46         assertThat(messageString).contains("mobile.isDefault=true")
47         assertThat(messageString).contains("carrierMerged.isDefault=true")
48         assertThat(messageString).contains("ethernet.isDefault=false")
49         assertThat(messageString).contains("isValidated=false")
50     }
51 
52     @Test
messageInitializerAndPrinter_isValidatedTrue_hasCorrectInfonull53     fun messageInitializerAndPrinter_isValidatedTrue_hasCorrectInfo() {
54         val model =
55             DefaultConnectionModel(
56                 DefaultConnectionModel.Wifi(isDefault = true),
57                 DefaultConnectionModel.Mobile(isDefault = false),
58                 DefaultConnectionModel.CarrierMerged(isDefault = false),
59                 DefaultConnectionModel.Ethernet(isDefault = false),
60                 isValidated = true,
61             )
62         val message = LogMessageImpl.create()
63 
64         model.messageInitializer(message)
65         val messageString = model.messagePrinter(message)
66 
67         assertThat(messageString).contains("wifi.isDefault=true")
68         assertThat(messageString).contains("mobile.isDefault=false")
69         assertThat(messageString).contains("carrierMerged.isDefault=false")
70         assertThat(messageString).contains("ethernet.isDefault=false")
71         assertThat(messageString).contains("isValidated=true")
72     }
73 }
74