[Build, IGS] Make the consent checker tests parameterized tests
This commit is contained in:
committed by
Space Team
parent
c7b2240c8e
commit
9dd4241a70
@@ -11,7 +11,11 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.kotlinx.serialization.json)
|
implementation(libs.kotlinx.serialization.json)
|
||||||
implementation(kotlin("test-junit5"))
|
testImplementation(kotlin("test-junit5"))
|
||||||
|
testImplementation(platform(libs.junit.bom))
|
||||||
|
testImplementation(libs.junit.jupiter.api)
|
||||||
|
testImplementation(libs.junit.jupiter.params)
|
||||||
|
testRuntimeOnly(libs.junit.jupiter.engine)
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin.jvmToolchain(8)
|
kotlin.jvmToolchain(8)
|
||||||
|
|||||||
+36
-46
@@ -6,17 +6,25 @@
|
|||||||
package org.jetbrains.kotlin.build
|
package org.jetbrains.kotlin.build
|
||||||
|
|
||||||
import org.apache.tools.ant.filters.StringInputStream
|
import org.apache.tools.ant.filters.StringInputStream
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.Named.named
|
||||||
import org.junit.jupiter.api.io.TempDir
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
import java.util.stream.Stream
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNull
|
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
data class ConsentConfiguration(
|
||||||
|
val globalConsent: Boolean?,
|
||||||
|
val localConsent: Boolean?,
|
||||||
|
val expected: Boolean?,
|
||||||
|
)
|
||||||
|
|
||||||
class ConsentManagerTest {
|
class ConsentManagerTest {
|
||||||
@TempDir
|
@TempDir
|
||||||
lateinit var workingDir: Path
|
lateinit var workingDir: Path
|
||||||
@@ -29,50 +37,17 @@ class ConsentManagerTest {
|
|||||||
LocalPropertiesModifier(localPropertiesFile.toFile())
|
LocalPropertiesModifier(localPropertiesFile.toFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest(name = "{0}")
|
||||||
@DisplayName("can check if there's no decision over the consent")
|
@MethodSource("getConfigurationsForParameterizedConsentCheckingTest")
|
||||||
fun testNoConsentRead() {
|
fun testConsentChecker(consentConfiguration: ConsentConfiguration) {
|
||||||
assertNull(ConsentManager(modifier).getUserDecision())
|
when (consentConfiguration.localConsent) {
|
||||||
}
|
true -> localPropertiesFile.toFile().writeText(USER_CONSENT_MARKER)
|
||||||
|
false -> localPropertiesFile.toFile().writeText(USER_REFUSAL_MARKER)
|
||||||
@Test
|
null -> {
|
||||||
@DisplayName("can check if there's agree to the consent")
|
// do nothing
|
||||||
fun testConsentAgreeRead() {
|
}
|
||||||
localPropertiesFile.toFile().writeText(USER_CONSENT_MARKER)
|
}
|
||||||
assertEquals(true, ConsentManager(modifier).getUserDecision())
|
assertEquals(consentConfiguration.expected, ConsentManager(modifier, consentConfiguration.globalConsent).getUserDecision())
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("can check if there's refusal to the consent")
|
|
||||||
fun testConsentRefusalRead() {
|
|
||||||
localPropertiesFile.toFile().writeText(USER_REFUSAL_MARKER)
|
|
||||||
assertEquals(false, ConsentManager(modifier).getUserDecision())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("if there's no local consent, but the global one is given")
|
|
||||||
fun testGlobalConsentGiven() {
|
|
||||||
assertEquals(true, ConsentManager(modifier, true).getUserDecision())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("if there's no local consent, but the global one is refused")
|
|
||||||
fun testGlobalConsentRefusal() {
|
|
||||||
assertEquals(false, ConsentManager(modifier, false).getUserDecision())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("local given consent takes priority over the global one")
|
|
||||||
fun testLocalGivenConsentTakesPriority() {
|
|
||||||
localPropertiesFile.toFile().writeText(USER_CONSENT_MARKER)
|
|
||||||
assertEquals(true, ConsentManager(modifier, false).getUserDecision())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("local refused consent takes priority over the global one")
|
|
||||||
fun testLocalRefusedConsentTakesPriority() {
|
|
||||||
localPropertiesFile.toFile().writeText(USER_REFUSAL_MARKER)
|
|
||||||
assertEquals(false, ConsentManager(modifier, true).getUserDecision())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -117,4 +92,19 @@ class ConsentManagerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
private fun getConfigurationsForParameterizedConsentCheckingTest() = Stream.of(
|
||||||
|
named("no decision is provided", ConsentConfiguration(null, null, null)),
|
||||||
|
named("local consent given with no global decision", ConsentConfiguration(null, true, true)),
|
||||||
|
named("local consent refused with no global decision", ConsentConfiguration(null, false, false)),
|
||||||
|
named("global consent refused with no local decision", ConsentConfiguration(false, null, false)),
|
||||||
|
named("local given consent takes priority over the global refused one", ConsentConfiguration(false, true, true)),
|
||||||
|
named("both local and global consents are refused", ConsentConfiguration(false, false, false)),
|
||||||
|
named("global consent refused with no local decision", ConsentConfiguration(true, null, true)),
|
||||||
|
named("both local and global consents are given", ConsentConfiguration(true, true, true)),
|
||||||
|
named("local refused consent takes priority over the global given one", ConsentConfiguration(true, false, false)),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user