Skip to content

Commit

Permalink
cosmetic: eliminate code warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jul 17, 2024
1 parent 0081786 commit 9979ccf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,41 +98,35 @@ 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;
}

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<NavigationPageItem> 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<NavigationPageItem> 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;
Expand Down Expand Up @@ -170,15 +164,12 @@ private List<NavigationPageItem> createChildItems(final Page parentPage, final I

private List<NavigationPageItem> 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;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void testGetMainNavigation() throws Exception {
}

@Test
void testGetMainNavigation_1Levels() throws Exception {
void testGetMainNavigation_1Levels() {
NavigationPageItem rootItem = underTest.getMainNavigation(1);
List<NavigationPageItem> mainnavItems = rootItem.getChildren();
assertEquals(5, mainnavItems.size());
Expand All @@ -84,7 +84,7 @@ void testGetMainNavigation_1Levels() throws Exception {
}

@Test
void testGetMainNavigation_0Levels() throws Exception {
void testGetMainNavigation_0Levels() {
NavigationPageItem rootItem = underTest.getMainNavigation(0);
List<NavigationPageItem> mainnavItems = rootItem.getChildren();
assertEquals(0, mainnavItems.size());
Expand All @@ -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<NavigationPageItem> footerNavItems = rootItem.getChildren();
assertEquals(3, footerNavItems.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 9979ccf

Please sign in to comment.