Add more nearby tests (#3877)

* more nearby tests added

* Add tests for Label class

* Add checkbox test javadocs

* Add javadocs for label
This commit is contained in:
neslihanturan 2020-08-05 18:06:03 +03:00 committed by GitHub
parent fb4af37418
commit e7f54a97e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 108 additions and 0 deletions

View file

@ -0,0 +1,71 @@
package fr.free.nrw.commons.nearby
import android.widget.CompoundButton
import androidx.test.core.app.ApplicationProvider
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.location.LatLng
import fr.free.nrw.commons.nearby.CheckBoxTriStates.CHECKED
import fr.free.nrw.commons.nearby.CheckBoxTriStates.UNCHECKED
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
class CheckBoxTriStatesTest {
@Mock
internal lateinit var callback: CheckBoxTriStates.Callback
@Mock
internal lateinit var onCheckChangeListener: CompoundButton.OnCheckedChangeListener
private lateinit var checkBoxTriStates: CheckBoxTriStates
/**
* initial setup
*/
@Before
@Throws(Exception::class)
fun setUp() {
MockitoAnnotations.initMocks(this)
checkBoxTriStates = CheckBoxTriStates(ApplicationProvider.getApplicationContext())
checkBoxTriStates.setCallback(callback)
checkBoxTriStates.setOnCheckedChangeListener(onCheckChangeListener)
}
/**
* If same state is trying to be set, nothing should happen
*/
@Test
fun testSetStateWhenSameState() {
checkBoxTriStates.state = CHECKED
checkBoxTriStates.setState(CHECKED)
verifyNoMoreInteractions(callback)
}
/**
* If different, markers should be filtered by new state
*/
@Test
fun testSetStateWhenDiffState() {
NearbyController.currentLocation = LatLng(0.0,0.0,0.0f)
checkBoxTriStates.state = CHECKED
checkBoxTriStates.setState(UNCHECKED)
verify(callback).filterByMarkerType(null, UNCHECKED, false, true)
}
/**
* If current latitude longtitude null, then no more interactions required
*/
@Test
fun testSetStateWhenCurrLatLngNull() {
NearbyController.currentLocation = null
checkBoxTriStates.state = CHECKED
checkBoxTriStates.setState(UNCHECKED)
verifyNoMoreInteractions(callback)
}
}

View file

@ -0,0 +1,37 @@
package fr.free.nrw.commons.nearby
import fr.free.nrw.commons.R
import fr.free.nrw.commons.R.*
import org.junit.Before
import org.junit.Test
class LabelTest {
private lateinit var label: Label
/**
* initial setup
*/
@Before
@Throws(Exception::class)
fun setUp() {
label = Label.fromText("Q44539")
}
/**
* test if a random label icon matches with intended one
*/
@Test
fun testLabelIcon() {
assert(label.icon.equals(R.drawable.round_icon_church))
}
/**
* test if label is not found in label set, unknown icon is used
*/
@Test
fun testNullLabelIcon() {
var nullLabel: Label = Label.fromText("a random text not exist in label texts")
assert(nullLabel.icon.equals(R.drawable.round_icon_unknown))
}
}