Slugify { @Deprecated public Slugify(boolean lowerCase) { this(); withLowerCase(lowerCase); } @Deprecated  Slugify(boolean lowerCase);  Slugify(); Slugify withCustomReplacement(final String from, final String to); Slugify withCustomReplacements(final Map<String, String> customReplacements); Slugify withUnderscoreSeparator(final boolean underscoreSeparator); Slugify withTransliterator(final boolean transliterator); Slugify withLowerCase(final boolean lowerCase); String slugify(final String text); Map<String, String> getCustomReplacements();  }
@Test public void shouldReturnSlugifiedString() { String string = "Hello world"; String result = new Slugify().slugify(string); assertEquals("hello-world", result); }
@Test public void shouldReplacePlusSignToSeparator() { String string = "\tHello+\tworld \r\t"; String result = new Slugify().slugify(string); assertEquals("hello-world", result); }
@Test public void shouldReturnEmptyStringIfNullGiven() { String string = null; String result = new Slugify().slugify(string); assertEquals("", result); }
@Test public void shouldNormalizeRepeatedHyphensToSingleHyphenWithHyphenSeparator() { String string = "a---b___c"; String result = new Slugify().slugify(string); assertEquals("a-b___c", result); }
@Test public void shouldReplaceSpacesWithSeparator() { String string = "Hello world "; String result = new Slugify().slugify(string); assertEquals("hello-world", result); }
@Test public void shouldTrimWhiteSpacesOtherThanSpace() { String string = "\tHello \tworld \r\t"; String result = new Slugify().slugify(string); assertEquals("hello-world", result); }
@Test public void shouldSlugifyAnyPrintableASCIICharacter() { String string = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; String result = new Slugify().slugify(string); assertEquals("0123456789-abcdefghijklmnopqrstuvwxyz-_-abcdefghijklmnopqrstuvwxyz", result); }
@Test public void shouldSlugifyExtendedASCIICharacters() { String string = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘”•–—˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæç" + "èéêëìíîïðñòóôõö÷øùúûüýþÿĄĆĘŁŃÓŚŹŻąćęłńóśźż"; String result = new Slugify().slugify(string); assertEquals("sz-tmszy-a-23-1o141234aaaaaeaaaeceeeeiiiinoooooeoeuuuueyssaaaaaeaaaeceeeeiiiinoooooeoeuuuueyyacelnoszzacelnoszz", result); }
@Test public void shouldSlugifyGreekCharacters() { String capital = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"; String small = "αβγδεζηθικλμνξοπρστυφχψω"; String tonosCapital = "ΆΈΉΊΌΎΏ"; String smallTonos = "άέήίόύώ"; String dialytika = "ΪΫϊϋΰΐ"; String result1 = new Slugify().slugify(capital); String result2 = new Slugify().slugify(small); String result3 = new Slugify().slugify(tonosCapital); String result4 = new Slugify().slugify(smallTonos); String result5 = new Slugify().slugify(dialytika); assertEquals("abgdezhthiklmnksoprstyfxpsw", result1); assertEquals("abgdezhthiklmnksoprstyfxpsw", result2); assertEquals("aehioyw", result3); assertEquals("aehioyw", result4); assertEquals("iyiuui", result5); }
@Test public void shouldUseBuiltInReplacements() { String string = "ÅÄÆÖØÜåäæöøüß"; String result = new Slugify().slugify(string); assertEquals("aaaeaeoeoeueaaaeaeoeoeuess", result); }
@Test public void shouldTransliterateCyrillicProperly() { String string = "Смысловые галлюцинации"; String result = new Slugify().slugify(string); assertEquals("smyslovye-gallyutsinatsii", result); }
@Test public void shouldTransliterateArabicProperly() { String string = "هذه هي اللغة العربية"; String result = new Slugify().slugify(string); assertEquals("hthh-hy-llgh-laarby", result); }
@Test public void shouldTransliteratePolishProperly() { String string = "Zażółć gęślą jaźń."; String result = new Slugify().slugify(string); assertEquals("zazolc-gesla-jazn", result); }