I mock ThirdPartyPluginLicenseStorageManager and PluginLicense.class using mockito in a junit test.
But while calling the internal methods of them it throws null pointer exception.
How can i overcome them as i dont see a way of setting the values in the mock confluence license objects
Few lines in my macro stub
@Mock
private ThirdPartyPluginLicenseStorageManager licenseManager;
@Before
public void setUp() throws Exception {
super.setUp();
exampleMacro = new Macro(licenseManager);
PluginLicense pluginLicense = Mockito.mock(PluginLicense.class);
}
@Test
public void test() throws Exception {
when(pluginLicense.getError().isDefined()).thenReturn(Boolean.FALSE); // Null pointer Exception
when(licenseManager.getLicense().isDefined()).thenReturn(Boolean.TRUE); // Null pointer Exception
}
Few lines in my macro code which are throwing null pointer exception
private final ThirdPartyPluginLicenseStorageManager licenseManager;
public Macro(ThirdPartyPluginLicenseStorageManager licenseManager){
this.licenseManager = licenseManager;
}
PluginLicense pluginLicense = licenseManager.getLicense().get();
if(licenseManager.getLicense().isDefined()) {
if(pluginLicense.getError().isDefined()) {
}
}