Skip to content

Commit 0109b18

Browse files
add more test
1 parent d76c8a3 commit 0109b18

3 files changed

Lines changed: 135 additions & 15 deletions

File tree

app/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Build Properties
2-
#Mon Jul 28 09:54:51 EDT 2025
3-
version_build=24
2+
#Mon Jul 28 21:15:00 EDT 2025
3+
version_build=25
44
version_major=3
55
version_minor=2
66
version_patch=1

app/jacoco.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def jacocoCoverageVerificationProvider = tasks.register('jacocoTestCoverageVerif
7373
}
7474
limit {
7575
counter = 'BRANCH'
76-
minimum = 0.93
76+
minimum = 0.94
7777
}
7878
limit {
7979
counter = 'COMPLEXITY'
@@ -93,4 +93,4 @@ def jacocoCoverageVerificationProvider = tasks.register('jacocoTestCoverageVerif
9393
}
9494
}
9595
}
96-
}
96+
}

app/src/test/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/AccessPointsAdapterGroupTest.kt

Lines changed: 131 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.assertj.core.api.Assertions.assertThat
2929
import org.junit.After
3030
import org.junit.Test
3131
import org.mockito.kotlin.any
32+
import org.mockito.kotlin.doReturn
3233
import org.mockito.kotlin.mock
3334
import org.mockito.kotlin.times
3435
import org.mockito.kotlin.verify
@@ -38,13 +39,15 @@ import org.mockito.kotlin.whenever
3839
class AccessPointsAdapterGroupTest {
3940
private val expandableListView: ExpandableListView = mock()
4041
private val expandableListAdapter: ExpandableListAdapter = mock()
42+
private val wiFiDetailWithChildren = mock<WiFiDetail>()
4143
private val settings = INSTANCE.settings
4244
private val fixture = AccessPointsAdapterGroup()
4345

4446
@After
4547
fun tearDown() {
4648
verifyNoMoreInteractions(expandableListView)
4749
verifyNoMoreInteractions(expandableListAdapter)
50+
verifyNoMoreInteractions(wiFiDetailWithChildren)
4851
INSTANCE.restore()
4952
}
5053

@@ -58,47 +61,47 @@ class AccessPointsAdapterGroupTest {
5861
fun afterUpdateWithGroupByChannel() {
5962
// setup
6063
val wiFiDetails = withWiFiDetails()
61-
whenever(settings.groupBy()).thenReturn(GroupBy.CHANNEL)
62-
whenever(expandableListView.expandableListAdapter).thenReturn(expandableListAdapter)
63-
whenever(expandableListAdapter.groupCount).thenReturn(wiFiDetails.size)
64+
doReturn(GroupBy.CHANNEL).whenever(settings).groupBy()
65+
doReturn(expandableListAdapter).whenever(expandableListView).expandableListAdapter
66+
doReturn(wiFiDetails.size).whenever(expandableListAdapter).groupCount
6467
// execute
6568
fixture.update(wiFiDetails, expandableListView)
6669
// validate
70+
assertThat(fixture.groupBy).isEqualTo(GroupBy.CHANNEL)
6771
verify(settings).groupBy()
6872
verify(expandableListView).expandableListAdapter
6973
verify(expandableListAdapter).groupCount
7074
verify(expandableListView, times(3)).collapseGroup(any())
71-
assertThat(fixture.groupBy).isEqualTo(GroupBy.CHANNEL)
7275
}
7376

7477
@Test
7578
fun updateGroupBy() {
7679
// setup
77-
whenever(settings.groupBy()).thenReturn(GroupBy.SSID)
80+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
7881
// execute
7982
fixture.updateGroupBy()
8083
// validate
81-
verify(settings).groupBy()
8284
assertThat(fixture.groupBy).isEqualTo(GroupBy.SSID)
85+
verify(settings).groupBy()
8386
}
8487

8588
@Test
8689
fun updateGroupByWillClearExpandedWhenGroupByIsChanged() {
8790
// setup
8891
fixture.expanded.add("TEST")
89-
whenever(settings.groupBy()).thenReturn(GroupBy.SSID)
92+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
9093
// execute
9194
fixture.updateGroupBy()
9295
// validate
93-
verify(settings).groupBy()
9496
assertThat(fixture.groupBy).isEqualTo(GroupBy.SSID)
9597
assertThat(fixture.expanded).isEmpty()
98+
verify(settings).groupBy()
9699
}
97100

98101
@Test
99102
fun updateGroupByWillNotClearExpandedWhenGroupByIsSame() {
100103
// setup
101-
whenever(settings.groupBy()).thenReturn(GroupBy.SSID)
104+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
102105
fixture.updateGroupBy()
103106
fixture.expanded.add("TEST")
104107
// execute
@@ -110,7 +113,7 @@ class AccessPointsAdapterGroupTest {
110113
@Test
111114
fun onGroupExpanded() {
112115
// setup
113-
whenever(settings.groupBy()).thenReturn(GroupBy.SSID)
116+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
114117
fixture.updateGroupBy()
115118
val wiFiDetails = withWiFiDetails()
116119
// execute
@@ -122,7 +125,7 @@ class AccessPointsAdapterGroupTest {
122125
@Test
123126
fun onGroupCollapsed() {
124127
// setup
125-
whenever(settings.groupBy()).thenReturn(GroupBy.SSID)
128+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
126129
fixture.updateGroupBy()
127130
val wiFiDetails = withWiFiDetails()
128131
fixture.onGroupExpanded(wiFiDetails, 0)
@@ -132,6 +135,123 @@ class AccessPointsAdapterGroupTest {
132135
assertThat(fixture.expanded).isEmpty()
133136
}
134137

138+
@Test
139+
fun updateWithGroupByNoneDoesNotInteractWithExpandableListView() {
140+
// setup
141+
val wiFiDetails = withWiFiDetails()
142+
doReturn(GroupBy.NONE).whenever(settings).groupBy()
143+
// execute
144+
fixture.update(wiFiDetails, expandableListView)
145+
// validate
146+
verify(settings).groupBy()
147+
}
148+
149+
@Test
150+
fun updateWithExpandableListViewNullDoesNotThrow() {
151+
// setup
152+
val wiFiDetails = withWiFiDetails()
153+
doReturn(GroupBy.CHANNEL).whenever(settings).groupBy()
154+
// execute
155+
fixture.update(wiFiDetails, null)
156+
// validate
157+
verify(settings).groupBy()
158+
}
159+
160+
@Test
161+
fun onGroupExpandedWithGroupByNoneDoesNothing() {
162+
// setup
163+
val wiFiDetails = withWiFiDetails()
164+
doReturn(GroupBy.NONE).whenever(settings).groupBy()
165+
fixture.updateGroupBy()
166+
// execute
167+
fixture.onGroupExpanded(wiFiDetails, 0)
168+
// validate
169+
assertThat(fixture.expanded).isEmpty()
170+
}
171+
172+
@Test
173+
fun onGroupCollapsedWithGroupByNoneDoesNothing() {
174+
// setup
175+
val wiFiDetails = withWiFiDetails()
176+
doReturn(GroupBy.NONE).whenever(settings).groupBy()
177+
fixture.updateGroupBy()
178+
fixture.expanded.add("test")
179+
// execute
180+
fixture.onGroupCollapsed(wiFiDetails, 0)
181+
// validate
182+
assertThat(fixture.expanded).contains("test")
183+
}
184+
185+
@Test
186+
fun onGroupExpandedWithInvalidGroupPositionDoesNothing() {
187+
// setup
188+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
189+
fixture.updateGroupBy()
190+
val wiFiDetails = withWiFiDetails()
191+
// execute
192+
fixture.onGroupExpanded(wiFiDetails, -1)
193+
fixture.onGroupExpanded(wiFiDetails, wiFiDetails.size)
194+
// validate
195+
assertThat(fixture.expanded).isEmpty()
196+
}
197+
198+
@Test
199+
fun onGroupCollapsedWithInvalidGroupPositionDoesNothing() {
200+
// setup
201+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
202+
fixture.updateGroupBy()
203+
val wiFiDetails = withWiFiDetails()
204+
fixture.expanded.add("test")
205+
// execute
206+
fixture.onGroupCollapsed(wiFiDetails, -1)
207+
fixture.onGroupCollapsed(wiFiDetails, wiFiDetails.size)
208+
// validate
209+
assertThat(fixture.expanded).contains("test")
210+
}
211+
212+
@Test
213+
fun updateWithEmptyWiFiDetailsDoesNotThrow() {
214+
// setup
215+
doReturn(GroupBy.CHANNEL).whenever(settings).groupBy()
216+
doReturn(expandableListAdapter).whenever(expandableListView).expandableListAdapter
217+
doReturn(0).whenever(expandableListAdapter).groupCount
218+
// execute
219+
fixture.update(emptyList(), expandableListView)
220+
// validate
221+
verify(settings).groupBy()
222+
verify(expandableListView).expandableListAdapter
223+
verify(expandableListAdapter).groupCount
224+
}
225+
226+
@Test
227+
fun onGroupCollapsedDoesNotRemoveIfHasChildren() {
228+
// setup
229+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
230+
fixture.updateGroupBy()
231+
doReturn(false).whenever(wiFiDetailWithChildren).noChildren
232+
val wiFiDetails = listOf(wiFiDetailWithChildren)
233+
fixture.expanded.add("test")
234+
// execute
235+
fixture.onGroupCollapsed(wiFiDetails, 0)
236+
// validate
237+
assertThat(fixture.expanded).contains("test")
238+
verify(wiFiDetailWithChildren).noChildren
239+
}
240+
241+
@Test
242+
fun onGroupExpandedDoesNotAddIfHasChildren() {
243+
// setup
244+
doReturn(GroupBy.SSID).whenever(settings).groupBy()
245+
fixture.updateGroupBy()
246+
doReturn(false).whenever(wiFiDetailWithChildren).noChildren
247+
val wiFiDetails = listOf(wiFiDetailWithChildren)
248+
// execute
249+
fixture.onGroupExpanded(wiFiDetails, 0)
250+
// validate
251+
assertThat(fixture.expanded).isEmpty()
252+
verify(wiFiDetailWithChildren).noChildren
253+
}
254+
135255
private fun withWiFiDetail(): WiFiDetail =
136256
WiFiDetail(
137257
WiFiIdentifier("SSID1", "BSSID1"),

0 commit comments

Comments
 (0)