What’s the difference between Mockito Matchers isA, any, eq, and same?

any() checks absolutely nothing. Since Mockito 2.0, any(T.class) shares isA semantics to mean “any T” or properly “any instance of type T“. This is a change compared to Mockito 1.x, where any(T.class) checked absolutely nothing but saved a cast prior to Java 8: “Any kind object, not necessary of the given class. The class argument … Read more

PatternSyntaxException: Illegal Repetition when using regex in Java

The { and } are special in Java’s regex dialect (and most other dialects for that matter): they are the opening and closing tokens for the repetition quantifier {n,m} where n and m are integers. Hence the error message: “Illegal repetition”. You should escape them: “\\{\”user_id\” : [0-9]*\\}”. And since you seem to be trying … Read more

java regex pattern unclosed character class

Assuming that you want to match \ and – and not ]: Pattern pattern = Pattern.compile(“^[a-zA-Z\300-\3770-9\u0153\346 \u002F.’\\\\-]*$”); You need to double escape your backslashes, as \ is also an escape character in regex. Thus \\] escapes the backslash for java but not for regex. You need to add another java-escaped \ in order to regex-escape … Read more

How to extract parameters from a given url

It doesn’t have to be regex. Since I think there’s no standard method to handle this thing, I’m using something that I copied from somewhere (and perhaps modified a bit): public static Map<String, List<String>> getQueryParams(String url) { try { Map<String, List<String>> params = new HashMap<String, List<String>>(); String[] urlParts = url.split(“\\?”); if (urlParts.length > 1) { … Read more