BAEL-838 Corrected Helper class and associated empty string test case. Added StringUtils.substing tests.
This commit is contained in:
parent
d889dba928
commit
124966a0f6
|
@ -10,7 +10,7 @@ package com.baeldung.string;
|
|||
public class RemoveLastChar {
|
||||
public static String substring (String s) {
|
||||
if (s == null || s.length() == 0) {
|
||||
return null;
|
||||
return s;
|
||||
} else {
|
||||
return (s.substring(0, s.length() - 1));
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public class RemoveLastCharTest {
|
|||
public void givenTestString_substring_getStingWithoutLastChar() {
|
||||
Assert.assertEquals("abcde", RemoveLastChar.substring(TEST_STRING));
|
||||
Assert.assertEquals("abcde", StringUtils.chop(TEST_STRING));
|
||||
Assert.assertEquals("abcde", StringUtils.substring(TEST_STRING, 0, TEST_STRING.length() - 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -37,20 +38,25 @@ public class RemoveLastCharTest {
|
|||
|
||||
@Test
|
||||
public void givenEmptyString_substring_getEmptyString() {
|
||||
Assert.assertEquals(NULL_STRING, RemoveLastChar.substring(EMPTY_STRING));
|
||||
Assert.assertEquals(NULL_STRING, StringUtils.chop(NULL_STRING));
|
||||
Assert.assertEquals(EMPTY_STRING, RemoveLastChar.substring(EMPTY_STRING));
|
||||
Assert.assertEquals(EMPTY_STRING, StringUtils.chop(EMPTY_STRING));
|
||||
Assert.assertEquals(EMPTY_STRING, StringUtils.substring(EMPTY_STRING, 0, EMPTY_STRING.length() - 1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenOneCharString_substring_getEmptyString() {
|
||||
Assert.assertEquals(EMPTY_STRING, RemoveLastChar.substring(ONE_CHAR_STRING));
|
||||
Assert.assertEquals(EMPTY_STRING, StringUtils.chop(ONE_CHAR_STRING));
|
||||
Assert.assertEquals(EMPTY_STRING, StringUtils.substring(ONE_CHAR_STRING, 0, ONE_CHAR_STRING.length() - 1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringWithWhiteSpaceAtTheEnd_substring_getStringWithoutWhiteSpaceAtTheEnd() {
|
||||
Assert.assertEquals("abc", RemoveLastChar.substring(WHITE_SPACE_AT_THE_END_STRING));
|
||||
Assert.assertEquals("abc", StringUtils.chop(WHITE_SPACE_AT_THE_END_STRING));
|
||||
Assert.assertEquals("abc", StringUtils.substring(WHITE_SPACE_AT_THE_END_STRING, 0, WHITE_SPACE_AT_THE_END_STRING.length() - 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue