From c657f96d2e5ee8c3ec1b08906d8db105eeb423f8 Mon Sep 17 00:00:00 2001 From: Igor Rogic Date: Tue, 10 Sep 2024 17:37:01 +0200 Subject: [PATCH] Add another unit test for Async execution --- .../AcToolStartupHookServiceImplTest.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/accesscontroltool-startuphook-bundle/src/test/java/biz/netcentric/cq/tools/actool/startuphook/impl/AcToolStartupHookServiceImplTest.java b/accesscontroltool-startuphook-bundle/src/test/java/biz/netcentric/cq/tools/actool/startuphook/impl/AcToolStartupHookServiceImplTest.java index 8b7714b1..7e260253 100644 --- a/accesscontroltool-startuphook-bundle/src/test/java/biz/netcentric/cq/tools/actool/startuphook/impl/AcToolStartupHookServiceImplTest.java +++ b/accesscontroltool-startuphook-bundle/src/test/java/biz/netcentric/cq/tools/actool/startuphook/impl/AcToolStartupHookServiceImplTest.java @@ -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 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 mockedFrameworkUtil = mockStatic(FrameworkUtil.class)) { + createAndActivateStartupHookService(mockedFrameworkUtil, true); + verify(installationService, times(1)).apply(null, new String[]{}, true); + } + } + + private void createAndActivateStartupHookService(MockedStatic 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); + } } \ No newline at end of file