I want to check whether a String contains a certain substring n times. I know I can do:
Assertions.assertThat(myString).contains("xyz");
Or even
Assertions.assertThat(myString).containsOnlyOnce("xyz");
But how can I ensure this for n times?
I tried something like:
Assertions.assertThat(myString).areExactly(n, myString.contains("xyz"));
but sadly this is not compilable.
Any ideas?
assertThat("aaa").areExactly(2, "aa")
? Is this true? – Loux"aa"
present 2 or 1 time in"aaa"
? That's why I said it was tricky. – Loux