Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,22 @@ data class AnnotationDataFilter(val cnf: TestFilterConfiguration.AnnotationDataF
tests
}

private fun match(metaProperty: MetaProperty): Boolean {
return cnf.nameRegex.matches(metaProperty.name) && metaProperty.values.containsKey("value") && cnf.valueRegex.matches(metaProperty.values["value"].toString())
private fun match(metaProperty: MetaProperty) = cnf.nameRegex.matches(metaProperty.name) && metaProperty.matchesValueRegex()

private fun MetaProperty.matchesValueRegex() = when (val annotationData = this.values["value"]) {
null -> false

is Array<*> -> annotationData.map {
it.toString()
.substringAfter("(value=")
.substringBefore(")")
}
.any { cnf.valueRegex.matches(it) }

else -> cnf.valueRegex.matches(annotationData.toString())
}


override fun equals(other: Any?): Boolean {
if (other !is AnnotationDataFilter) return false
return (cnf.nameRegex.toString() + cnf.valueRegex.toString()).contentEquals((other.cnf.nameRegex.toString() + other.cnf.valueRegex.toString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class AnnotationDataFilterTest {
private val test5MetaProperty = MetaProperty("com.example.CorrectAnnotation", mapOf("testKey" to "testValue"))
private val test5 = stubTest(test5MetaProperty)

private val test6 =
stubTest(AnnotationDataWithArray("com.example.CorrectAnnotation", "CORRECT_VALUE", "INCORRECT_VALUE"))

private val test7 =
stubTest(AnnotationDataWithArray("com.example.CorrectAnnotation", AnnotationValue("CORRECT_VALUE"), AnnotationValue("INCORRECT_VALUE")))

@Test
fun shouldFilter() {
filter.filter(tests) shouldBeEqualTo listOf(test1, test2)
Expand All @@ -46,14 +52,55 @@ class AnnotationDataFilterTest {
fun shouldNotFailIfValueFieldIsNotExist() {
filter.filter(listOf(test5)) shouldBeEqualTo emptyList()
}

@Test
fun shouldFilterWithArrayString() {
filter2.filter(listOf(*tests.toTypedArray(), test6)) shouldBeEqualTo listOf(test6)
}

@Test
fun shouldFilterNotWithArrayString() {
filter2.filterNot(listOf(*tests.toTypedArray(), test6)) shouldBeEqualTo tests
}

@Test
fun shouldNotFailWithArrayAnotherType() {
filter2.filter(listOf(*tests.toTypedArray(), test7)) shouldBeEqualTo emptyList()
}
}

private class AnnotationData(
var name: String = "",
var value: String = ""
)

private class AnnotationDataWithArray<T>(
var name: String = "",
vararg var value: T
)

private class AnnotationValue(
var value: String = ""
)


private fun stubTest(vararg annotations: MetaProperty) = MarathonTest("com.sample", "SimpleTest", "fakeMethod", listOf(*annotations))
private fun stubTest(vararg annotations: AnnotationData) =
MarathonTest("com.sample", "SimpleTest", "fakeMethod", annotations.map { MetaProperty(it.name, mapOf("value" to it.value)) })
private fun stubTest(vararg annotations: MetaProperty) = MarathonTest(
pkg = "com.sample",
clazz = "SimpleTest",
method = "fakeMethod",
metaProperties = listOf(*annotations)
)

private fun stubTest(vararg annotations: AnnotationData) = MarathonTest(
pkg = "com.sample",
clazz = "SimpleTest",
method = "fakeMethod",
metaProperties = annotations.map { MetaProperty(it.name, mapOf("value" to it.value)) }
)

private fun <T> stubTest(vararg annotations: AnnotationDataWithArray<T>) = MarathonTest(
pkg = "com.sample",
clazz = "SimpleTest",
method = "fakeMethod",
metaProperties = annotations.map { MetaProperty(it.name, mapOf("value" to it.value)) }
)
Loading