Skip to content

Commit 63f1cf2

Browse files
committed
More unit test coverage
1 parent ec9ba8a commit 63f1cf2

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

app/src/test/java/com/jkuester/unlauncher/bindings/AnalogClockBindingsTest.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,46 @@ class AnalogClockBindingsTest {
400400
excludeRecords { canvas.rotate(any(), any(), any()) }
401401
excludeRecords { canvas.restoreToCount(any()) }
402402
}
403+
404+
@Test
405+
fun drawAnalogClock_withTickCountGreaterThan12_drawsMajorAndMinorTicks() {
406+
val paint = mockk<Paint>()
407+
val canvas = mockk<Canvas>()
408+
val calendar = mockk<Calendar>()
409+
mockkStatic(::getColorPaint)
410+
mockkStatic(Calendar::class)
411+
every { getColorPaint(context, R.attr.colorAccent) } returns paint
412+
every { Calendar.getInstance() } returns calendar
413+
every { calendar[Calendar.HOUR] } returns 10
414+
every { calendar[Calendar.MINUTE] } returns 30
415+
justRun { paint.style = any() }
416+
justRun { paint.strokeCap = any() }
417+
justRun { paint.strokeWidth = any() }
418+
justRun { canvas.drawLine(any(), any(), any(), any(), any()) }
419+
every { canvas.save() } returns 0
420+
justRun { canvas.rotate(any(), any(), any()) }
421+
justRun { canvas.restoreToCount(any()) }
422+
423+
val state = AnalogClockState(context)
424+
state.radius = 100F
425+
state.tickCount = 60
426+
427+
drawAnalogClock(state, canvas, 200, 200, 0)
428+
429+
verify(exactly = 1) { Calendar.getInstance() }
430+
verify(exactly = 1) { calendar[Calendar.HOUR] }
431+
verify(exactly = 1) { calendar[Calendar.MINUTE] }
432+
verify(atLeast = 1) { canvas.drawLine(any(), any(), any(), any(), any()) }
433+
verify(exactly = 1) { getColorPaint(context, R.attr.colorAccent) }
434+
verify(exactly = 1) { paint.style = Paint.Style.STROKE }
435+
verify(exactly = 1) { paint.strokeCap = Paint.Cap.ROUND }
436+
// Verify strokeWidth is set multiple times (for major ticks, minor ticks, and hands)
437+
verify(atLeast = 3) { paint.strokeWidth = any() }
438+
// Verify the tickWidthMin is used for minor ticks
439+
verify(exactly = 1) { paint.strokeWidth = state.tickWidthMin }
440+
// Exclude canvas rotation/save operations from verification
441+
excludeRecords { canvas.save() }
442+
excludeRecords { canvas.rotate(any(), any(), any()) }
443+
excludeRecords { canvas.restoreToCount(any()) }
444+
}
403445
}

0 commit comments

Comments
 (0)