Skip to content

Commit

Permalink
add tests for onZoom
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Jan 19, 2025
1 parent 0686a68 commit 56cef41
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.osmdroid.events.ScrollEvent
import org.osmdroid.events.ZoomEvent
import org.osmdroid.util.BoundingBox
import org.osmdroid.views.MapView
import org.robolectric.RobolectricTestRunner
Expand Down Expand Up @@ -107,6 +108,13 @@ class MainDataHandlerTest {
verify {handler.postDelayed(uut, 1000)}
}

@Test
fun onScrollWithoutEvent() {
val result = uut.onScroll(null)

assertThat(result).isFalse
}

@Test
fun reactOnScrollWithinDataArea() {
val mapView = mockk<OwnMapView>();
Expand Down Expand Up @@ -135,5 +143,47 @@ class MainDataHandlerTest {

assertThat(result).isTrue
}

@Test
fun reactOnZoomWithinDataArea() {
val mapView = mockk<OwnMapView>();
every { mapView.isAnimating } returns false
val boundingBox = BoundingBox(45.0, 15.0, 40.0, 10.0)
every { mapView.boundingBox } returns boundingBox
every { localData.update(boundingBox, false) } returns false
val event = ZoomEvent(mapView, 6.0)

val result = uut.onZoom(event)

assertThat(result).isFalse
}

@Test
fun reactOnZoomlLeavingDataArea() {
val mapView = mockk<OwnMapView>();
every { mapView.isAnimating } returns false
val boundingBox = BoundingBox(45.0, 15.0, 40.0, 10.0)
every { mapView.boundingBox } returns boundingBox
every { localData.update(boundingBox, false) } returns true
val event = ZoomEvent(mapView, 6.0)

val result = uut.onZoom(event)

assertThat(result).isTrue
}

@Test
fun reactOnZoomlUpdateGridSize() {
val mapView = mockk<OwnMapView>();
every { mapView.isAnimating } returns false
val boundingBox = BoundingBox(45.0, 15.0, 40.0, 10.0)
every { mapView.boundingBox } returns boundingBox
every { localData.update(boundingBox, false) } returns false
val event = ZoomEvent(mapView, 8.0)

val result = uut.onZoom(event)

assertThat(result).isTrue
}
}

0 comments on commit 56cef41

Please sign in to comment.