I have a class LocalizedCollatorProvider
public class LocalizedCollatorProvider {
private String language = "pl";
private String country = "PL";
public Collator getCollator() {
return Collator.getInstance(new Locale(language, country)):
}
}
I try to write a test of this class and I get an error Unnecessary stubbing detected in line
given(collatorProvider.getCollator()).willReturn(getInstance(new Locale("pl", "PL")));
collatorProvider is a mock of the above class LocalizedCollatorProvider
Mockito tries to help you to create clean tests. In strict mode it shall detect the unused stubs in test code.
In this case you mocked something but you didn't use that.
Recomennded solution - use that mock if you have already created
I will use Hungarian locale to demonstrate a simple comare method. The
ávowel is betweenaandb.In the previous example I called the mocked method and made an assertion. So I necessarily made a mock.
Workaround - bypass the error
If you really want to create an unnecessary mock, then you can bypass that using lenient stictness.