|
| 1 | +package com.stubbornjava.common; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +public class SlugsTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + public void testSimpleSlug() { |
| 11 | + String in = "2016-01-01 My Post"; |
| 12 | + String result = Slugs.toSlug(in); |
| 13 | + String expected = "2016-01-01-my-post"; |
| 14 | + assertEquals(expected, result); |
| 15 | + } |
| 16 | + |
| 17 | + @Test |
| 18 | + public void testSimpleSlugEndsWithoutSpecialChar() { |
| 19 | + String in = "2016-01-01 My Post?"; |
| 20 | + String result = Slugs.toSlug(in); |
| 21 | + String expected = "2016-01-01-my-post"; |
| 22 | + assertEquals(expected, result); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testMultiInvalidCharSlug() { |
| 27 | + String in = "2016-01-01-- &&^% My ++ Post"; |
| 28 | + String result = Slugs.toSlug(in); |
| 29 | + String expected = "2016-01-01-my-post"; |
| 30 | + assertEquals(expected, result); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testNullSlug() { |
| 35 | + String in = null; |
| 36 | + String result = Slugs.toSlug(in); |
| 37 | + String expected = null; |
| 38 | + assertEquals(expected, result); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testEmptySlug() { |
| 43 | + String in = ""; |
| 44 | + String result = Slugs.toSlug(in); |
| 45 | + String expected = ""; |
| 46 | + assertEquals(expected, result); |
| 47 | + } |
| 48 | +} |
0 commit comments