diff --git a/app/src/test/kotlin/fr/free/nrw/commons/nearby/CheckboxTriStatesTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/nearby/CheckboxTriStatesTest.kt new file mode 100644 index 000000000..178a3202c --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/nearby/CheckboxTriStatesTest.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/test/kotlin/fr/free/nrw/commons/nearby/LabelTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/nearby/LabelTest.kt new file mode 100644 index 000000000..e66765ef6 --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/nearby/LabelTest.kt @@ -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)) + } + +}