From ded99f6ee494319c037217143407b345ec7f3a4e Mon Sep 17 00:00:00 2001 From: Saairam Venkatesh Date: Tue, 17 Oct 2023 23:48:26 -0500 Subject: [PATCH 1/3] Fixed flaky test --- .../models/v1/ClientLibrariesImplTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java index ac8d29f83d..55ac24880d 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java @@ -53,6 +53,7 @@ import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -456,12 +457,18 @@ void testGetCategoriesWithInjectedResourceTypesAndInheritance() { add("core/wcm/components/carousel/v3/carousel"); }}); ClientLibraries clientlibs = getClientLibrariesUnderTest(ROOT_PAGE, attributes); - StringBuilder includes = new StringBuilder(); - includes.append(jsIncludes.get(ACCORDION_CATEGORY)); - includes.append(jsIncludes.get(CAROUSEL_CATEGORY)); - includes.append(cssIncludes.get(ACCORDION_CATEGORY)); - includes.append(cssIncludes.get(CAROUSEL_CATEGORY)); - assertEquals(includes.toString(), clientlibs.getJsAndCssIncludes()); + String actual = clientlibs.getJsAndCssIncludes(); + StringBuilder includes1 = new StringBuilder(); + includes1.append(jsIncludes.get(ACCORDION_CATEGORY)); + includes1.append(jsIncludes.get(CAROUSEL_CATEGORY)); + includes1.append(cssIncludes.get(ACCORDION_CATEGORY)); + includes1.append(cssIncludes.get(CAROUSEL_CATEGORY)); + StringBuilder includes2 = new StringBuilder(); + includes2.append(jsIncludes.get(CAROUSEL_CATEGORY)); + includes2.append(jsIncludes.get(ACCORDION_CATEGORY)); + includes2.append(cssIncludes.get(CAROUSEL_CATEGORY)); + includes2.append(cssIncludes.get(ACCORDION_CATEGORY)); + assertTrue((includes1.toString().equals(actual)) || (includes2.toString().equals(actual))); } @Test From 40e76214aad449dc0b43b36c3660364f01f773bb Mon Sep 17 00:00:00 2001 From: Saairam Venkatesh Date: Tue, 31 Oct 2023 21:14:33 -0500 Subject: [PATCH 2/3] Changed HashSet to LinkedHashSet in ClientLibrariesImpl --- .../models/v1/ClientLibrariesImpl.java | 2 +- .../models/v1/ClientLibrariesImplTest.java | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java index 1f634572e4..a17780528f 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java @@ -297,7 +297,7 @@ private String getInline(LibraryType libraryType) { @NotNull protected Set getCategoriesFromComponents() { try (ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, COMPONENTS_SERVICE))) { - Set categories = new HashSet<>(); + Set categories = new LinkedHashSet<>(); for (ClientLibrary library : this.getAllClientLibraries(resourceResolver)) { for (String category : library.getCategories()) { if (pattern == null || pattern.matcher(category).matches()) { diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java index 55ac24880d..ac8d29f83d 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImplTest.java @@ -53,7 +53,6 @@ import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -457,18 +456,12 @@ void testGetCategoriesWithInjectedResourceTypesAndInheritance() { add("core/wcm/components/carousel/v3/carousel"); }}); ClientLibraries clientlibs = getClientLibrariesUnderTest(ROOT_PAGE, attributes); - String actual = clientlibs.getJsAndCssIncludes(); - StringBuilder includes1 = new StringBuilder(); - includes1.append(jsIncludes.get(ACCORDION_CATEGORY)); - includes1.append(jsIncludes.get(CAROUSEL_CATEGORY)); - includes1.append(cssIncludes.get(ACCORDION_CATEGORY)); - includes1.append(cssIncludes.get(CAROUSEL_CATEGORY)); - StringBuilder includes2 = new StringBuilder(); - includes2.append(jsIncludes.get(CAROUSEL_CATEGORY)); - includes2.append(jsIncludes.get(ACCORDION_CATEGORY)); - includes2.append(cssIncludes.get(CAROUSEL_CATEGORY)); - includes2.append(cssIncludes.get(ACCORDION_CATEGORY)); - assertTrue((includes1.toString().equals(actual)) || (includes2.toString().equals(actual))); + StringBuilder includes = new StringBuilder(); + includes.append(jsIncludes.get(ACCORDION_CATEGORY)); + includes.append(jsIncludes.get(CAROUSEL_CATEGORY)); + includes.append(cssIncludes.get(ACCORDION_CATEGORY)); + includes.append(cssIncludes.get(CAROUSEL_CATEGORY)); + assertEquals(includes.toString(), clientlibs.getJsAndCssIncludes()); } @Test From 7718d46edc49c55916521128338fde4fe46a6d61 Mon Sep 17 00:00:00 2001 From: Saairam Venkatesh Date: Sun, 12 Nov 2023 10:46:12 -0600 Subject: [PATCH 3/3] Removed unused import HashSet --- .../core/components/internal/models/v1/ClientLibrariesImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java index a17780528f..71feecd984 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map;