BAEL-838 Refromatted code using formatter.xml. Added Assert.assertEquals import. Renamed test to follow convention. Reordered tests.
(cherry picked from commit d9d35f8
)
This commit is contained in:
parent
b29cb580a6
commit
c53095a3d7
|
@ -1,12 +1,5 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.string;
|
||||
|
||||
/**
|
||||
* @author iaforek
|
||||
*
|
||||
*/
|
||||
public class RemoveLastChar {
|
||||
public static String substring(String s) {
|
||||
if (s == null || s.length() == 0) {
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung.string;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author iaforek
|
||||
*
|
||||
*/
|
||||
public class RemoveLastCharTest {
|
||||
|
||||
public static final String TEST_STRING = "abcdef";
|
||||
|
@ -19,44 +13,37 @@ public class RemoveLastCharTest {
|
|||
public static final String ONE_CHAR_STRING = "a";
|
||||
public static final String WHITE_SPACE_AT_THE_END_STRING = "abc ";
|
||||
|
||||
/**
|
||||
* Test method for {@link com.baeldung.string.RemoveLastChar#substring(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
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));
|
||||
public void givenTestString_whenSubstring_thenGetStingWithoutLastChar() {
|
||||
assertEquals("abcde", RemoveLastChar.substring(TEST_STRING));
|
||||
assertEquals("abcde", StringUtils.substring(TEST_STRING, 0, TEST_STRING.length() - 1));
|
||||
assertEquals("abcde", StringUtils.chop(TEST_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNullString_substring_getNullString() {
|
||||
Assert.assertEquals(NULL_STRING, RemoveLastChar.substring(NULL_STRING));
|
||||
Assert.assertEquals(NULL_STRING, StringUtils.chop(NULL_STRING));
|
||||
|
||||
public void givenNullString_whenSubstring_thenGetNullString() {
|
||||
assertEquals(NULL_STRING, RemoveLastChar.substring(NULL_STRING));
|
||||
assertEquals(NULL_STRING, StringUtils.chop(NULL_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyString_substring_getEmptyString() {
|
||||
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));
|
||||
|
||||
public void givenEmptyString_whenSubstring_thenGetEmptyString() {
|
||||
assertEquals(EMPTY_STRING, RemoveLastChar.substring(EMPTY_STRING));
|
||||
assertEquals(EMPTY_STRING, StringUtils.substring(EMPTY_STRING, 0, EMPTY_STRING.length() - 1));
|
||||
assertEquals(EMPTY_STRING, StringUtils.chop(EMPTY_STRING));
|
||||
}
|
||||
|
||||
@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));
|
||||
|
||||
public void givenOneCharString_whenSubstring_thenGetEmptyString() {
|
||||
assertEquals(EMPTY_STRING, RemoveLastChar.substring(ONE_CHAR_STRING));
|
||||
assertEquals(EMPTY_STRING, StringUtils.substring(ONE_CHAR_STRING, 0, ONE_CHAR_STRING.length() - 1));
|
||||
assertEquals(EMPTY_STRING, StringUtils.chop(ONE_CHAR_STRING));
|
||||
}
|
||||
|
||||
@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));
|
||||
public void givenStringWithWhiteSpaceAtTheEnd_whenSubstring_thenGetStringWithoutWhiteSpaceAtTheEnd() {
|
||||
assertEquals("abc", RemoveLastChar.substring(WHITE_SPACE_AT_THE_END_STRING));
|
||||
assertEquals("abc", StringUtils.substring(WHITE_SPACE_AT_THE_END_STRING, 0, WHITE_SPACE_AT_THE_END_STRING.length() - 1));
|
||||
assertEquals("abc", StringUtils.chop(WHITE_SPACE_AT_THE_END_STRING));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue