Junit for getting Configuration through Bundle Context
I am trying to write Junit using Junit5
@Mock
ProcessingComponentConfiguration config;
@Mock
FrameworkUtil framework;
@BeforeEach
void setup() {
MockitoAnnotations.initMocks(this);
}
@Mock
ConfigurationAdmin configAdmin;
@Mock
ProcessingContext context;
@Mock
BundleContext bundleContext;
@Mock
SlingHttpServletRequest request;
@2785667
void testInit() throws IOException {
Mockito.when(context.getRequest()).thenReturn(request);
Mockito.when( request.getServerName()).thenReturn("server");
Mockito.when(framework.getBundle(Test.class).getBundleContext()).thenReturn(bundleContext);
}
It is giving null pointer exception when I inspect framework.getBundle(Test.class).getBundleContext().
How to write Junit for this. Below is my code.
BundleContext bundleContext = FrameworkUtil.getBundle(Test.class).getBundleContext();
ServiceReference slingSettingRef = bundleContext.getServiceReference(SlingSettingsService.class.getName());
SlingSettingsService slingSetting = (SlingSettingsService) bundleContext.getService(slingSettingRef);
ServiceReference factoryRef = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
ConfigurationAdmin configAdmin = (ConfigurationAdmin) bundleContext.getService(factoryRef);