junit5: new assertions supported

This commit is contained in:
Anna Kozlova
2016-03-10 13:51:39 +01:00
parent 02cdec08bb
commit 7e4a697ea1
5 changed files with 26 additions and 5 deletions
+9
View File
@@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="opentest4j">
<CLASSES>
<root url="jar://$PROJECT_DIR$/plugins/junit5_rt/lib/opentest4j-1.0.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
+1
View File
@@ -267,6 +267,7 @@ libraryLicense(name: "NanoXML", version: "2.2.3", license: "zlib/libpng", url: "
libraryLicense(name: "nekohtml", libraryName: "nekohtml", version: "1.9.14", license: "Apache 2.0", url: "http://nekohtml.sourceforge.net/", licenseUrl: "http://apache.org/licenses/LICENSE-2.0.txt")
libraryLicense(name: "Netty", libraryName: "Netty", version: "4.1.0.Beta3", license: "Apache 2.0", url: "http://netty.io", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0")
libraryLicense(name: "Objenesis", libraryName: "objenesis-1.2.jar", version: "1.2", license: "Apache 2.0", url: "http://objenesis.org/", licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
libraryLicense(name: "opentest4j", libraryName: "opentest4j", version: "1.0.0", license: "Apache 2.0", url: "https://github.com/ota4j-team/opentest4j", licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
libraryLicense(name: "pep8.py", attachedTo: "python-helpers", version: "1.6.2", license: "MIT", url: "http://pep8.readthedocs.org/")
libraryLicense(name: "PicoContainer", libraryName: "picocontainer", version: "1.2", license: "BSD", url: "http://www.picocontainer.org/", licenseUrl: "http://docs.codehaus.org/display/PICO/License")
libraryLicense(name: "plexus-archiver", libraryName: "plexus-archiver-2.4.4.jar", version: "2.4.4", license: "Apache 2.0", url: "https://github.com/codehaus-plexus/plexus-archiver", licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
+1
View File
@@ -10,5 +10,6 @@
<orderEntry type="module" module-name="junit_rt" />
<orderEntry type="module" module-name="java-runtime" />
<orderEntry type="library" name="junit5_rt" level="project" />
<orderEntry type="library" name="opentest4j" level="project" />
</component>
</module>
Binary file not shown.
@@ -15,6 +15,7 @@
*/
package com.intellij.junit5;
import com.intellij.junit4.ExpectedPatterns;
import com.intellij.rt.execution.junit.ComparisonFailureData;
import com.intellij.rt.execution.junit.MapSerializerUtil;
import org.junit.gen5.engine.TestExecutionResult;
@@ -22,6 +23,7 @@ import org.junit.gen5.engine.support.descriptor.JavaSource;
import org.junit.gen5.launcher.TestExecutionListener;
import org.junit.gen5.launcher.TestIdentifier;
import org.junit.gen5.launcher.TestPlan;
import org.opentest4j.AssertionFailedError;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -116,7 +118,7 @@ public class JUnit5TestExecutionListener implements TestExecutionListener {
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
final String displayName = testIdentifier.getDisplayName();
final TestExecutionResult.Status status = testExecutionResult.getStatus();
final Optional<Throwable> throwableOptional = testExecutionResult.getThrowable();
final Throwable throwableOptional = testExecutionResult.getThrowable().orElse(null);
if (testIdentifier.isTest()) {
final long duration = System.currentTimeMillis() - myCurrentTestStart;
if (status == TestExecutionResult.Status.FAILED) {
@@ -155,7 +157,7 @@ public class JUnit5TestExecutionListener implements TestExecutionListener {
myPrintStream.println("\n##teamcity[testFinished" + idAndName(testIdentifier) + (duration > 0 ? "\' duration=\'" + Long.toString(duration) : "") + "\']");
}
private void testFailure(Optional<Throwable> failure, String messageName, TestIdentifier testIdentifier, long duration) {
private void testFailure(Throwable ex, String messageName, TestIdentifier testIdentifier, long duration) {
final Map<String, String> attrs = new HashMap<>();
attrs.put("name", testIdentifier.getDisplayName());
attrs.put("id", testIdentifier.getUniqueId().toString());
@@ -163,12 +165,20 @@ public class JUnit5TestExecutionListener implements TestExecutionListener {
attrs.put("duration", Long.toString(duration));
}
try {
if (failure.isPresent()) {
final Throwable ex = failure.get();
if (ex != null) {
final StringWriter stringWriter = new StringWriter();
final PrintWriter writer = new PrintWriter(stringWriter);
ex.printStackTrace(writer);
ComparisonFailureData.registerSMAttributes(null, stringWriter.toString(), ex.getMessage(), attrs, ex);
final ComparisonFailureData failureData;
if (ex instanceof AssertionFailedError && ((AssertionFailedError)ex).isActualDefined() && ((AssertionFailedError)ex).isExpectedDefined()) {
final Object actual = ((AssertionFailedError)ex).getActual();
final Object expected = ((AssertionFailedError)ex).getExpected();
failureData = new ComparisonFailureData(expected.toString(), actual.toString());
}
else {
failureData = ExpectedPatterns.createExceptionNotification(ex);
}
ComparisonFailureData.registerSMAttributes(failureData, stringWriter.toString(), ex.getMessage(), attrs, ex);
}
}
finally {