1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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 }