blob: 2c46e91af11df4b09daf9ddae7115c4dac1d9de4 [file] [log] [blame]
package com.android.example.text.styling.renderer.spans
import junit.framework.Assert.assertEquals
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import android.graphics.Typeface
import android.text.TextPaint
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentCaptor
/**
* Tests for the [FontSpan] class.
*/
class FontSpanTest {
private val paint = mock(TextPaint::class.java)
private val span = FontSpan(Typeface.DEFAULT)
private val defaultTypeface = Typeface.create("serif", Typeface.BOLD)
@Before fun setUp() {
`when`(paint.typeface).thenReturn(defaultTypeface)
}
@Test fun updateMeasureState() {
// When the update measure state is called
span.updateMeasureState(paint)
// Check that the typeface set has the correct typeface and style
val captor = ArgumentCaptor.forClass(Typeface::class.java)
verify(paint).typeface = captor.capture()
assertEquals(Typeface.BOLD, captor.value.style)
}
@Test fun updateDrawState() {
// When the update draw state is called
span.updateDrawState(paint)
// Check that the typeface set has the correct typeface and style
val captor = ArgumentCaptor.forClass(Typeface::class.java)
verify(paint).typeface = captor.capture()
assertEquals(Typeface.BOLD, captor.value.style)
}
}