How to ensure a string has a substring exactly n times?
You can have the regex like this which test String "myString" has SubString "xyz" n times.
Assertions.assertThat(myString).containsPattern("(xyz.*?){n}");
You can replace n with the count of substring you want to test.
You are probably looking for StringUtils.countMatches
Counts the number of occurrences of one String in another