|
| 1 | +package org.apache.maven.surefire.its.jiras; |
| 2 | + |
| 3 | +/* |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | + * or more contributor license agreements. See the NOTICE file |
| 6 | + * distributed with this work for additional information |
| 7 | + * regarding copyright ownership. The ASF licenses this file |
| 8 | + * to you under the Apache License, Version 2.0 (the |
| 9 | + * "License"); you may not use this file except in compliance |
| 10 | + * with the License. You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, |
| 15 | + * software distributed under the License is distributed on an |
| 16 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | + * KIND, either express or implied. See the License for the |
| 18 | + * specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + */ |
| 21 | + |
| 22 | +import static java.nio.charset.StandardCharsets.UTF_8; |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; |
| 24 | +import static org.hamcrest.Matchers.matchesRegex; |
| 25 | + |
| 26 | +import java.util.Arrays; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +import org.apache.maven.surefire.its.fixture.OutputValidator; |
| 30 | +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +/** |
| 34 | + * Integration Test for SUREFIRE-2143 |
| 35 | + */ |
| 36 | +@SuppressWarnings( "checkstyle:magicnumber" ) |
| 37 | +public class Surefire2143ParameterizedSkippedIT extends SurefireJUnit4IntegrationTestCase |
| 38 | +{ |
| 39 | + @Test |
| 40 | + public void junit5ParameterizedSkipped() |
| 41 | + { |
| 42 | + OutputValidator validator = unpack( "surefire-2143-junit5-parameterized-test-skipped" ) |
| 43 | + .executeTest() |
| 44 | + .assertTestSuiteResults( 5, 0, 0, 2 ); |
| 45 | + |
| 46 | + String xmlReport = validator |
| 47 | + .getSurefireReportsFile( "TEST-jira2143.DisabledParameterizedTest.xml", UTF_8 ) |
| 48 | + .readFileToString(); |
| 49 | + |
| 50 | + List<String> testCaseResults = Arrays.asList( |
| 51 | + xmlReport.substring( xmlReport.indexOf( "<testcase " ), |
| 52 | + xmlReport.indexOf( "</testsuite>" ) ) |
| 53 | + .split( ".(?=<testcase )" ) ); |
| 54 | + |
| 55 | + assertThat( testCaseResults ) |
| 56 | + .hasSize( 5 ) |
| 57 | + .filteredOn( testCaseResult -> testCaseResult.contains( "<skipped" ) ) |
| 58 | + .map( testCaseResult -> testCaseResult.substring( 0, testCaseResult.indexOf( "classname" ) ) ) |
| 59 | + .containsExactlyInAnyOrder( |
| 60 | + "<testcase name=\"disabledParameterized(String)\" ", |
| 61 | + "<testcase name=\"disabledNonParameterized\" " ); |
| 62 | + |
| 63 | + validator.getSurefireReportsFile( "TEST-jira2143.DisabledParameterizedTest.xml", UTF_8 ) |
| 64 | + .assertContainsText( "<testcase name=\"disabledParameterized(String)\" " |
| 65 | + + "classname=\"jira2143.DisabledParameterizedTest\"" ) |
| 66 | + .assertContainsText( "<testcase name=\"disabledNonParameterized\" " |
| 67 | + + "classname=\"jira2143.DisabledParameterizedTest\"" ) |
| 68 | + .assertContainsText( matchesRegex( ".*<skipped [^>]*disabledParameterized.*" ) ) |
| 69 | + .assertContainsText( matchesRegex( ".*<skipped [^>]*disabledNonParameterized.*" ) ) |
| 70 | + .assertContainsText( "<testcase name=\"enabledParameterized(String)[1]\"" ) |
| 71 | + .assertContainsText( "<testcase name=\"enabledParameterized(String)[2]\"" ) |
| 72 | + .assertContainsText( "<testcase name=\"enabledNonParameterized\"" ) |
| 73 | + .assertNotContainsText( matchesRegex( ".*<skipped [^>]*enabledParameterized.*" ) ) |
| 74 | + .assertNotContainsText( matchesRegex( ".*<skipped [^>]*enabledNonParameterized.*" ) ); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void junit4ParameterizedSkipped() |
| 79 | + { |
| 80 | + OutputValidator validator = unpack( "surefire-2143-junit4-parameterized-test-skipped" ) |
| 81 | + .executeTest() |
| 82 | + .assertTestSuiteResults( 4, 0, 0, 2 ); |
| 83 | + |
| 84 | + String xmlReport = validator |
| 85 | + .getSurefireReportsFile( "TEST-jira2143.IgnoredParameterizedTest.xml", UTF_8 ) |
| 86 | + .readFileToString(); |
| 87 | + |
| 88 | + List<String> testCaseResults = Arrays.asList( |
| 89 | + xmlReport.substring( xmlReport.indexOf( "<testcase " ), |
| 90 | + xmlReport.indexOf( "</testsuite>" ) ) |
| 91 | + .split( ".(?=<testcase )" ) ); |
| 92 | + |
| 93 | + assertThat( testCaseResults ) |
| 94 | + .hasSize( 4 ) |
| 95 | + .filteredOn( testCaseResult -> testCaseResult.contains( "<skipped" ) ) |
| 96 | + .map( testCaseResult -> testCaseResult.substring( 0, testCaseResult.indexOf( "classname" ) ) ) |
| 97 | + .containsExactlyInAnyOrder( |
| 98 | + "<testcase name=\"ignoredParameterized[0]\" ", |
| 99 | + "<testcase name=\"ignoredParameterized[1]\" " ); |
| 100 | + } |
| 101 | + |
| 102 | +} |
0 commit comments