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