Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/org/apache/maven/shared/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1108,11 +1108,13 @@ public static String rightPad(@NonNull String str, int size) {
* @param size size to pad to
* @param delim string to pad with
* @return right padded String
* @throws ArithmeticException if delim is the empty String
* @throws NullPointerException if str or delim is <code>null</code>
*/
@NonNull
public static String rightPad(@NonNull String str, int size, @NonNull String delim) {
if (delim.isEmpty()) {
return str;
}
size = (size - str.length()) / delim.length();
if (size > 0) {
str += repeat(delim, size);
Expand Down Expand Up @@ -1142,11 +1144,13 @@ public static String leftPad(@NonNull String str, int size) {
* @param size size to pad to
* @param delim string to pad with
* @return left padded String
* @throws ArithmeticException if delim is the empty string
* @throws NullPointerException if str or delim is null
*/
@NonNull
public static String leftPad(@NonNull String str, int size, @NonNull String delim) {
if (delim.isEmpty()) {
return str;
}
size = (size - str.length()) / delim.length();
if (size > 0) {
str = repeat(delim, size) + str;
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@ public void testLeftPad2() {
assertEquals("*****dings", StringUtils.leftPad("dings", 10, "*"));
}

@Test
public void testLeftPadEmptyDelim() {
assertEquals("dings", StringUtils.leftPad("dings", 10, ""));
}

@SuppressWarnings("ConstantValue")
@Test
public void testLowerCase() {
Expand Down Expand Up @@ -1268,6 +1273,11 @@ public void testRightPad2() {
assertEquals("dings+++++", StringUtils.rightPad("dings", 10, "+"));
}

@Test
public void testRightPadEmptyDelim() {
assertEquals("dings", StringUtils.rightPad("dings", 10, ""));
}

@Test
public void testSplit1NPE() {
assertThrows(NullPointerException.class, () -> StringUtils.split(null));
Expand Down
Loading