View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.its;
20  
21  import org.apache.maven.surefire.its.fixture.OutputValidator;
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  /**
27   * JUnit4 RunListener Integration Test.
28   *
29   * @author <a href="mailto:matthew.gilliard@gmail.com">Matthew Gilliard</a>
30   */
31  public class JUnit4RunListenerIT extends SurefireJUnit4IntegrationTestCase {
32      private SurefireLauncher unpack() {
33          return unpack("/junit4-runlistener");
34      }
35  
36      @Test
37      public void testJUnit4RunListener() {
38          final OutputValidator outputValidator = unpack().addGoal("-Dprovider=surefire-junit4")
39                  .setJUnitVersion("4.4")
40                  .executeTest()
41                  .verifyErrorFreeLog();
42          assertResults(outputValidator);
43          outputValidator.verifyTextInLog("testRunStarted null");
44          outputValidator.verifyTextInLog("testFinished simpleTest");
45          outputValidator.verifyTextInLog("testRunFinished org.junit.runner.Result");
46      }
47  
48      @Test
49      public void testRunlistenerJunitCoreProvider() {
50          final OutputValidator outputValidator = unpack().addGoal("-Dprovider=surefire-junit47")
51                  .setJUnitVersion("4.8.1")
52                  .addGoal("-DjunitVersion=4.8.1")
53                  .executeTest()
54                  .verifyErrorFreeLog(); // Todo: Fix junitVesion
55          assertResults(outputValidator);
56          outputValidator.verifyTextInLog("testRunStarted null");
57          outputValidator.verifyTextInLog("testFinished simpleTest");
58          outputValidator.verifyTextInLog("testRunFinished org.junit.runner.Result");
59      }
60  
61      private void assertResults(OutputValidator outputValidator) {
62          outputValidator.assertTestSuiteResults(1, 0, 0, 0);
63          outputValidator.getTargetFile("runlistener-output-1.txt").assertFileExists();
64          outputValidator.getTargetFile("runlistener-output-2.txt").assertFileExists();
65      }
66  }