This asserts that "xyz" occurrs n times anywhere in myString.
Matcher matcher = Pattern.compile("xyz").matcher(myString); assertThat(matcher.results().count()).isEqualTo(n);