Skip to content

Commit

Permalink
Implode - empty string bug - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
williamniemiec committed Feb 24, 2022
1 parent 771aa2e commit 4f233d5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
Binary file added dist/1.x/string-utils-1.1.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom-mavencentral.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.wniemiec-util-java</groupId>
<artifactId>string-utils</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<name>StringUtils</name>
<description>Contains methods that perform string manipulation.</description>
<url>https://github.com/wniemiec-util-java/string-utils</url>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>wniemiec.util.java</groupId>
<artifactId>string-utils</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<name>StringUtils</name>
<description>Contains methods that perform string manipulation.</description>
<url>https://github.com/wniemiec-util-java/string-utils</url>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/wniemiec/util/java/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static <T> String implode(List<T> list, String delimiter) {
response.append(delimiter);
}

removeLastCharacter(response);
if (!delimiter.isEmpty()) {
removeLastCharacter(response);
}

return response.toString();
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/wniemiec/util/java/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ void testHelloWorld() {

Assertions.assertEquals("hello world", obtained);
}

@Test
void testHelloWorldEmptyDelimiter() {
List<String> items = List.of("hello", "world");
String obtained = StringUtils.implode(items, "");

Assertions.assertEquals("helloworld", obtained);
}

@Test
void testNullList() {
Expand Down

0 comments on commit 4f233d5

Please sign in to comment.