diff --git a/app/build.gradle b/app/build.gradle
index b0662424f..59515810f 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -18,9 +18,7 @@ android {
minSdk 21
targetSdk 33
- buildFeatures {
- viewBinding true
- }
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
// ExoPlayer, AndroidX, and Material Components all need Java 8 to compile.
@@ -47,6 +45,10 @@ android {
}
}
+ buildFeatures {
+ viewBinding true
+ }
+
dependenciesInfo {
includeInApk = false
includeInBundle = false
@@ -110,8 +112,11 @@ dependencies {
// Locked below 1.7.0-alpha03 to avoid the same ripple bug
implementation "com.google.android.material:material:1.7.0-alpha02"
- // LeakCanary
+ // Development
debugImplementation "com.squareup.leakcanary:leakcanary-android:2.9.1"
+ testImplementation "junit:junit:4.13.2"
+ androidTestImplementation 'androidx.test.ext:junit:1.1.4'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
spotless {
diff --git a/app/src/androidTest/java/org/oxycblt/auxio/StubTest.kt b/app/src/androidTest/java/org/oxycblt/auxio/StubTest.kt
new file mode 100644
index 000000000..72626319e
--- /dev/null
+++ b/app/src/androidTest/java/org/oxycblt/auxio/StubTest.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2023 Auxio Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.oxycblt.auxio
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.junit.Assert.*
+import org.junit.runner.RunWith
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class StubTest {
+ // TODO: Add tests
+}
diff --git a/app/src/main/java/org/oxycblt/auxio/music/Date.kt b/app/src/main/java/org/oxycblt/auxio/music/Date.kt
index 2e05ef5a4..aa2783943 100644
--- a/app/src/main/java/org/oxycblt/auxio/music/Date.kt
+++ b/app/src/main/java/org/oxycblt/auxio/music/Date.kt
@@ -74,7 +74,7 @@ class Date private constructor(private val tokens: List) : Comparable
override fun hashCode() = tokens.hashCode()
- override fun equals(other: Any?) = other is Date && tokens == other.tokens
+ override fun equals(other: Any?) = other is Date && other.compareTo(this) == 0
override fun compareTo(other: Date): Int {
for (i in 0 until max(tokens.size, other.tokens.size)) {
diff --git a/app/src/test/java/org/oxycblt/auxio/music/DateTest.kt b/app/src/test/java/org/oxycblt/auxio/music/DateTest.kt
new file mode 100644
index 000000000..c0ae14f95
--- /dev/null
+++ b/app/src/test/java/org/oxycblt/auxio/music/DateTest.kt
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2023 Auxio Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.oxycblt.auxio.music
+
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class DateTest {
+ // TODO: Incomplete
+
+ @Test
+ fun date_fromYear() {
+ assertEquals(Date.from(2016).toString(), "2016")
+ }
+
+ @Test
+ fun date_fromDate() {
+ assertEquals(Date.from(2016, 8, 16).toString(), "2016-08-16")
+ }
+
+ @Test
+ fun date_fromDatetime() {
+ assertEquals(Date.from(2016, 8, 16, 0, 1).toString(), "2016-08-16T00:01Z")
+ }
+
+ @Test
+ fun date_fromFormalTimestamp() {
+ assertEquals(Date.from("2016-08-16T00:01:02").toString(), "2016-08-16T00:01:02Z")
+ }
+
+ @Test
+ fun date_fromSpacedTimestamp() {
+ assertEquals(Date.from("2016-08-16 00:01:02").toString(), "2016-08-16T00:01:02Z")
+ }
+
+ @Test
+ fun date_fromDatestamp() {
+ assertEquals(Date.from("2016-08-16").toString(), "2016-08-16")
+ }
+
+ @Test
+ fun date_fromWeirdDateTimestamp() {
+ assertEquals(Date.from("2016-08-16T00:01").toString(), "2016-08-16T00:01Z")
+ }
+
+ @Test
+ fun date_fromWeirdDatestamp() {
+ assertEquals(Date.from("2016-08").toString(), "2016-08")
+ }
+
+ @Test
+ fun date_fromYearStamp() {
+ assertEquals(Date.from("2016").toString(), "2016")
+ }
+
+ @Test
+ fun date_fromWackTimestamp() {
+ assertEquals(Date.from("2016-11-32 25:43:01").toString(), "2016-11")
+ }
+
+ @Test
+ fun date_fromWackYear() {
+ assertEquals(Date.from(0), null)
+ }
+}
diff --git a/app/src/test/java/org/oxycblt/auxio/music/parsing/ParsingUtilTest.kt b/app/src/test/java/org/oxycblt/auxio/music/parsing/ParsingUtilTest.kt
new file mode 100644
index 000000000..dd9b0de79
--- /dev/null
+++ b/app/src/test/java/org/oxycblt/auxio/music/parsing/ParsingUtilTest.kt
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2023 Auxio Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.oxycblt.auxio.music.parsing
+
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class ParsingUtilTest {
+ @Test
+ fun splitEscaped_correct() {
+ assertEquals("a,b,c".splitEscaped { it == ',' }, listOf("a", "b", "c"))
+ }
+
+ @Test
+ fun splitEscaped_escaped() {
+ assertEquals("a\\,b,c".splitEscaped { it == ',' }, listOf("a,b", "c"))
+ }
+
+ @Test
+ fun splitEscaped_whitespace() {
+ assertEquals("a , b, c , ".splitEscaped { it == ',' }, listOf("a ", " b", " c ", " "))
+ }
+
+ @Test
+ fun splitEscaped_escapedWhitespace() {
+ assertEquals("a \\, b, c , ".splitEscaped { it == ',' }, listOf("a , b", " c ", " "))
+ }
+
+ @Test
+ fun correctWhitespace_stringCorrect() {
+ assertEquals(
+ " asymptotic self-improvement ".correctWhitespace(), "asymptotic self-improvement")
+ }
+
+ @Test
+ fun correctWhitespace_stringOopsAllWhitespace() {
+ assertEquals(" ".correctWhitespace(), null)
+ }
+
+ @Test
+ fun correctWhitespace_listCorrect() {
+ assertEquals(
+ listOf(" asymptotic self-improvement ", " daemons never stop", "tcp phagocyte")
+ .correctWhitespace(),
+ listOf("asymptotic self-improvement", "daemons never stop", "tcp phagocyte"))
+ }
+
+ @Test
+ fun correctWhitespace_listOopsAllWhitespacE() {
+ assertEquals(
+ listOf(" ", "", " tcp phagocyte").correctWhitespace(), listOf("tcp phagocyte"))
+ }
+
+ @Test
+ fun parseId3v2Position_correct() {
+ assertEquals("16/32".parseId3v2Position(), 16)
+ }
+
+ @Test
+ fun parseId3v2Position_noTotal() {
+ assertEquals("16".parseId3v2Position(), 16)
+ }
+
+ @Test
+ fun parseId3v2Position_wack() {
+ assertEquals("16/".parseId3v2Position(), 16)
+ }
+}