I googled all I could think of for solutions, but phrasing is difficult.
I have a unit test that calls delete on a Spring Repository. The repo is defined as:
public interface FileConfigurationRepository extends CasenetRepository<FileConfiguration, String> {}
The method I'm testing has the following call:
fileConfigurationRepository.delete(GlobalConfiguration.CUSTOM_LOGO_ID);
Where GlobalConfiguration.CUSTOM_LOGO_ID is defined as:
public static final String CUSTOM_LOGO_ID = "customLogoId";
So I wrote my mock as follows:
Mockito.when(fileConfigurationRepository.delete(GlobalConfiguration.CUSTOM_LOGO_ID)).thenThrow(new Exception());
But then I get the following error:
The text of the error:
No instance(s) of type variable(s) T exist so that void conforms to T
Unsure how to proceed.
As indicated, the issue was really about the return being void and not about the parameter type being passed. According to How to make mock to void methods with Mockito, I changed the code as follows:
Mockito.doThrow(new RuntimeException()).when(fileConfigurationRepository).delete(GlobalConfiguration.CUSTOM_LOGO_ID);
And that fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With