View Javadoc
1   package org.apache.maven.surefire.junit4;
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 junit.framework.TestCase;
23  import org.apache.maven.surefire.booter.BaseProviderFactory;
24  import org.apache.maven.surefire.testset.TestRequest;
25  import org.junit.runner.Description;
26  
27  import java.util.HashMap;
28  
29  import static java.util.Arrays.asList;
30  import static org.hamcrest.MatcherAssert.assertThat;
31  import static org.hamcrest.Matchers.*;
32  import static org.junit.runner.Description.createSuiteDescription;
33  
34  /**
35   * @author Kristian Rosenvold
36   */
37  public class JUnit4ProviderTest
38      extends TestCase
39  {
40      public void testCreateProvider()
41      {
42          assertNotNull( getJUnit4Provider() );
43      }
44  
45      private JUnit4Provider getJUnit4Provider()
46      {
47          BaseProviderFactory providerParameters = new BaseProviderFactory( null, true );
48          providerParameters.setProviderProperties( new HashMap<String, String>() );
49          providerParameters.setClassLoaders( getClass().getClassLoader() );
50          providerParameters.setTestRequest( new TestRequest( null, null, null ) );
51          return new JUnit4Provider( providerParameters );
52      }
53  
54      public void testShouldCreateDescription()
55      {
56          class A {
57          }
58  
59          class B {
60          }
61  
62          Description d = JUnit4Provider.createTestsDescription( asList( A.class, B.class ) );
63          assertThat( d, is( notNullValue() ) );
64          assertThat( d.getDisplayName(), not( isEmptyOrNullString() ) );
65          assertThat( d.getDisplayName(), is( "null" ) );
66          assertThat( d.getChildren(), hasSize( 2 ) );
67          Description a = createSuiteDescription( A.class );
68          Description b = createSuiteDescription( B.class );
69          assertThat( d.getChildren(), contains( a, b ) );
70      }
71  
72  }