View Javadoc
1   package org.apache.maven.plugin.surefire.report;
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.api.report.ReportEntry;
23  import org.junit.Test;
24  import org.junit.runner.RunWith;
25  import org.mockito.Mock;
26  import org.powermock.core.classloader.annotations.PowerMockIgnore;
27  import org.powermock.modules.junit4.PowerMockRunner;
28  
29  import static org.apache.maven.surefire.shared.utils.logging.MessageUtils.buffer;
30  import static org.fest.assertions.Assertions.assertThat;
31  import static org.mockito.Mockito.times;
32  import static org.mockito.Mockito.verify;
33  import static org.mockito.Mockito.verifyNoMoreInteractions;
34  import static org.mockito.Mockito.when;
35  
36  /**
37   * tests for {@link TestSetStats}.
38   */
39  @RunWith( PowerMockRunner.class )
40  @PowerMockIgnore( { "org.jacoco.agent.rt.*", "com.vladium.emma.rt.*" } )
41  public class TestSetStatsTest
42  {
43      @Mock
44      private ReportEntry reportEntry;
45  
46      @Test
47      public void shouldConcatenateWithTestGroup()
48      {
49          when( reportEntry.getNameWithGroup() )
50                  .thenReturn( "pkg.MyTest (my group)" );
51          String actual = TestSetStats.concatenateWithTestGroup( buffer(), reportEntry, false );
52          verify( reportEntry, times( 1 ) ).getNameWithGroup();
53          verifyNoMoreInteractions( reportEntry );
54          String expected = buffer().a( "pkg." ).strong( "MyTest (my group)" ).toString();
55          assertThat( actual )
56                  .isEqualTo( expected );
57      }
58  
59      @Test
60      public void shouldConcatenateWithJUnit5TestGroup()
61      {
62          when( reportEntry.getReportNameWithGroup() )
63                  .thenReturn( "pkg.MyTest (my group)" );
64          String actual = TestSetStats.concatenateWithTestGroup( buffer(), reportEntry, true );
65          verify( reportEntry, times( 1 ) ).getReportNameWithGroup();
66          verifyNoMoreInteractions( reportEntry );
67          String expected = buffer().strong( "pkg.MyTest (my group)" ).toString();
68          assertThat( actual )
69                  .isEqualTo( expected );
70      }
71  }