Skip to content

Commit 8b2bc18

Browse files
committed
Fix incorrect dependency declaration; add tests for pattern matcher
1 parent 722c9c5 commit 8b2bc18

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

test-app/build-tools/android-metadata-generator/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies {
5151

5252
testCompile 'junit:junit:4.13'
5353
testCompile 'org.mockito:mockito-core:3.0.0'
54-
implementation 'junit:junit:4.12'
54+
testImplementation 'junit:junit:4.12'
5555
}
5656

5757
task copyNecessaryFiles {

test-app/build-tools/android-metadata-generator/src/src/com/telerik/metadata/security/filtering/matching/impl/PatternMatcherImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class PatternMatcherImpl : PatternMatcher {
99
Algorithm is borrowed from: https://www.geeksforgeeks.org/wildcard-character-matching/
1010
*/
1111

12+
13+
// Short circuit if pattern is '*'
14+
if (pattern == "*" && input.isNotEmpty()) {
15+
return true
16+
}
17+
1218
// If we reach at the end of both strings,
1319
// we are done
1420
if (pattern.isEmpty() && input.isEmpty())
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.telerik.metadata.security.filtering.matching.impl
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Test
5+
import org.junit.runner.RunWith
6+
import org.junit.runners.Parameterized
7+
8+
9+
@RunWith(Parameterized::class)
10+
class PatternMatcherImplTest(private var pattern: String, private var input: String, private var shouldMatch: Boolean) {
11+
12+
private val matcher = PatternMatcherImpl()
13+
14+
companion object {
15+
@JvmStatic
16+
@Parameterized.Parameters(name = "Case {index}: matcher.match({0}, {1}) should be {2}")
17+
fun data(): Collection<Array<Any>> {
18+
return listOf(
19+
arrayOf("g*ks", "geeks", true),
20+
arrayOf("ge?ks*", "geeksforgeeks", true),
21+
arrayOf("g*k", "gee", false),
22+
arrayOf("*pqrs", "pqrst", false),
23+
arrayOf("abc*bcd", "abcdhghgbcd", true),
24+
arrayOf("abc*c?d", "abcd", false),
25+
arrayOf("*c*d", "abcd", true),
26+
arrayOf("*?c*d", "abcd", true)
27+
)
28+
}
29+
}
30+
31+
@Test
32+
fun `Test match`() {
33+
assertEquals("Wrong pattern matcher result!", shouldMatch, matcher.match(pattern, input))
34+
}
35+
}

0 commit comments

Comments
 (0)