Merge branch 'master' into master
This commit is contained in:
commit
37da5f8854
@ -8,7 +8,7 @@ public class RemoveLastChar {
|
|||||||
return (s.substring(0, s.length() - 1));
|
return (s.substring(0, s.length() - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String chop(String s) {
|
public static String chop(String s) {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return s;
|
return s;
|
||||||
|
@ -2,7 +2,7 @@ package com.baeldung.stackoverflowerror;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class AccountHolderUnitTest {
|
public class AccountHolderManualTest {
|
||||||
@Test(expected = StackOverflowError.class)
|
@Test(expected = StackOverflowError.class)
|
||||||
public void whenInstanciatingAccountHolder_thenThrowsException() {
|
public void whenInstanciatingAccountHolder_thenThrowsException() {
|
||||||
AccountHolder holder = new AccountHolder();
|
AccountHolder holder = new AccountHolder();
|
@ -1,10 +1,9 @@
|
|||||||
package com.baeldung.stackoverflowerror;
|
package com.baeldung.stackoverflowerror;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CyclicDependancyUnitTest {
|
public class CyclicDependancyManualTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenInstanciatingClassOne_thenThrowsException() {
|
public void whenInstanciatingClassOne_thenThrowsException() {
|
||||||
try {
|
try {
|
@ -2,10 +2,9 @@ package com.baeldung.stackoverflowerror;
|
|||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class InfiniteRecursionWithTerminationConditionUnitTest {
|
public class InfiniteRecursionWithTerminationConditionManualTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenPositiveIntNoOne_whenCalcFact_thenThrowsException() {
|
public void givenPositiveIntNoOne_whenCalcFact_thenThrowsException() {
|
||||||
int numToCalcFactorial = 1;
|
int numToCalcFactorial = 1;
|
@ -1,29 +1,33 @@
|
|||||||
package com.baeldung.stackoverflowerror;
|
package com.baeldung.stackoverflowerror;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class UnintendedInfiniteRecursionUnitTest {
|
public class UnintendedInfiniteRecursionManualTest {
|
||||||
@Test(expected = StackOverflowError.class)
|
@Test(expected = StackOverflowError.class)
|
||||||
public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() {
|
public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() {
|
||||||
int numToCalcFactorial = 1;
|
int numToCalcFactorial= 1;
|
||||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
UnintendedInfiniteRecursion uir
|
||||||
|
= new UnintendedInfiniteRecursion();
|
||||||
|
|
||||||
uir.calculateFactorial(numToCalcFactorial);
|
uir.calculateFactorial(numToCalcFactorial);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = StackOverflowError.class)
|
@Test(expected = StackOverflowError.class)
|
||||||
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
||||||
int numToCalcFactorial = 2;
|
int numToCalcFactorial= 2;
|
||||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
UnintendedInfiniteRecursion uir
|
||||||
|
= new UnintendedInfiniteRecursion();
|
||||||
|
|
||||||
uir.calculateFactorial(numToCalcFactorial);
|
uir.calculateFactorial(numToCalcFactorial);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = StackOverflowError.class)
|
@Test(expected = StackOverflowError.class)
|
||||||
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
||||||
int numToCalcFactorial = -1;
|
int numToCalcFactorial= -1;
|
||||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
UnintendedInfiniteRecursion uir
|
||||||
|
= new UnintendedInfiniteRecursion();
|
||||||
|
|
||||||
uir.calculateFactorial(numToCalcFactorial);
|
uir.calculateFactorial(numToCalcFactorial);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ package com.baeldung.string;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -10,56 +10,84 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
public class CustomisedReports implements IReporter {
|
public class CustomisedReports implements IReporter {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(CustomisedReports.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(CustomisedReports.class);
|
||||||
|
|
||||||
|
private static final String ROW_TEMPLATE = "<tr class=\"%s\"><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>";
|
||||||
|
|
||||||
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
|
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
|
||||||
String reportTemplate = initReportTemplate();
|
String reportTemplate = initReportTemplate();
|
||||||
String resultRow = "<tr class=\"%s\"><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>";
|
|
||||||
StringBuilder rows = new StringBuilder();
|
|
||||||
suites.forEach(suite -> {
|
|
||||||
Map<String, ISuiteResult> suiteResults = suite.getResults();
|
|
||||||
suiteResults.forEach((testName, suiteResult) -> {
|
|
||||||
|
|
||||||
ITestContext testContext = suiteResult.getTestContext();
|
final String body = suites
|
||||||
|
.stream()
|
||||||
|
.flatMap(suiteToResults())
|
||||||
|
.collect(Collectors.joining());
|
||||||
|
|
||||||
Stream<ITestResult> failedTests = testContext.getFailedTests().getAllResults().stream();
|
saveReportTemplate(outputDirectory, reportTemplate.replaceFirst("</tbody>", String.format("%s</tbody>", body)));
|
||||||
Stream<ITestResult> passedTests = testContext.getPassedTests().getAllResults().stream();
|
|
||||||
Stream<ITestResult> skippedTests = testContext.getSkippedTests().getAllResults().stream();
|
|
||||||
|
|
||||||
String suiteName = suite.getName();
|
|
||||||
|
|
||||||
Stream<ITestResult> allTestResults = Stream.concat(Stream.concat(failedTests, passedTests), skippedTests);
|
|
||||||
generateReportRows(resultRow, rows, testName, suiteName, allTestResults);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
reportTemplate = reportTemplate.replaceFirst("</tbody>", rows.toString() + "</tbody>");
|
|
||||||
saveReportTemplate(outputDirectory, reportTemplate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateReportRows(String resultRow, StringBuilder rows, String testName, String suiteName, Stream<ITestResult> allTestResults) {
|
private Function<ISuite, Stream<? extends String>> suiteToResults() {
|
||||||
allTestResults
|
return suite -> suite.getResults().entrySet()
|
||||||
.forEach(testResult -> {
|
.stream()
|
||||||
String testReportRow = "";
|
.flatMap(resultsToRows(suite));
|
||||||
if (testResult.getStatus() == ITestResult.FAILURE) {
|
}
|
||||||
testReportRow = String.format(resultRow, "danger", suiteName, testName, testResult.getName(), "FAILED", "NA");
|
|
||||||
}
|
|
||||||
if (testResult.getStatus() == ITestResult.SUCCESS) {
|
|
||||||
testReportRow = String.format(resultRow, "success", suiteName, testName, testResult.getName(), "PASSED", String.valueOf(testResult.getEndMillis() - testResult.getStartMillis()));
|
|
||||||
|
|
||||||
|
private Function<Map.Entry<String, ISuiteResult>, Stream<? extends String>> resultsToRows(ISuite suite) {
|
||||||
|
return e -> {
|
||||||
|
ITestContext testContext = e.getValue().getTestContext();
|
||||||
|
|
||||||
|
Set<ITestResult> failedTests = testContext
|
||||||
|
.getFailedTests()
|
||||||
|
.getAllResults();
|
||||||
|
Set<ITestResult> passedTests = testContext
|
||||||
|
.getPassedTests()
|
||||||
|
.getAllResults();
|
||||||
|
Set<ITestResult> skippedTests = testContext
|
||||||
|
.getSkippedTests()
|
||||||
|
.getAllResults();
|
||||||
|
|
||||||
|
String suiteName = suite.getName();
|
||||||
|
|
||||||
|
return Stream
|
||||||
|
.of(failedTests, passedTests, skippedTests)
|
||||||
|
.flatMap(results -> generateReportRows(e.getKey(), suiteName, results).stream());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> generateReportRows(String testName, String suiteName, Set<ITestResult> allTestResults) {
|
||||||
|
return allTestResults.stream()
|
||||||
|
.map(testResultToResultRow(testName, suiteName))
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Function<ITestResult, String> testResultToResultRow(String testName, String suiteName) {
|
||||||
|
return testResult -> {
|
||||||
|
switch (testResult.getStatus()) {
|
||||||
|
case ITestResult.FAILURE:
|
||||||
|
return String.format(ROW_TEMPLATE, "danger", suiteName, testName, testResult.getName(), "FAILED", "NA");
|
||||||
|
|
||||||
|
case ITestResult.SUCCESS:
|
||||||
|
return String.format(ROW_TEMPLATE, "success", suiteName, testName, testResult.getName(), "PASSED", String.valueOf(testResult.getEndMillis() - testResult.getStartMillis()));
|
||||||
|
|
||||||
|
case ITestResult.SKIP:
|
||||||
|
return String.format(ROW_TEMPLATE, "warning", suiteName, testName, testResult.getName(), "SKIPPED", "NA");
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
if (testResult.getStatus() == ITestResult.SKIP) {
|
};
|
||||||
testReportRow = String.format(resultRow, "warning", suiteName, testName, testResult.getName(), "SKIPPED", "NA");
|
|
||||||
}
|
|
||||||
rows.append(testReportRow);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String initReportTemplate() {
|
private String initReportTemplate() {
|
||||||
String template = null;
|
String template = null;
|
||||||
byte[] reportTemplate = null;
|
byte[] reportTemplate;
|
||||||
try {
|
try {
|
||||||
reportTemplate = Files.readAllBytes(Paths.get("src/test/resources/reportTemplate.html"));
|
reportTemplate = Files.readAllBytes(Paths.get("src/test/resources/reportTemplate.html"));
|
||||||
template = new String(reportTemplate, "UTF-8");
|
template = new String(reportTemplate, "UTF-8");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user