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