|
| 1 | +/** |
| 2 | + * |
| 3 | + */ |
| 4 | +package com.baeldung.string; |
| 5 | + |
| 6 | +import org.apache.commons.lang3.StringUtils; |
| 7 | +import org.junit.Assert; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author iaforek |
| 12 | + * |
| 13 | + */ |
| 14 | +public class RemoveLastCharTest { |
| 15 | + |
| 16 | + public static final String TEST_STRING = "abcdef"; |
| 17 | + public static final String NULL_STRING = null; |
| 18 | + public static final String EMPTY_STRING = ""; |
| 19 | + public static final String ONE_CHAR_STRING = "a"; |
| 20 | + public static final String WHITE_SPACE_AT_THE_END_STRING = "abc "; |
| 21 | + |
| 22 | + /** |
| 23 | + * Test method for {@link com.baeldung.string.RemoveLastChar#substring(java.lang.String)}. |
| 24 | + */ |
| 25 | + @Test |
| 26 | + public void givenTestString_substring_getStingWithoutLastChar() { |
| 27 | + Assert.assertEquals("abcde", RemoveLastChar.substring(TEST_STRING)); |
| 28 | + Assert.assertEquals("abcde", StringUtils.chop(TEST_STRING)); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void givenNullString_substring_getNullString() { |
| 33 | + Assert.assertEquals(NULL_STRING, RemoveLastChar.substring(NULL_STRING)); |
| 34 | + Assert.assertEquals(NULL_STRING, StringUtils.chop(NULL_STRING)); |
| 35 | + |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void givenEmptyString_substring_getEmptyString() { |
| 40 | + Assert.assertEquals(NULL_STRING, RemoveLastChar.substring(EMPTY_STRING)); |
| 41 | + Assert.assertEquals(NULL_STRING, StringUtils.chop(NULL_STRING)); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void givenOneCharString_substring_getEmptyString() { |
| 46 | + Assert.assertEquals(EMPTY_STRING, RemoveLastChar.substring(ONE_CHAR_STRING)); |
| 47 | + Assert.assertEquals(EMPTY_STRING, StringUtils.chop(ONE_CHAR_STRING)); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void givenStringWithWhiteSpaceAtTheEnd_substring_getStringWithoutWhiteSpaceAtTheEnd() { |
| 52 | + Assert.assertEquals("abc", RemoveLastChar.substring(WHITE_SPACE_AT_THE_END_STRING)); |
| 53 | + Assert.assertEquals("abc", StringUtils.chop(WHITE_SPACE_AT_THE_END_STRING)); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments