Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bux where Strings.join returns empty String #2465

Merged
merged 4 commits into from
Jan 24, 2021
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
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