Skip to content

Commit e7f54a9

Browse files
Add more nearby tests (#3877)
* more nearby tests added * Add tests for Label class * Add checkbox test javadocs * Add javadocs for label
1 parent fb4af37 commit e7f54a9

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package fr.free.nrw.commons.nearby
2+
3+
import fr.free.nrw.commons.R
4+
import fr.free.nrw.commons.R.*
5+
import org.junit.Before
6+
import org.junit.Test
7+
8+
class LabelTest {
9+
private lateinit var label: Label
10+
11+
/**
12+
* initial setup
13+
*/
14+
@Before
15+
@Throws(Exception::class)
16+
fun setUp() {
17+
label = Label.fromText("Q44539")
18+
}
19+
20+
/**
21+
* test if a random label icon matches with intended one
22+
*/
23+
@Test
24+
fun testLabelIcon() {
25+
assert(label.icon.equals(R.drawable.round_icon_church))
26+
}
27+
28+
/**
29+
* test if label is not found in label set, unknown icon is used
30+
*/
31+
@Test
32+
fun testNullLabelIcon() {
33+
var nullLabel: Label = Label.fromText("a random text not exist in label texts")
34+
assert(nullLabel.icon.equals(R.drawable.round_icon_unknown))
35+
}
36+
37+
}

0 commit comments

Comments
 (0)