From ec7cb028007c03731b42d07937b5d5a77010bcc2 Mon Sep 17 00:00:00 2001 From: Shekhar Gulati Date: Tue, 19 Jul 2016 18:13:13 +0530 Subject: [PATCH] cleanup and added tests --- src/main/java/strman/Strman.java | 6 +++- src/test/java/strman/StrmanTest.java | 42 +++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/main/java/strman/Strman.java b/src/main/java/strman/Strman.java index fe5fad5..2327e5e 100644 --- a/src/main/java/strman/Strman.java +++ b/src/main/java/strman/Strman.java @@ -944,7 +944,11 @@ public abstract class Strman { */ public static String htmlEncode(final String html) { validate(html, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER); - return html.chars().mapToObj(c -> "\\u" + String.format("%04x", c).toUpperCase()).map(e -> HtmlEntities.encodedEntities.get(e)).collect(joining()); + return html + .chars() + .mapToObj(c -> "\\u" + String.format("%04x", c).toUpperCase()) + .map(HtmlEntities.encodedEntities::get) + .collect(joining()); } /** diff --git a/src/test/java/strman/StrmanTest.java b/src/test/java/strman/StrmanTest.java index be931e4..07ed4e0 100644 --- a/src/test/java/strman/StrmanTest.java +++ b/src/test/java/strman/StrmanTest.java @@ -26,6 +26,7 @@ package strman; +import org.junit.Ignore; import org.junit.Test; import java.util.Arrays; @@ -800,7 +801,8 @@ public class StrmanTest { " de_camelize" }; - Arrays.stream(fixture).forEach(el -> assertThat(String.format("toKebabCase(%s) should be de-camelize", el), toKebabCase(el), equalTo("de-camelize"))); + Arrays.stream(fixture).forEach(el -> + assertThat(String.format("toKebabCase(%s) should be de-camelize", el), toKebabCase(el), equalTo("de-camelize"))); } @Test @@ -845,4 +847,42 @@ public class StrmanTest { String result = removeRight("Remove the END at the end", " END", false); assertThat(result, is("Remove the END at the")); } + + @Test + public void transliterate_shouldDeburrTheString() throws Exception { + String result = transliterate("déjà vu"); + assertThat(result, is(equalTo("deja vu"))); + } + + @Ignore + public void htmlEncode_shouldConvertCharactersToTheirHtmlEntities() throws Exception { + String result = htmlEncode("fred, barney, & pebbles"); + assertThat(result, is(equalTo("fred, barney, & pebbles"))); + } + + @Ignore + public void kebabCase_shouldConvertAStringToKebabCase() throws Exception { + String[] input = { + "Foo Bar", + "fooBar", + "__FOO_BAR__" + }; + + Arrays.stream(input).forEach(el -> + assertThat(String.format("%s should be foo-bar", el), toKebabCase(el), is(equalTo("foo-bar")))); + + } + + @Ignore + public void snakeCase_shouldConvertAStringToSnakecase() throws Exception { + String[] input = { + "Foo Bar", + "fooBar", + "--FOO-BAR--" + }; + + Arrays.stream(input).forEach(el -> + assertThat(String.format("%s should be foo_bar", el), toSnakeCase(el), is(equalTo("foo_bar")))); + + } } \ No newline at end of file