@@ -33,6 +33,8 @@ import com.vrem.wifianalyzer.wifi.model.WiFiIdentifier
3333import com.vrem.wifianalyzer.wifi.model.WiFiSecurity
3434import com.vrem.wifianalyzer.wifi.model.WiFiSignal
3535import com.vrem.wifianalyzer.wifi.model.WiFiWidth
36+ import com.vrem.wifianalyzer.wifi.predicate.falsePredicate
37+ import com.vrem.wifianalyzer.wifi.predicate.truePredicate
3638import org.assertj.core.api.Assertions.assertThat
3739import org.junit.Test
3840import org.junit.runner.RunWith
@@ -59,7 +61,7 @@ class DataManagerTest {
5961 // setup
6062 assertThat(fixture.xValue).isEqualTo(0 )
6163 // execute
62- fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y )
64+ fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y , truePredicate )
6365 // validate
6466 assertThat(fixture.xValue).isEqualTo(1 )
6567 }
@@ -69,7 +71,7 @@ class DataManagerTest {
6971 // setup
7072 assertThat(fixture.scanCount).isEqualTo(0 )
7173 // execute
72- fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y )
74+ fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y , truePredicate )
7375 // validate
7476 assertThat(fixture.scanCount).isEqualTo(1 )
7577 }
@@ -80,7 +82,7 @@ class DataManagerTest {
8082 val wiFiDetails = makeWiFiDetails()
8183 val wiFiDetailsSet = wiFiDetails.toSet()
8284 // execute
83- fixture.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y )
85+ fixture.addSeriesData(graphViewWrapper, wiFiDetails, MAX_Y , truePredicate )
8486 // validate
8587 wiFiDetailsSet.forEach {
8688 verify(graphViewWrapper).newSeries(it)
@@ -93,7 +95,7 @@ class DataManagerTest {
9395 // setup
9496 fixture.scanCount = MAX_SCAN_COUNT
9597 // execute
96- fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y )
98+ fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y , truePredicate )
9799 // validate
98100 assertThat(fixture.scanCount).isEqualTo(MAX_SCAN_COUNT )
99101 }
@@ -103,7 +105,7 @@ class DataManagerTest {
103105 // setup
104106 fixture.scanCount = 1
105107 // execute
106- fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y )
108+ fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y , truePredicate )
107109 // validate
108110 assertThat(fixture.scanCount).isEqualTo(2 )
109111 verify(graphViewWrapper).setHorizontalLabelsVisible(true )
@@ -112,7 +114,7 @@ class DataManagerTest {
112114 @Test
113115 fun addSeriesDoesNotSetHorizontalLabelsVisible () {
114116 // execute
115- fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y )
117+ fixture.addSeriesData(graphViewWrapper, listOf (), MAX_Y , truePredicate )
116118 // validate
117119 verify(graphViewWrapper, never()).setHorizontalLabelsVisible(true )
118120 }
@@ -127,7 +129,7 @@ class DataManagerTest {
127129 val dataPoint = GraphDataPoint (xValue, MIN_Y + MIN_Y_OFFSET )
128130 whenever(graphViewWrapper.differenceSeries(wiFiDetails)).thenReturn(difference)
129131 // execute
130- fixture.adjustData(graphViewWrapper, wiFiDetails)
132+ fixture.adjustData(graphViewWrapper, wiFiDetails, truePredicate )
131133 // validate
132134 difference.forEach {
133135 verify(graphViewWrapper).appendToSeries(
@@ -148,13 +150,52 @@ class DataManagerTest {
148150 val moreWiFiDetails: Set <WiFiDetail > = makeMoreWiFiDetails().toSet()
149151 whenever(timeGraphCache.active()).thenReturn(moreWiFiDetails)
150152 // execute
151- val actual = fixture.newSeries(wiFiDetails)
153+ val actual = fixture.newSeries(wiFiDetails, truePredicate )
152154 // validate
153155 assertThat(actual).containsAll(wiFiDetails)
154156 assertThat(actual).containsAll(moreWiFiDetails)
155157 verify(timeGraphCache).active()
156158 }
157159
160+ @Test
161+ fun newSeriesShouldNotIncludeActiveCacheEntriesNotInCurrentWiFiDetails () {
162+ // Expected: newSeries includes currentDetails and only those active cache
163+ // entries that satisfy the given predicate. Entries from timeGraphCache.active()
164+ // that do not match the predicate (e.g. filtered-out SSIDs) must be excluded.
165+ // setup
166+ val currentDetails: Set <WiFiDetail > = makeWiFiDetails().toSet()
167+ val staleEntries: Set <WiFiDetail > = makeMoreWiFiDetails().toSet()
168+ whenever(timeGraphCache.active()).thenReturn(staleEntries)
169+ // execute
170+ val actual = fixture.newSeries(currentDetails, falsePredicate)
171+ assertThat(actual).containsAll(currentDetails)
172+ assertThat(actual).doesNotContainAnyElementsOf(staleEntries)
173+ verify(timeGraphCache).active()
174+ }
175+
176+ @Test
177+ fun adjustDataShouldNotAppendToStaleCacheEntriesNotInCurrentDetails () {
178+ // Expected: adjustData only appends floor data points and increments the
179+ // TimeGraphCache counter for differenceSeries entries that satisfy the
180+ // given predicate. Entries that do not match must be left untouched.
181+ // setup
182+ val currentDetails: Set <WiFiDetail > = makeWiFiDetails().toSet()
183+ val staleEntry: WiFiDetail = makeWiFiDetail(" SSID4" )
184+ whenever(graphViewWrapper.differenceSeries(currentDetails))
185+ .thenReturn(listOf (staleEntry))
186+ // execute
187+ fixture.adjustData(graphViewWrapper, currentDetails, falsePredicate)
188+ verify(graphViewWrapper, never()).appendToSeries(
189+ eq(staleEntry),
190+ any(),
191+ any(),
192+ any(),
193+ )
194+ // validate: stale entries must NOT be added to the time graph cache
195+ verify(timeGraphCache, never()).add(staleEntry)
196+ verify(timeGraphCache).clear()
197+ }
198+
158199 @Test
159200 fun addDataToExistingSeries () {
160201 // setup
0 commit comments