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 org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; 23 import org.apache.maven.surefire.its.fixture.SurefireLauncher; 24 import org.junit.Test; 25 26 @SuppressWarnings( { "javadoc", "checkstyle:javadoctype" } ) 27 /** 28 * 29 * In the surefire plugin, it is possible to specify one or more RunListener when running tests with JUnit. 30 * However, it does not look like the listener is properly called by the plugin. In particular, there is a problem 31 * with the method: 32 * <pre> 33 * public void testRunStarted(Description description) 34 * </pre> 35 * it's javadoc at 36 * <a href="http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html#testRunStarted%28org.junit.runner.Description%29"/> 37 * states: 38 * "Parameters: 39 * description - describes the tests to be run " 40 * however, in all maven projects I tried ("mvn test"), the surefire plugin seems like passing a null reference instead 41 * of a Description instance that "describes the tests to be run " 42 * Note: other methods in the RunListener I tested seems fine (i.e., they get a valid Description object as input) 43 * 44 * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a> 45 * @see <a href="https://issues.apache.org/jira/browse/SUREFIRE-1095}"/> 46 * @since 2.18 47 */ 48 public final class Surefire1095NpeInRunListener 49 extends SurefireJUnit4IntegrationTestCase 50 { 51 52 /** 53 * Method Request.classes( String, Class[] ); exists in JUnit 4.0 - 4.4 54 * See JUnit4Reflector. 55 */ 56 @Test 57 public void testRunStartedWithJUnit40() 58 { 59 unpack().setJUnitVersion( "4.0" ) 60 .executeTest() 61 .verifyErrorFree( 1 ) 62 .verifyTextInLog( "Running JUnit 4.0" ) 63 .verifyTextInLog( "testRunStarted [jiras.surefire1095.SomeTest]" ); 64 } 65 66 /** 67 * Method Request.classes( Class[] ); Since of JUnit 4.5 68 * See JUnit4Reflector. 69 */ 70 @Test 71 public void testRunStartedWithJUnit45() 72 { 73 unpack().setJUnitVersion( "4.5" ) 74 .executeTest() 75 .verifyErrorFree( 1 ) 76 .verifyTextInLog( "Running JUnit 4.5" ) 77 .verifyTextInLog( "testRunStarted [jiras.surefire1095.SomeTest]" ); 78 } 79 80 @Test 81 public void testRunStartedWithJUnit47() 82 { 83 unpack().setJUnitVersion( "4.7" ) 84 .executeTest() 85 .verifyErrorFree( 1 ) 86 .verifyTextInLog( "Running JUnit 4.7" ) 87 .verifyTextInLog( "testRunStarted [jiras.surefire1095.SomeTest]" ); 88 } 89 90 private SurefireLauncher unpack() 91 { 92 return unpack( "surefire-1095-npe-in-runlistener" ); 93 } 94 }