Convert Javascript regular expression to Java syntax

Change the leading and trailing “https://stackoverflow.com/” characters to ‘”‘, and then replace each ‘\’ with “\\”. Unlike, JavaScript, Perl and other scripting languages, Java doesn’t have a special syntax for regexes. Instead, they are (typically) expressed using Java string literals. But ‘\’ is the escape character in a Java string literal, so each ‘\’ in … Read more

How to get a Jest custom matcher working in typescript?

The other question and answer you linked to were correct, and you can also find a very succinct example for how to extend jest in this github comment on react-testing-library. To implement their solution for your code, just change: declare global { namespace jest { interface MomentMatchers extends Matchers<moment.Moment> { toBeSameMoment: (expected: moment.Moment) => CustomMatcherResult; … Read more

Spring Security – Authorize Request for certain URL & HTTP-Method using HttpSecurity

Take a look here https://github.com/spring-projects/spring-data-examples/tree/master/rest/security which has http .httpBasic().and() .authorizeRequests() .antMatchers(HttpMethod.POST, “/employees”).hasRole(“ADMIN”) .antMatchers(HttpMethod.PUT, “/employees/**”).hasRole(“ADMIN”) .antMatchers(HttpMethod.PATCH, “/employees/**”).hasRole(“ADMIN”);

Why doesn’t this code attempting to use Hamcrest’s hasItems compile?

Just ran into this post trying to fix it for myself. Gave me just enough information to work it out. You can give the compiler just enough to persuade it to compile by casting the return value from hasItems to a (raw) Matcher, eg: ArrayList<Integer> actual = new ArrayList<Integer>(); ArrayList<Integer> expected = new ArrayList<Integer>(); actual.add(1); … Read more

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

When to use ** (double star) in glob syntax within JAVA

The javadoc for FileSystem#getPathMatcher() has some pretty good examples and explanations *.java Matches a path that represents a file name ending in .java *.* Matches file names containing a dot *.{java,class} Matches file names ending with .java or .class foo.? Matches file names starting with foo. and a single character extension /home/*/* Matches /home/gus/data on … Read more