diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java index ceb92b40ea..0fecaf160b 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/WrappedReportEntry.java @@ -174,21 +174,25 @@ String getReportSourceName() { } String getReportSourceName(String suffix) { - return isBlank(suffix) ? getReportSourceName() : getReportSourceName() + "(" + suffix + ")"; + return withReportNameSuffix(getReportSourceName(), suffix); } String getSourceName(String suffix) { - return isBlank(suffix) ? getSourceName() : getSourceName() + "(" + suffix + ")"; + return withReportNameSuffix(getSourceName(), suffix); } String getSourceQualifiedName(String suffix) { String qualifiedName = original.getSourceQualifiedName(); if (qualifiedName != null) { - return isBlank(suffix) ? qualifiedName : qualifiedName + "(" + suffix + ")"; + return withReportNameSuffix(qualifiedName, suffix); } - // Fall back to pre-existing behaviour: sourceText if set, else sourceName (with suffix) + // Fall back to the same source selected before qualified names were tracked. String sourceText = getSourceText(); - return sourceText != null ? sourceText : getSourceName(suffix); + return sourceText != null ? withReportNameSuffix(sourceText, suffix) : getSourceName(suffix); + } + + private static String withReportNameSuffix(String sourceName, String suffix) { + return isBlank(suffix) ? sourceName : sourceName + "(" + suffix + ")"; } String getReportName() { diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java index cd8cc60785..196892d1a9 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java @@ -74,6 +74,14 @@ public void testRegular() { assertEquals("surefire.testcase.JunitParamsTest", wr.getNameWithGroup()); } + @Test + public void sourceQualifiedNameFallsBackToSourceTextWithSuffix() { + ReportEntry reportEntry = new SimpleReportEntry( + NORMAL_RUN, 1L, "JunitParamsTest", "surefire.testcase.JunitParamsTest", "testSum", null); + WrappedReportEntry wr = new WrappedReportEntry(reportEntry, null, 1771085631L, 12, null, null); + assertEquals("surefire.testcase.JunitParamsTest(BDD)", wr.getSourceQualifiedName("BDD")); + } + @Test public void testDisplayNames() { ReportEntry reportEntry = new SimpleReportEntry( diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire3210ReportNameSuffixIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire3210ReportNameSuffixIT.java new file mode 100644 index 0000000000..641be4a890 --- /dev/null +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire3210ReportNameSuffixIT.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.surefire.its.jiras; + +import org.apache.maven.surefire.its.fixture.OutputValidator; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.apache.maven.surefire.its.fixture.TestFile; +import org.junit.jupiter.api.Test; + +public class Surefire3210ReportNameSuffixIT extends SurefireJUnit4IntegrationTestCase { + @Test + public void reportNameSuffixIsUsedInTestcaseClassname() { + OutputValidator validator = + unpack("surefire-3210-report-name-suffix").executeTest().verifyErrorFree(1); + + TestFile reportFile = validator.getSurefireReportsXmlFile("TEST-jira3210.MonkeyTest-Linux.xml"); + reportFile + .assertContainsText("name=\"jira3210.MonkeyTest(Linux)\"") + .assertContainsText(" + + + + 4.0.0 + + org.apache.maven.plugins.surefire + surefire-3210-report-name-suffix + 1.0 + Test for SUREFIRE-3210: reportNameSuffix in XML report classname + + + 5.13.4 + 1.8 + 1.8 + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit5.version} + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + Linux + + + + + diff --git a/surefire-its/src/test/resources/surefire-3210-report-name-suffix/src/test/java/jira3210/MonkeyTest.java b/surefire-its/src/test/resources/surefire-3210-report-name-suffix/src/test/java/jira3210/MonkeyTest.java new file mode 100644 index 0000000000..7d881ed469 --- /dev/null +++ b/surefire-its/src/test/resources/surefire-3210-report-name-suffix/src/test/java/jira3210/MonkeyTest.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package jira3210; + +import org.junit.jupiter.api.Test; + +class MonkeyTest { + @Test + void testMonkeyConvert() {} +}