-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GITHUB- - Failsafe parameter.toString
- Loading branch information
1 parent
75698c2
commit acfac7a
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
testng-core/src/test/java/org/testng/reporters/TestHTMLReporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.testng.reporters; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.testng.ITestClass; | ||
import org.testng.ITestNGMethod; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.Test; | ||
import org.testng.internal.TestResult; | ||
|
||
public class TestHTMLReporterTest { | ||
|
||
@Test(description = "GITHUB-2830") | ||
public void generateTableParametersToStringShouldBeFailsafe() { | ||
ITestClass testClass = mock(ITestClass.class); | ||
when(testClass.getName()).thenReturn("testClass"); | ||
|
||
ITestNGMethod testNGMethod = mock(ITestNGMethod.class); | ||
when(testNGMethod.getMethodName()).thenReturn("testMethod"); | ||
when(testNGMethod.getTestClass()).thenReturn(testClass); | ||
|
||
TestResult testResult = TestResult.newEmptyTestResult(); | ||
testResult.setMethod(testNGMethod); | ||
|
||
testResult.setParameters(new Object[] {new ThrowingOnToString()}); | ||
|
||
List<ITestResult> tests = Collections.singletonList(testResult); | ||
|
||
StringWriter sw = new StringWriter(); | ||
PrintWriter pw = new PrintWriter(sw, true); | ||
TestHTMLReporter.generateTable(pw, "title", tests, "cssClass", (t1, t2) -> 0); | ||
|
||
assertThat(sw.toString()) | ||
.contains("Parameters: org.testng.reporters.TestHTMLReporterTest$ThrowingOnToString@"); | ||
} | ||
|
||
private static class ThrowingOnToString { | ||
@Override | ||
public String toString() { | ||
throw new IllegalStateException("Cannot calculate toString"); | ||
} | ||
} | ||
} |