testing: add unit test framework

Add junit/espresso alongside a few basic tests.

I am nowhere near close to being "done" with this at all.
This commit is contained in:
Alexander Capehart 2023-01-05 12:27:37 -07:00
parent a10cf1e0c3
commit 78e3739a68
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 205 additions and 5 deletions

View file

@ -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 {

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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
}

View file

@ -74,7 +74,7 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
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)) {

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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)
}
}

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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)
}
}