Skip to content

Commit

Permalink
add test for StrikeColorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Oct 13, 2024
1 parent 3dd5022 commit 6597cd8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class ColorHandler(private val preferences: SharedPreferences) {
val colors: IntArray
get() = getColors(target)

protected abstract fun getColors(target: ColorTarget): IntArray
abstract fun getColors(target: ColorTarget): IntArray

fun getColorSection(referenceTime: Long, eventTime: Long, intervalDuration: Int): Int {
val minutesPerColor = intervalDuration / colors.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ open class StrikeColorHandler(preferences: SharedPreferences) : ColorHandler(pre
}

private fun getCachedStreetmapStrikeColors(strikeColors: IntArray): IntArray {
if (!streetmapColors.containsKey(strikeColors)) {
streetmapColors[strikeColors] = modifyBrightness(strikeColors, 0.8f)
return streetmapColors[strikeColors] ?: run {
val newValue = modifyBrightness(strikeColors, 0.8f)
streetmapColors[strikeColors] = newValue
newValue
}
return streetmapColors[strikeColors]!!
}

override fun getTextColor(target: ColorTarget): Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.blitzortung.android.map.overlay.color

import android.content.Context
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE)
class StrikeColorHandlerTest {

lateinit var strikeColorHandler: StrikeColorHandler;

@Before
fun setUp() {
val context = RuntimeEnvironment.getApplication()
val preferences = context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE)

strikeColorHandler = StrikeColorHandler(preferences)

}

@Test
fun shouldReturnProperSatelliteColors() {
val colors = strikeColorHandler.getColors(ColorTarget.SATELLITE)

assertThat(colors).isEqualTo(ColorScheme.BLITZORTUNG.strikeColors)
}

@Test
fun shouldReturnProperSatelliteTextColor() {
val textColor = strikeColorHandler.getTextColor(ColorTarget.SATELLITE)

assertThat(textColor).isEqualTo(0xff000000.toInt())
}

@Test
fun shouldReturnProperStreetmapColors() {
val colors = strikeColorHandler.getColors(ColorTarget.STREETMAP)

assertThat(colors).containsExactly(
0xffcccccc.toInt(),
0xffcccc8d.toInt(),
0xffccb361.toInt(),
0xffcc8d4d.toInt(),
0xffc0664d.toInt(),
0xffb34040.toInt(),
)
}

@Test
fun shouldReturnProperStreetmapTextColor() {
val textColor = strikeColorHandler.getTextColor(ColorTarget.STREETMAP)

assertThat(textColor).isEqualTo(0xffffffff.toInt())
}
}

0 comments on commit 6597cd8

Please sign in to comment.