diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.kt b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.kt index da52f45f..b5a2a091 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.kt +++ b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.kt @@ -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 diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.kt b/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.kt index f8c4d181..af666d0f 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.kt +++ b/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.kt @@ -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 { diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/color/StrikeColorHandlerTest.kt b/app/src/test/java/org/blitzortung/android/map/overlay/color/StrikeColorHandlerTest.kt new file mode 100644 index 00000000..730a6bdb --- /dev/null +++ b/app/src/test/java/org/blitzortung/android/map/overlay/color/StrikeColorHandlerTest.kt @@ -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()) + } +} \ No newline at end of file