Commit 0a241e3a authored by Skylot's avatar Skylot

core tests: add custom string matchers

parent 37857e88
package jadx.tests.utils;
import org.hamcrest.core.SubstringMatcher;
public class CountString extends SubstringMatcher {
private final int count;
public CountString(int count, String substring) {
super(substring);
this.count = count;
}
@Override
protected boolean evalSubstringOf(String string) {
return this.count == countStr(string, substring);
}
@Override
protected String relationship() {
return "containing " + count + " occurrence of";
}
private static int countStr(String string, String substring) {
int cnt = 0;
int idx = 0;
while ((idx = string.indexOf(substring, idx)) != -1) {
idx++;
cnt++;
}
return cnt;
}
}
package jadx.tests.utils;
import org.hamcrest.Matcher;
public class JadxMatchers {
public static Matcher<String> countString(int count, String substring) {
return new CountString(count, substring);
}
public static Matcher<String> containsOne(String substring) {
return new CountString(1, substring);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment