cleaned up testing. removed a bunch of stuff that didn't return anything. I think i understand a bit better what people mean by "testable code"
This commit is contained in:
parent
e44a61958e
commit
a6b50d9e6b
@ -1,9 +1,12 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import org.mockito.Mockito.*
|
import org.mockito.Mockito.mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import params.MouseWiggleParams
|
||||||
import java.awt.Point
|
import java.awt.Point
|
||||||
import java.awt.event.InputEvent
|
import java.awt.event.InputEvent
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
|
||||||
class AutomatonTest {
|
class AutomatonTest {
|
||||||
@ -18,9 +21,26 @@ class AutomatonTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
fun `Automaton extends DesktopController`() {
|
fun `Automaton extends DesktopController`() {
|
||||||
|
|
||||||
val automaton = mock(Automaton::class.java)
|
val automaton = mock(Automaton::class.java)
|
||||||
verify(automaton).getAlmostPoint(Point(100, 100))
|
|
||||||
// Asserts Automaton extends DesktopController
|
|
||||||
|
// Given
|
||||||
|
val basePoint = Point(10, 10)
|
||||||
|
val wiggleParams = MouseWiggleParams(xWiggle = 5, yWiggle = 5)
|
||||||
|
|
||||||
|
|
||||||
|
// When
|
||||||
|
`when`(automaton.getAlmostPoint(basePoint, wiggleParams)).thenReturn(Point(12, 8))
|
||||||
|
|
||||||
|
val result = automaton.getAlmostPoint(basePoint, wiggleParams)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
assertTrue(result.x >= basePoint.x - wiggleParams.xWiggle)
|
||||||
|
assertTrue(result.x <= basePoint.x + wiggleParams.xWiggle)
|
||||||
|
|
||||||
|
assertTrue(result.y >= basePoint.y - wiggleParams.yWiggle)
|
||||||
|
assertTrue(result.y <= basePoint.y + wiggleParams.yWiggle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
package controllers
|
|
||||||
|
|
||||||
import org.mockito.Mockito.*
|
|
||||||
import org.mockito.ArgumentMatchers.*
|
|
||||||
import java.awt.Point
|
|
||||||
import kotlin.test.Test
|
|
||||||
|
|
||||||
class OrchestratorTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests scrollOutToHeight() calls expected methods on Automaton.
|
|
||||||
*
|
|
||||||
* Creates mock Orchestrator and Automaton instances.
|
|
||||||
* Mocks the orchestrator's automaton to return the mock Automaton.
|
|
||||||
* Calls scrollOutToHeight() on the orchestrator mock.
|
|
||||||
* Verifies sleep(), doLoop(), scrollIn(), and scrollOut() are called on
|
|
||||||
* the Automaton mock with expected arguments.
|
|
||||||
* This validates scrollOutToHeight() correctly delegates to Automaton.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun `scrollOutToHeight calls doLoop and scroll methods`() {
|
|
||||||
val orchestrator = mock(Orchestrator::class.java)
|
|
||||||
val automaton = mock(Automaton::class.java)
|
|
||||||
|
|
||||||
`when`(orchestrator.automaton).thenReturn(automaton)
|
|
||||||
|
|
||||||
orchestrator.scrollOutToHeight(10)
|
|
||||||
|
|
||||||
verify(automaton).sleep(anyLong())
|
|
||||||
verify(orchestrator).doLoop(anyInt(), anyInt(), any())
|
|
||||||
verify(automaton, times(2)).scrollIn(anyLong(), anyLong())
|
|
||||||
verify(automaton, times(10)).scrollOut(anyLong(), anyLong())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user