Skip to content

Commit

Permalink
Add another unit test for Async execution
Browse files Browse the repository at this point in the history
  • Loading branch information
gicig committed Sep 10, 2024
1 parent 3f1999b commit c657f96
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,29 @@ void setup() throws RepositoryException {
when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
when(bundleContext.getBundle(anyLong())).thenReturn(bundle);
}

@Test
void testActivation() {
void testActivationSync() {
try (MockedStatic<FrameworkUtil> mockedFrameworkUtil = mockStatic(FrameworkUtil.class)) {
mockedFrameworkUtil.when(() -> FrameworkUtil.getBundle(RuntimeHelper.class)).thenReturn(bundle);
AcToolStartupHookServiceImpl startupHookService = new AcToolStartupHookServiceImpl();
startupHookService.repository = repository;
startupHookService.acInstallationService = installationService;
startupHookService.activate(bundleContext, config);
createAndActivateStartupHookService(mockedFrameworkUtil, false);
verify(installationService, times(1)).apply(null, new String[]{}, true);
}
}

@Test
void testActivationAsync() {
try (MockedStatic<FrameworkUtil> mockedFrameworkUtil = mockStatic(FrameworkUtil.class)) {
createAndActivateStartupHookService(mockedFrameworkUtil, true);
verify(installationService, times(1)).apply(null, new String[]{}, true);
}
}

private void createAndActivateStartupHookService(MockedStatic<FrameworkUtil> mockedFrameworkUtil, boolean runAsyncForMutableContent) {
mockedFrameworkUtil.when(() -> FrameworkUtil.getBundle(RuntimeHelper.class)).thenReturn(bundle);
AcToolStartupHookServiceImpl startupHookService = new AcToolStartupHookServiceImpl();
startupHookService.repository = repository;
startupHookService.acInstallationService = installationService;
when(config.runAsyncForMutableConent()).thenReturn(runAsyncForMutableContent);
startupHookService.activate(bundleContext, config);
}
}

0 comments on commit c657f96

Please sign in to comment.