Skip to content

Commit 317fbd5

Browse files
committed
Rename tests
1 parent 4c0797d commit 317fbd5

File tree

39 files changed

+1096
-952
lines changed

39 files changed

+1096
-952
lines changed

android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/RedeemVoucherDialogTest.kt

+4-7
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class RedeemVoucherDialogTest {
5656
val mockedClickHandler: (Boolean) -> Unit = mockk(relaxed = true)
5757
setContentWithTheme {
5858
RedeemVoucherDialog(
59-
uiState =
60-
VoucherDialogUiState(voucherViewModelState = VoucherDialogState.Success(0)),
59+
uiState = VoucherDialogUiState(voucherState = VoucherDialogState.Success(0)),
6160
onVoucherInputChange = {},
6261
onRedeem = {},
6362
onDismiss = mockedClickHandler
@@ -98,8 +97,7 @@ class RedeemVoucherDialogTest {
9897
// Arrange
9998
setContentWithTheme {
10099
RedeemVoucherDialog(
101-
uiState =
102-
VoucherDialogUiState(voucherViewModelState = VoucherDialogState.Verifying),
100+
uiState = VoucherDialogUiState(voucherState = VoucherDialogState.Verifying),
103101
onVoucherInputChange = {},
104102
onRedeem = {},
105103
onDismiss = {}
@@ -116,8 +114,7 @@ class RedeemVoucherDialogTest {
116114
// Arrange
117115
setContentWithTheme {
118116
RedeemVoucherDialog(
119-
uiState =
120-
VoucherDialogUiState(voucherViewModelState = VoucherDialogState.Success(0)),
117+
uiState = VoucherDialogUiState(voucherState = VoucherDialogState.Success(0)),
121118
onVoucherInputChange = {},
122119
onRedeem = {},
123120
onDismiss = {}
@@ -136,7 +133,7 @@ class RedeemVoucherDialogTest {
136133
RedeemVoucherDialog(
137134
uiState =
138135
VoucherDialogUiState(
139-
voucherViewModelState = VoucherDialogState.Error(ERROR_MESSAGE)
136+
voucherState = VoucherDialogState.Error(ERROR_MESSAGE)
140137
),
141138
onVoucherInputChange = {},
142139
onRedeem = {},

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RedeemVoucherDialog.kt

+10-16
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ fun RedeemVoucherDialog(
119119
) {
120120
AlertDialog(
121121
title = {
122-
if (uiState.voucherViewModelState !is VoucherDialogState.Success)
122+
if (uiState.voucherState !is VoucherDialogState.Success)
123123
Text(
124124
text = stringResource(id = R.string.enter_voucher_code),
125125
)
126126
},
127127
confirmButton = {
128128
Column {
129-
if (uiState.voucherViewModelState !is VoucherDialogState.Success) {
129+
if (uiState.voucherState !is VoucherDialogState.Success) {
130130
VariantButton(
131131
text = stringResource(id = R.string.redeem),
132132
onClick = { onRedeem(uiState.voucherInput) },
@@ -138,13 +138,11 @@ fun RedeemVoucherDialog(
138138
text =
139139
stringResource(
140140
id =
141-
if (uiState.voucherViewModelState is VoucherDialogState.Success)
141+
if (uiState.voucherState is VoucherDialogState.Success)
142142
R.string.got_it
143143
else R.string.cancel
144144
),
145-
onClick = {
146-
onDismiss(uiState.voucherViewModelState is VoucherDialogState.Success)
147-
}
145+
onClick = { onDismiss(uiState.voucherState is VoucherDialogState.Success) }
148146
)
149147
}
150148
},
@@ -153,11 +151,9 @@ fun RedeemVoucherDialog(
153151
modifier = Modifier.fillMaxWidth(),
154152
horizontalAlignment = Alignment.CenterHorizontally
155153
) {
156-
if (uiState.voucherViewModelState is VoucherDialogState.Success) {
154+
if (uiState.voucherState is VoucherDialogState.Success) {
157155
val days: Int =
158-
(uiState.voucherViewModelState.addedTime /
159-
DateTimeConstants.SECONDS_PER_DAY)
160-
.toInt()
156+
(uiState.voucherState.addedTime / DateTimeConstants.SECONDS_PER_DAY).toInt()
161157
val message =
162158
stringResource(
163159
R.string.added_to_your_account,
@@ -190,9 +186,7 @@ fun RedeemVoucherDialog(
190186
},
191187
containerColor = MaterialTheme.colorScheme.background,
192188
titleContentColor = MaterialTheme.colorScheme.onBackground,
193-
onDismissRequest = {
194-
onDismiss(uiState.voucherViewModelState is VoucherDialogState.Success)
195-
},
189+
onDismissRequest = { onDismiss(uiState.voucherState is VoucherDialogState.Success) },
196190
properties =
197191
DialogProperties(
198192
securePolicy =
@@ -257,17 +251,17 @@ private fun EnterVoucherBody(
257251
verticalAlignment = Alignment.CenterVertically,
258252
modifier = Modifier.height(Dimens.listIconSize).fillMaxWidth()
259253
) {
260-
if (uiState.voucherViewModelState is VoucherDialogState.Verifying) {
254+
if (uiState.voucherState is VoucherDialogState.Verifying) {
261255
MullvadCircularProgressIndicatorSmall()
262256
Text(
263257
text = stringResource(id = R.string.verifying_voucher),
264258
modifier = Modifier.padding(start = Dimens.smallPadding),
265259
color = MaterialTheme.colorScheme.onPrimary,
266260
style = MaterialTheme.typography.bodySmall
267261
)
268-
} else if (uiState.voucherViewModelState is VoucherDialogState.Error) {
262+
} else if (uiState.voucherState is VoucherDialogState.Error) {
269263
Text(
270-
text = uiState.voucherViewModelState.errorMessage,
264+
text = uiState.voucherState.errorMessage,
271265
color = MaterialTheme.colorScheme.error,
272266
style = MaterialTheme.typography.bodySmall
273267
)

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.padding
1212
import androidx.compose.material3.ExperimentalMaterial3Api
1313
import androidx.compose.material3.Icon
1414
import androidx.compose.material3.IconButton
15+
import androidx.compose.material3.ListItem
1516
import androidx.compose.material3.MaterialTheme
1617
import androidx.compose.material3.SnackbarHostState
1718
import androidx.compose.material3.Text
@@ -73,6 +74,7 @@ import org.koin.androidx.compose.koinViewModel
7374
@Preview
7475
@Composable
7576
private fun PreviewAccountScreen() {
77+
ListItem()
7678
AppTheme {
7779
AccountScreen(
7880
uiState =

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/VoucherDialogUiState.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package net.mullvad.mullvadvpn.compose.state
22

33
data class VoucherDialogUiState(
44
val voucherInput: String = "",
5-
val voucherViewModelState: VoucherDialogState = VoucherDialogState.Default
5+
val voucherState: VoucherDialogState = VoucherDialogState.Default
66
) {
77
companion object {
88
val INITIAL = VoucherDialogUiState()

android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/PaymentAvailabilityExtensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fun PaymentAvailability.toPaymentState(): PaymentState =
1010
is PaymentAvailability.Error.Other -> PaymentState.Error.Generic
1111
is PaymentAvailability.ProductsAvailable -> PaymentState.PaymentAvailable(products)
1212
PaymentAvailability.ProductsUnavailable -> PaymentState.NoPayment
13-
PaymentAvailability.NoProductsFounds -> PaymentState.NoProductsFounds
13+
PaymentAvailability.NoProductsFound -> PaymentState.NoProductsFounds
1414
PaymentAvailability.Loading -> PaymentState.Loading
1515
// Unrecoverable error states
1616
PaymentAvailability.Error.DeveloperError,

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VoucherDialogViewModel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class VoucherDialogViewModel(
4949
_shared
5050
.flatMapLatest {
5151
combine(vmState, voucherInput) { state, input ->
52-
VoucherDialogUiState(voucherInput = input, voucherViewModelState = state)
52+
VoucherDialogUiState(voucherInput = input, voucherState = state)
5353
}
5454
}
5555
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), VoucherDialogUiState.INITIAL)

android/app/src/test/kotlin/net/mullvad/mullvadvpn/applist/ApplicationsProviderTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ApplicationsProviderTest {
2323
}
2424

2525
@Test
26-
fun test_get_apps() {
26+
fun `fetch all apps should work`() {
2727
val launchWithInternetPackageName = "launch_with_internet_package_name"
2828
val launchWithoutInternetPackageName = "launch_without_internet_package_name"
2929
val nonLaunchWithInternetPackageName = "non_launch_with_internet_package_name"

android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt

+22-22
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,48 @@ class RelayNameComparatorTest {
1414
}
1515

1616
@Test
17-
fun test_compare_respect_numbers_in_name() {
17+
fun `given two relays with same prefix but different numbers comparator should return lowest number first`() {
1818
val relay9 =
1919
RelayItem.Relay(
2020
name = "se9-wireguard",
2121
location = mockk(),
2222
locationName = "mock",
23-
active = false
23+
active = false,
2424
)
2525
val relay10 =
2626
RelayItem.Relay(
2727
name = "se10-wireguard",
2828
location = mockk(),
2929
locationName = "mock",
30-
active = false
30+
active = false,
3131
)
3232

3333
relay9 assertOrderBothDirection relay10
3434
}
3535

3636
@Test
37-
fun test_compare_same_name() {
37+
fun `given two relays with same name with number in name comparator should return 0`() {
3838
val relay9a =
3939
RelayItem.Relay(
4040
name = "se9-wireguard",
4141
location = mockk(),
4242
locationName = "mock",
43-
active = false
43+
active = false,
4444
)
4545
val relay9b =
4646
RelayItem.Relay(
4747
name = "se9-wireguard",
4848
location = mockk(),
4949
locationName = "mock",
50-
active = false
50+
active = false,
5151
)
5252

5353
assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0)
5454
assertTrue(RelayNameComparator.compare(relay9b, relay9a) == 0)
5555
}
5656

5757
@Test
58-
fun test_compare_only_numbers_in_name() {
58+
fun `comparator should be able to handle name of only numbers`() {
5959
val relay001 =
6060
RelayItem.Relay(name = "001", location = mockk(), locationName = "mock", active = false)
6161
val relay1 =
@@ -72,75 +72,75 @@ class RelayNameComparatorTest {
7272
}
7373

7474
@Test
75-
fun test_compare_without_numbers_in_name() {
75+
fun `given two relays with same name and without number comparator should return 0`() {
7676
val relay9a =
7777
RelayItem.Relay(
7878
name = "se-wireguard",
7979
location = mockk(),
8080
locationName = "mock",
81-
active = false
81+
active = false,
8282
)
8383
val relay9b =
8484
RelayItem.Relay(
8585
name = "se-wireguard",
8686
location = mockk(),
8787
locationName = "mock",
88-
active = false
88+
active = false,
8989
)
9090

9191
assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0)
9292
assertTrue(RelayNameComparator.compare(relay9b, relay9a) == 0)
9393
}
9494

9595
@Test
96-
fun test_compare_with_trailing_zeros_in_name() {
96+
fun `given two relays with leading zeroes comparator should return lowest number first`() {
9797
val relay001 =
9898
RelayItem.Relay(
9999
name = "se001-wireguard",
100100
location = mockk(),
101101
locationName = "mock",
102-
active = false
102+
active = false,
103103
)
104104
val relay005 =
105105
RelayItem.Relay(
106106
name = "se005-wireguard",
107107
location = mockk(),
108108
locationName = "mock",
109-
active = false
109+
active = false,
110110
)
111111

112112
relay001 assertOrderBothDirection relay005
113113
}
114114

115115
@Test
116-
fun test_compare_prefix_and_numbers() {
116+
fun `given 4 relays comparator should sort by prefix then number`() {
117117
val relayAr2 =
118118
RelayItem.Relay(
119119
name = "ar2-wireguard",
120120
location = mockk(),
121121
locationName = "mock",
122-
active = false
122+
active = false,
123123
)
124124
val relayAr8 =
125125
RelayItem.Relay(
126126
name = "ar8-wireguard",
127127
location = mockk(),
128128
locationName = "mock",
129-
active = false
129+
active = false,
130130
)
131131
val relaySe5 =
132132
RelayItem.Relay(
133133
name = "se5-wireguard",
134134
location = mockk(),
135135
locationName = "mock",
136-
active = false
136+
active = false,
137137
)
138138
val relaySe10 =
139139
RelayItem.Relay(
140140
name = "se10-wireguard",
141141
location = mockk(),
142142
locationName = "mock",
143-
active = false
143+
active = false,
144144
)
145145

146146
relayAr2 assertOrderBothDirection relayAr8
@@ -149,7 +149,7 @@ class RelayNameComparatorTest {
149149
}
150150

151151
@Test
152-
fun test_compare_suffix_and_numbers() {
152+
fun `given two relays with same prefix and number comparator should sort by suffix`() {
153153
val relay2c =
154154
RelayItem.Relay(
155155
name = "se2-cloud",
@@ -162,14 +162,14 @@ class RelayNameComparatorTest {
162162
name = "se2-wireguard",
163163
location = mockk(),
164164
locationName = "mock",
165-
active = false
165+
active = false,
166166
)
167167

168168
relay2c assertOrderBothDirection relay2w
169169
}
170170

171171
@Test
172-
fun test_compare_different_length() {
172+
fun `given two relays with same prefix, but one with no suffix, the one with no suffix should come first`() {
173173
val relay22a =
174174
RelayItem.Relay(
175175
name = "se22",
@@ -182,7 +182,7 @@ class RelayNameComparatorTest {
182182
name = "se22-wireguard",
183183
location = mockk(),
184184
locationName = "mock",
185-
active = false
185+
active = false,
186186
)
187187

188188
relay22a assertOrderBothDirection relay22b

android/app/src/test/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ConnectionProxyTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ConnectionProxyTest {
5050
}
5151

5252
@Test
53-
fun test_initialize_connection_proxy() {
53+
fun `initialize connection proxy should work`() {
5454
// Arrange
5555
val eventType = slot<KClass<Event.TunnelStateChange>>()
5656
every { mockedDispatchingHandler.registerHandler(capture(eventType), any()) } just Runs
@@ -60,7 +60,7 @@ class ConnectionProxyTest {
6060
}
6161

6262
@Test
63-
fun test_tunnel_normal_connect_disconnect() {
63+
fun `normal connect and disconnect should not crash`() {
6464
// Arrange
6565
every { connection.send(any()) } just Runs
6666
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs
@@ -71,7 +71,7 @@ class ConnectionProxyTest {
7171
}
7272

7373
@Test
74-
fun test_tunnel_handle_crash_on_connect() {
74+
fun `connect should catch DeadObjectException`() {
7575
// Arrange
7676
every { connection.send(any()) } throws DeadObjectException()
7777
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs

android/app/src/test/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionDeviceDataSourceTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ServiceConnectionDeviceDataSourceTest {
4747
}
4848

4949
@Test
50-
fun test_get_devices_list() {
50+
fun `get device should work`() {
5151
// Arrange
5252
every { connection.send(any()) } just Runs
5353
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs
@@ -58,7 +58,7 @@ class ServiceConnectionDeviceDataSourceTest {
5858
}
5959

6060
@Test
61-
fun test_catch_exception_on_devices_list() {
61+
fun `get device should catch DeadObjectException`() {
6262
// Arrange
6363
every { connection.send(any()) } throws DeadObjectException()
6464
every { mockedDispatchingHandler.registerHandler(any<KClass<Event>>(), any()) } just Runs

0 commit comments

Comments
 (0)