I want to test a private method in a final utitlity class.
1. The class itself:
Class signature:
public final class SomeHelper {
private SomeHelper() {
}
And there is a method of its own:
private static String formatValue(BigDecimal value)
The test has already been written, but previously the method was in a non-useful non-finite class without a private constructor.
The test is already using @RunWith(Parameterized.class).
Now all I get is an exception:
org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class com.some.package.util.SomeHelper
Mockito cannot mock/spy following:
- final classes
- anonymous classes
- primitive types
2. Test
The most important line in this test:
String result = Whitebox.invokeMethod(mValue, "formatValue", mGiven);
Is there a way to do a test job?
source
share