1
+ package fr.free.nrw.commons.nearby
2
+
3
+ import android.widget.CompoundButton
4
+ import androidx.test.core.app.ApplicationProvider
5
+ import com.nhaarman.mockitokotlin2.verify
6
+ import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions
7
+ import fr.free.nrw.commons.TestCommonsApplication
8
+ import fr.free.nrw.commons.location.LatLng
9
+ import fr.free.nrw.commons.nearby.CheckBoxTriStates.CHECKED
10
+ import fr.free.nrw.commons.nearby.CheckBoxTriStates.UNCHECKED
11
+ import org.junit.Before
12
+ import org.junit.Test
13
+ import org.junit.runner.RunWith
14
+ import org.mockito.Mock
15
+ import org.mockito.MockitoAnnotations
16
+ import org.robolectric.RobolectricTestRunner
17
+ import org.robolectric.annotation.Config
18
+
19
+ @RunWith(RobolectricTestRunner ::class )
20
+ @Config(sdk = [21 ], application = TestCommonsApplication ::class )
21
+ class CheckBoxTriStatesTest {
22
+ @Mock
23
+ internal lateinit var callback: CheckBoxTriStates .Callback
24
+ @Mock
25
+ internal lateinit var onCheckChangeListener: CompoundButton .OnCheckedChangeListener
26
+ private lateinit var checkBoxTriStates: CheckBoxTriStates
27
+
28
+ /* *
29
+ * initial setup
30
+ */
31
+ @Before
32
+ @Throws(Exception ::class )
33
+ fun setUp () {
34
+ MockitoAnnotations .initMocks(this )
35
+ checkBoxTriStates = CheckBoxTriStates (ApplicationProvider .getApplicationContext())
36
+ checkBoxTriStates.setCallback(callback)
37
+ checkBoxTriStates.setOnCheckedChangeListener(onCheckChangeListener)
38
+ }
39
+
40
+ /* *
41
+ * If same state is trying to be set, nothing should happen
42
+ */
43
+ @Test
44
+ fun testSetStateWhenSameState () {
45
+ checkBoxTriStates.state = CHECKED
46
+ checkBoxTriStates.setState(CHECKED )
47
+ verifyNoMoreInteractions(callback)
48
+ }
49
+
50
+ /* *
51
+ * If different, markers should be filtered by new state
52
+ */
53
+ @Test
54
+ fun testSetStateWhenDiffState () {
55
+ NearbyController .currentLocation = LatLng (0.0 ,0.0 ,0.0f )
56
+ checkBoxTriStates.state = CHECKED
57
+ checkBoxTriStates.setState(UNCHECKED )
58
+ verify(callback).filterByMarkerType(null , UNCHECKED , false , true )
59
+ }
60
+
61
+ /* *
62
+ * If current latitude longtitude null, then no more interactions required
63
+ */
64
+ @Test
65
+ fun testSetStateWhenCurrLatLngNull () {
66
+ NearbyController .currentLocation = null
67
+ checkBoxTriStates.state = CHECKED
68
+ checkBoxTriStates.setState(UNCHECKED )
69
+ verifyNoMoreInteractions(callback)
70
+ }
71
+ }
0 commit comments