diff --git a/bundles/core/src/main/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImpl.java b/bundles/core/src/main/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImpl.java index 1c7783c0..bbf2420e 100644 --- a/bundles/core/src/main/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImpl.java +++ b/bundles/core/src/main/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImpl.java @@ -98,17 +98,14 @@ public NavigationPageItem getFooterNavigation() { private NavigationPageItem getFooterNavigationSpecific(final Page footerNavRoot) { NavigationPageItem rootItem = createStructureItem(footerNavRoot); - rootItem.setChildren(createChildItems(footerNavRoot, new ItemCreator() { - @Override - public NavigationPageItem create(final Page pPage) { - NavigationPageItem columnItem = createStructureItem(pPage); - columnItem.setChildren(createChildItems(pPage, new ValidLinkableItemCreator())); - if (columnItem.getChildren().isEmpty()) { - return null; - } - else { - return columnItem; - } + rootItem.setChildren(createChildItems(footerNavRoot, page -> { + NavigationPageItem columnItem = createStructureItem(page); + columnItem.setChildren(createChildItems(page, new ValidLinkableItemCreator())); + if (columnItem.getChildren().isEmpty()) { + return null; + } + else { + return columnItem; } })); return rootItem; @@ -116,23 +113,20 @@ public NavigationPageItem create(final Page pPage) { private NavigationPageItem getFooterNavigationDerivedFromMainNav(final Page siteRootPage) { NavigationPageItem rootItem = createStructureItem(siteRootPage); - rootItem.setChildren(createChildItems(siteRootPage, new ItemCreator() { - @Override - public NavigationPageItem create(final Page pPage) { - NavigationPageItem columnItem = createStructureItem(pPage); - List linkItems = new ArrayList<>(); - NavigationPageItem mainnavLinkItem = createLinkableItem(pPage); - if (mainnavLinkItem.getLink().isValid()) { - linkItems.add(mainnavLinkItem); - } - linkItems.addAll(createChildItems(pPage, new ValidLinkableItemCreator())); - columnItem.setChildren(linkItems); - if (columnItem.getChildren().isEmpty()) { - return null; - } - else { - return columnItem; - } + rootItem.setChildren(createChildItems(siteRootPage, page -> { + NavigationPageItem columnItem = createStructureItem(page); + List linkItems = new ArrayList<>(); + NavigationPageItem mainnavLinkItem = createLinkableItem(page); + if (mainnavLinkItem.getLink().isValid()) { + linkItems.add(mainnavLinkItem); + } + linkItems.addAll(createChildItems(page, new ValidLinkableItemCreator())); + columnItem.setChildren(linkItems); + if (columnItem.getChildren().isEmpty()) { + return null; + } + else { + return columnItem; } })); return rootItem; @@ -170,15 +164,12 @@ private List createChildItems(final Page parentPage, final I private List createChildItemsRecursively(final Page parentPage, final ItemCreator itemCreator, final int level, final int maxLevels) { - return createChildItems(parentPage, new ItemCreator() { - @Override - public NavigationPageItem create(final Page pPage) { - NavigationPageItem item = itemCreator.create(pPage); - if (item != null && level < maxLevels) { - item.setChildren(createChildItemsRecursively(pPage, itemCreator, level + 1, maxLevels)); - } - return item; + return createChildItems(parentPage, page -> { + NavigationPageItem item = itemCreator.create(page); + if (item != null && level < maxLevels) { + item.setChildren(createChildItemsRecursively(page, itemCreator, level + 1, maxLevels)); } + return item; }); } diff --git a/bundles/core/src/test/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImplTest.java b/bundles/core/src/test/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImplTest.java index cdf2ec6c..f59bed9b 100644 --- a/bundles/core/src/test/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImplTest.java +++ b/bundles/core/src/test/java/io/wcm/samples/core/business/navigation/impl/NavigationManagerImplTest.java @@ -75,7 +75,7 @@ void testGetMainNavigation() throws Exception { } @Test - void testGetMainNavigation_1Levels() throws Exception { + void testGetMainNavigation_1Levels() { NavigationPageItem rootItem = underTest.getMainNavigation(1); List mainnavItems = rootItem.getChildren(); assertEquals(5, mainnavItems.size()); @@ -84,7 +84,7 @@ void testGetMainNavigation_1Levels() throws Exception { } @Test - void testGetMainNavigation_0Levels() throws Exception { + void testGetMainNavigation_0Levels() { NavigationPageItem rootItem = underTest.getMainNavigation(0); List mainnavItems = rootItem.getChildren(); assertEquals(0, mainnavItems.size()); @@ -94,7 +94,7 @@ void testGetMainNavigation_0Levels() throws Exception { * Test footer navigation with separate definition at tools/footernav/* */ @Test - void testGetFooterNavigation_ToolsFooterNav() throws Exception { + void testGetFooterNavigation_ToolsFooterNav() { NavigationPageItem rootItem = underTest.getFooterNavigation(); List footerNavItems = rootItem.getChildren(); assertEquals(3, footerNavItems.size()); diff --git a/bundles/core/src/test/java/io/wcm/samples/core/controller/common/PageTitleTest.java b/bundles/core/src/test/java/io/wcm/samples/core/controller/common/PageTitleTest.java index 87910221..86e09ca6 100644 --- a/bundles/core/src/test/java/io/wcm/samples/core/controller/common/PageTitleTest.java +++ b/bundles/core/src/test/java/io/wcm/samples/core/controller/common/PageTitleTest.java @@ -24,6 +24,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import io.wcm.samples.core.testcontext.AppAemContext; import io.wcm.testing.mock.aem.junit5.AemContext; @@ -34,36 +36,21 @@ class PageTitleTest { private final AemContext context = AppAemContext.newAemContext(); - @Test - void testGetRecursivePageTitle_Root() throws Exception { - context.currentPage("/content/wcm-io-samples/en"); - PageTitle underTest = context.request().adaptTo(PageTitle.class); - assertEquals("Handler Sample 2014", underTest.getRecursivePageTitle()); - } - - @Test - void testGetRecursivePageTitle_Conference() throws Exception { - context.currentPage("/content/wcm-io-samples/en/conference"); - PageTitle underTest = context.request().adaptTo(PageTitle.class); - assertEquals("Conference - Handler Sample 2014", underTest.getRecursivePageTitle()); - } - - @Test - void testGetRecursivePageTitle_Conference_CallForPapers() throws Exception { - context.currentPage("/content/wcm-io-samples/en/conference/call-for-papers"); - PageTitle underTest = context.request().adaptTo(PageTitle.class); - assertEquals("Call for Papers - Conference - Handler Sample 2014", underTest.getRecursivePageTitle()); - } - - @Test - void testGetRecursivePageTitle_Tools_Imprint() throws Exception { - context.currentPage("/content/wcm-io-samples/en/tools/navigation/imprint"); + @ParameterizedTest + @CsvSource({ + "/content/wcm-io-samples/en,Handler Sample 2014", + "/content/wcm-io-samples/en/conference,Conference - Handler Sample 2014", + "/content/wcm-io-samples/en/conference/call-for-papers,Call for Papers - Conference - Handler Sample 2014", + "/content/wcm-io-samples/en/tools/navigation/imprint,Imprint - Handler Sample 2014" + }) + void testGetRecursivePageTitle(String path, String expectedTitle) { + context.currentPage(path); PageTitle underTest = context.request().adaptTo(PageTitle.class); - assertEquals("Imprint - Handler Sample 2014", underTest.getRecursivePageTitle()); + assertEquals(expectedTitle, underTest.getRecursivePageTitle()); } @Test - void testGetSiteRootPageTitle() throws Exception { + void testGetSiteRootPageTitle() { PageTitle underTest = context.request().adaptTo(PageTitle.class); assertEquals("Handler Sample 2014", underTest.getSiteRootPageTitle()); } diff --git a/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/FooterNavPageLinkTest.java b/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/FooterNavPageLinkTest.java index fcf6d1e4..512463e7 100644 --- a/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/FooterNavPageLinkTest.java +++ b/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/FooterNavPageLinkTest.java @@ -41,13 +41,13 @@ class FooterNavPageLinkTest { private FooterNavPageLink underTest; @BeforeEach - void setUp() throws Exception { + void setUp() { when(navigationManager.getFooterNavigation()).thenReturn(navigationPageItem); underTest = new FooterNavPageLink(navigationManager); } @Test - void testGetRoot() throws Exception { + void testGetRoot() { assertSame(navigationPageItem, underTest.getRoot()); } diff --git a/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/MainNavPageLinkTest.java b/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/MainNavPageLinkTest.java index c6355290..14645924 100644 --- a/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/MainNavPageLinkTest.java +++ b/bundles/core/src/test/java/io/wcm/samples/core/controller/navigation/MainNavPageLinkTest.java @@ -43,12 +43,12 @@ class MainNavPageLinkTest { private MainNavPageLink underTest; @BeforeEach - void setUp() throws Exception { + void setUp() { when(navigationManager.getMainNavigation(anyInt())).thenReturn(navigationPageItem); } @Test - void testGetRoot() throws Exception { + void testGetRoot() { underTest = new MainNavPageLink(navigationManager, 5); verify(navigationManager).getMainNavigation(5); assertSame(navigationPageItem, underTest.getRoot()); diff --git a/bundles/core/src/test/java/io/wcm/samples/core/testcontext/AppAemContext.java b/bundles/core/src/test/java/io/wcm/samples/core/testcontext/AppAemContext.java index 22d81648..1ac36c60 100644 --- a/bundles/core/src/test/java/io/wcm/samples/core/testcontext/AppAemContext.java +++ b/bundles/core/src/test/java/io/wcm/samples/core/testcontext/AppAemContext.java @@ -27,8 +27,6 @@ import java.io.IOException; -import org.apache.sling.api.resource.PersistenceException; - import io.wcm.handler.media.spi.MediaFormatProvider; import io.wcm.samples.core.config.AppTemplate; import io.wcm.samples.core.config.impl.LinkHandlerConfigImpl; @@ -63,7 +61,7 @@ public static AemContext newAemContext() { */ private static final AemContextCallback SETUP_CALLBACK = new AemContextCallback() { @Override - public void execute(AemContext context) throws PersistenceException, IOException { + public void execute(AemContext context) throws IOException { // context path strategy MockCAConfig.contextPathStrategyRootTemplate(context, AppTemplate.EDITORIAL_HOMEPAGE.getTemplatePath());