@@ -6,7 +6,35 @@ import com.malinskiy.marathon.test.MetaProperty
6
6
class TestAnnotationParser {
7
7
fun extractAnnotations (event : TestEnded ): List <MetaProperty > {
8
8
val v2 = event.metrics[METRIC_ANNOTATION_V2 ]
9
+ val v3 = event.metrics[METRIC_ANNOTATION_V3 ]
9
10
return when {
11
+ v3 != null -> {
12
+ val removeSurrounding = v3.removeSurrounding(" [" , " ]" )
13
+ METRIC_ANNOTATION_V2_REGEX .findAll(removeSurrounding)
14
+ .map { it.value.trim() }
15
+ .filter { ! it.isNullOrEmpty() }
16
+ .toList().map { serializedAnnotation ->
17
+ val index = serializedAnnotation.indexOfFirst { it == ' (' }
18
+ val name = serializedAnnotation.substring(0 until index)
19
+ var serializedParameters = serializedAnnotation.substring(index).removeSurrounding(" (" , " )" )
20
+
21
+ val values = mutableListOf<Pair <String , String >>()
22
+ while (true ) {
23
+ val splitPoint = serializedParameters.indexOfFirst { it == ' L' }
24
+ if (splitPoint == - 1 ) break
25
+ val length = serializedParameters.substring(0 until splitPoint).toIntOrNull() ? : break
26
+ serializedParameters = serializedParameters.removeRange(0 .. splitPoint)
27
+ val parameter = serializedParameters.substring(0 until length)
28
+ serializedParameters = serializedParameters.removeRange(0 until length)
29
+ if (parameter.length > 1 && parameter.contains(" =" )) {
30
+ values.add(Pair (parameter.substringBefore(" =" ), parameter.substringAfter(" =" )))
31
+ }
32
+ }
33
+
34
+ MetaProperty (name = name, values = values.toMap())
35
+ }
36
+ }
37
+
10
38
v2 != null -> {
11
39
val removeSurrounding = v2.removeSurrounding(" [" , " ]" )
12
40
METRIC_ANNOTATION_V2_REGEX .findAll(removeSurrounding)
@@ -28,12 +56,14 @@ class TestAnnotationParser {
28
56
}
29
57
}
30
58
59
+
31
60
else -> emptyList()
32
61
}
33
62
}
34
63
35
64
companion object {
36
65
private const val METRIC_ANNOTATION_V2 = " com.malinskiy.adam.junit4.android.listener.TestAnnotationProducer.v2"
66
+ private const val METRIC_ANNOTATION_V3 = " com.malinskiy.adam.junit4.android.listener.TestAnnotationProducer.v3"
37
67
private val METRIC_ANNOTATION_V2_REGEX = " \\ p{Graph}+\\ ([^\\ )]*\\ )" .toRegex()
38
68
}
39
69
}
0 commit comments