diff --git a/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformation.java b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformation.java index c6dc8c39d..b11d46887 100644 --- a/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformation.java +++ b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformation.java @@ -18,7 +18,6 @@ import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; -import com.google.common.base.CaseFormat; import com.exadel.aem.toolkit.core.CoreConstants; @@ -93,9 +92,14 @@ private static String toCamelCase(String value) { if (StringUtils.isBlank(value)) { return value; } - return value.contains(CoreConstants.SEPARATOR_HYPHEN) - ? CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, value.toLowerCase().replace(CHAR_SPACE, CHAR_HYPHEN)) - : CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, value.toLowerCase().replace(CHAR_SPACE, CHAR_UNDERSCORE)); + String[] words = value.contains(CoreConstants.SEPARATOR_HYPHEN) + ? StringUtils.split(value, " -") + : StringUtils.split(value, " _"); + return words[0].toLowerCase() + Stream.of(words) + .skip(1) + .map(StringUtils::lowerCase) + .map(StringUtils::capitalize) + .collect(Collectors.joining()); } /** diff --git a/core/src/test/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformationTest.java b/core/src/test/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformationTest.java index 9c8999895..42009d6e3 100644 --- a/core/src/test/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformationTest.java +++ b/core/src/test/java/com/exadel/aem/toolkit/api/annotations/meta/StringTransformationTest.java @@ -13,11 +13,13 @@ */ package com.exadel.aem.toolkit.api.annotations.meta; +import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import org.junit.Test; public class StringTransformationTest { + private static final String SAMPLE0 = "LoReM"; private static final String SAMPLE1 = "L0rem IPSum! Do1or Sit Amet"; private static final String SAMPLE2 = "Lorem IPSum dolor-sit-Amet"; private static final String SAMPLE3 = "Lorem_IPSum__dolor_Sit_Amet"; @@ -34,6 +36,8 @@ public void shouldConvertToUpperCase() { @Test public void shouldConvertToCamelCase() { + Assert.assertEquals(StringUtils.EMPTY, StringTransformation.CAMELCASE.apply(StringUtils.EMPTY)); + Assert.assertEquals("lorem", StringTransformation.CAMELCASE.apply(SAMPLE0)); Assert.assertEquals("l0remIpsum!Do1orSitAmet", StringTransformation.CAMELCASE.apply(SAMPLE1)); Assert.assertEquals("loremIpsumDolorSitAmet", StringTransformation.CAMELCASE.apply(SAMPLE2)); Assert.assertEquals("loremIpsumDolorSitAmet", StringTransformation.CAMELCASE.apply(SAMPLE3)); @@ -41,6 +45,8 @@ public void shouldConvertToCamelCase() { @Test public void shouldCapitalize() { + Assert.assertEquals(StringUtils.EMPTY, StringTransformation.CAPITALIZE.apply(StringUtils.EMPTY)); + Assert.assertEquals("Lorem", StringTransformation.CAPITALIZE.apply(SAMPLE0)); Assert.assertEquals("L0rem Ipsum! Do1or Sit Amet", StringTransformation.CAPITALIZE.apply(SAMPLE1)); Assert.assertEquals("Lorem Ipsum Dolor Sit Amet", StringTransformation.CAPITALIZE.apply(SAMPLE2)); Assert.assertEquals("Lorem Ipsum Dolor Sit Amet", StringTransformation.CAPITALIZE.apply(SAMPLE3));