Skip to content

Commit 6f59154

Browse files
committed
Add missing tests
1 parent b533e9d commit 6f59154

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.nitri.opentopo.util
2+
3+
import androidx.preference.PreferenceManager
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import org.junit.Assert.assertEquals
7+
import org.junit.Before
8+
import org.junit.Test
9+
import org.junit.runner.RunWith
10+
import org.nitri.opentopo.defaultGpxTrackColor
11+
import org.nitri.opentopo.SettingsActivity
12+
import org.nitri.opentopo.ui.color.DEFAULT_GPX_TRACK_COLOR
13+
14+
@RunWith(AndroidJUnit4::class)
15+
class GpxPreferenceTest {
16+
17+
private val context = InstrumentationRegistry.getInstrumentation().targetContext
18+
19+
@Before
20+
fun setup() {
21+
PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit()
22+
}
23+
24+
@Test
25+
fun defaultGpxTrackColor_returnsDefaultWhenUnset() {
26+
assertEquals(DEFAULT_GPX_TRACK_COLOR, context.defaultGpxTrackColor())
27+
}
28+
29+
@Test
30+
fun defaultGpxTrackColor_returnsStoredValue() {
31+
val customColor = 0xFF654321.toInt()
32+
PreferenceManager.getDefaultSharedPreferences(context).edit()
33+
.putInt(SettingsActivity.PREF_GPX_TRACK_COLOR, customColor)
34+
.commit()
35+
36+
assertEquals(customColor, context.defaultGpxTrackColor())
37+
}
38+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.nitri.opentopo.ui.color
2+
3+
import org.junit.Assert.assertTrue
4+
import org.junit.Test
5+
6+
class PaletteTest {
7+
8+
@Test
9+
fun testPalette() {
10+
assertTrue("Default GPX color should be in the palette",
11+
APP_COLOR_PALETTE.contains(DEFAULT_GPX_TRACK_COLOR))
12+
13+
assertTrue("Legacy marker color should be in the palette",
14+
APP_COLOR_PALETTE.contains(DEFAULT_MARKER_COLOR))
15+
}
16+
}

0 commit comments

Comments
 (0)