Skip to content

Commit

Permalink
Fix bux where Strings.join returns empty String (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilson authored Jan 24, 2021
1 parent 636a825 commit 378e63e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2465: Fix bux where Strings.join returns empty String
Fixed: GITHUB-1632: throwing SkipException sets iTestResult status to Failure instead of Skip (Julien Herr & Krishnan Mahadevan)
New : GITHUB-2456: Add onDataProviderFailure listener (Krishnan Mahadevan)
Fixed: GITHUB-2445: NPE in FailedReporter.java With Tests Created in Factory (Arham Jain)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/testng/util/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static String join(String delimiter, String[] parts) {
for (int i = 0; i < parts.length - 1; i++) {
sb.append(parts[i]).append(delimiter);
}
if (parts.length > 1) {
if (parts.length > 0) {
sb.append(parts[parts.length - 1]);
}
return sb.toString();
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/testng/util/StringsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.testng.util;

import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

/**
* Unit tests for {@link Strings}
*/
public class StringsTest {
@Test
public void joinEmptyArray() {
String[] emptyArray = new String[0];
assertEquals(Strings.join(",", emptyArray), "");
}

@Test
public void joinArrayWithOneElement() {
String[] array = new String[]{"one"};
assertEquals(Strings.join(",", array), "one");
}

@Test
public void joinArrayWithTwoElements() {
String[] array = new String[]{"one", "two"};
assertEquals(Strings.join(",", array), "one,two");
}
}
1 change: 1 addition & 0 deletions src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@
<class name="org.testng.internal.UtilsTest" />
<class name="org.testng.internal.ClassHelperTest"/>
<class name="org.testng.internal.InstanceCreatorTest"/>
<class name="org.testng.util.StringsTest"/>
<class name="test.issue1430.TestFileToClass"/>
</classes>
</test>
Expand Down

0 comments on commit 378e63e

Please sign in to comment.