|
package me.seebrock3r.utils |
|
|
|
import android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 |
|
import android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 |
|
import android.os.Build.VERSION_CODES.KITKAT |
|
import android.os.Build.VERSION_CODES.LOLLIPOP |
|
import android.os.Build.VERSION_CODES.LOLLIPOP_MR1 |
|
import android.os.Build.VERSION_CODES.M |
|
import android.os.Build.VERSION_CODES.N |
|
import org.assertj.core.api.Assertions.assertThat |
|
import org.junit.Test |
|
import org.junit.runner.RunWith |
|
import org.junit.runners.Parameterized |
|
|
|
// Notes: these are JVM Junit 4.12 tests. The assertions require AssertJ, or Truth. Pick your poison, just tweak the imports. |
|
|
|
@RunWith(Parameterized::class) |
|
class AndroidOSVersionCheckerTest(private val checker: OSVersionChecker, private val currentSdkVersion: Int) { |
|
|
|
companion object { |
|
|
|
@Parameterized.Parameters(name = "{index}: SDK_INT {1}") |
|
@JvmStatic |
|
fun data(): Collection<Array<Any>> { |
|
return listOf( |
|
arrayOf(AndroidOSVersionChecker(JELLY_BEAN_MR1), JELLY_BEAN_MR1), |
|
arrayOf(AndroidOSVersionChecker(JELLY_BEAN_MR2), JELLY_BEAN_MR2), |
|
arrayOf(AndroidOSVersionChecker(KITKAT), KITKAT), |
|
arrayOf(AndroidOSVersionChecker(LOLLIPOP), LOLLIPOP), |
|
arrayOf(AndroidOSVersionChecker(LOLLIPOP_MR1), LOLLIPOP_MR1), |
|
arrayOf(AndroidOSVersionChecker(M), M), |
|
arrayOf(AndroidOSVersionChecker(N), N), |
|
arrayOf(AndroidOSVersionChecker(N_MR1), N_MR1), |
|
arrayOf(AndroidOSVersionChecker(O), O) |
|
) |
|
} |
|
} |
|
|
|
@Test |
|
fun `should report correct SDK version`() { |
|
assertThat(checker.sdkVersion).isEqualTo(currentSdkVersion) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if Oreo or later`() { |
|
assertThat(checker.isAtLeastOreo).isEqualTo(currentSdkVersion >= O) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if NougatMR1 or later`() { |
|
assertThat(checker.isAtLeastNougatMR1).isEqualTo(currentSdkVersion >= N_MR1) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if Nougat or later`() { |
|
assertThat(checker.isAtLeastNougat).isEqualTo(currentSdkVersion >= N) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if Marshmallow or later`() { |
|
assertThat(checker.isAtLeastMarshmallow).isEqualTo(currentSdkVersion >= M) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if LollipopMR1 or later`() { |
|
assertThat(checker.isAtLeastLollipopMR1).isEqualTo(currentSdkVersion >= LOLLIPOP_MR1) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if Lollipop or later`() { |
|
assertThat(checker.isAtLeastLollipop).isEqualTo(currentSdkVersion >= LOLLIPOP) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if KitKat or later`() { |
|
assertThat(checker.isAtLeastKitKat).isEqualTo(currentSdkVersion >= KITKAT) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if JellyBeanMR2 or later`() { |
|
assertThat(checker.isAtLeastJellyBeanMR2).isEqualTo(currentSdkVersion >= JELLY_BEAN_MR2) |
|
} |
|
|
|
@Test |
|
fun `should detect correctly if JellyBeanMR1 or later`() { |
|
assertThat(checker.isAtLeastJellyBeanMR1).isEqualTo(currentSdkVersion >= JELLY_BEAN_MR1) |
|
} |
|
} |