Skip to content

Commit cebfdd7

Browse files
committed
test: setup :common:android for testing
Otherwise it's easy to forget to add it to androidModulesToUnitTest Assisted-by: Claude Opus 4.6 - tests
1 parent 15fe889 commit cebfdd7

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

AnkiDroid/jacoco.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ tasks.register('jacocoTestReport', JacocoReport) {
127127
}
128128

129129
// Android library modules (do not yet support flavors play/full)
130-
def androidModulesToUnitTest = [":libanki", ":compat"]
130+
def androidModulesToUnitTest = [":common:android", ":libanki", ":compat"]
131131
// JVM modules: use 'test' task and 'classes/kotlin/main' class dir
132132
def jvmModulesToUnitTest = [":common"]
133133

common/android/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ dependencies {
6060

6161
implementation(libs.androidx.annotation)
6262
implementation(libs.jakewharton.timber)
63+
64+
testImplementation(libs.kotlin.test)
65+
testImplementation(libs.junit.jupiter)
66+
testImplementation(libs.junit.vintage.engine)
67+
testImplementation(libs.robolectric)
68+
testImplementation(libs.androidx.test.junit)
6369
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2026 David Allison <davidallisongithub@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation; either version 3 of the License, or (at your option) any later
7+
* version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.ichi2.anki.common.utils.android
18+
19+
import android.graphics.Color
20+
import androidx.test.ext.junit.runners.AndroidJUnit4
21+
import org.junit.Test
22+
import org.junit.runner.RunWith
23+
import kotlin.test.assertEquals
24+
25+
/** Tests for [darkenColor] and [lightenColorAbsolute] */
26+
@RunWith(AndroidJUnit4::class)
27+
class ColorUtilsTest {
28+
@Test
29+
fun darkenColor_withNoChange_returnsSameColor() {
30+
val white = Color.WHITE
31+
assertEquals(white, darkenColor(white, factor = 1.0f))
32+
}
33+
34+
@Test
35+
fun darkenColor_withFullDarken_returnsBlack() {
36+
val white = Color.WHITE
37+
assertEquals(Color.BLACK, darkenColor(white, factor = 0.0f))
38+
}
39+
40+
@Test
41+
fun lightenColorAbsolute_withNoChange_returnsSameColor() {
42+
val red = Color.RED
43+
assertEquals(red, lightenColorAbsolute(red, amount = 0.0f))
44+
}
45+
}

0 commit comments

Comments
 (0)