1 package org.apache.maven.surefire.junitplatform;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.maven.surefire.testset.TestListResolver.toClassFileName;
23 import static org.junit.jupiter.api.Assertions.assertFalse;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27
28 import java.lang.reflect.Method;
29
30 import org.apache.maven.surefire.testset.TestListResolver;
31 import org.junit.Test;
32 import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
33 import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
34 import org.junit.platform.engine.ConfigurationParameters;
35 import org.junit.platform.engine.FilterResult;
36 import org.junit.platform.engine.UniqueId;
37
38
39
40
41
42
43 public class TestMethodFilterTest
44 {
45 private static final ConfigurationParameters CONFIG_PARAMS = mock(ConfigurationParameters.class);
46
47 private final TestListResolver resolver = mock( TestListResolver.class );
48
49 private final TestMethodFilter filter = new TestMethodFilter( this.resolver );
50
51 @Test
52 public void includesBasedOnTestListResolver()
53 throws Exception
54 {
55 when( resolver.shouldRun( toClassFileName( TestClass.class ), "testMethod" ) ).thenReturn( true );
56
57 FilterResult result = filter.apply( newTestMethodDescriptor() );
58
59 assertTrue( result.included() );
60 assertFalse( result.excluded() );
61 }
62
63 @Test
64 public void excludesBasedOnTestListResolver()
65 throws Exception
66 {
67 when( resolver.shouldRun( toClassFileName( TestClass.class ), "testMethod" ) ).thenReturn( false );
68
69 FilterResult result = filter.apply( newTestMethodDescriptor() );
70
71 assertFalse( result.included() );
72 assertTrue( result.excluded() );
73 }
74
75 @Test
76 public void includesTestDescriptorWithClassSource()
77 {
78 FilterResult result = filter.apply( newClassTestDescriptor() );
79
80 assertTrue( result.included() );
81 assertFalse( result.excluded() );
82 }
83
84 private static TestMethodTestDescriptor newTestMethodDescriptor()
85 throws Exception
86 {
87 UniqueId uniqueId = UniqueId.forEngine( "method" );
88 Class<TestClass> testClass = TestClass.class;
89 Method testMethod = testClass.getMethod( "testMethod" );
90 return new TestMethodTestDescriptor( uniqueId, testClass, testMethod );
91 }
92
93 private static ClassTestDescriptor newClassTestDescriptor()
94 {
95 UniqueId uniqueId = UniqueId.forEngine( "class" );
96 return new ClassTestDescriptor( uniqueId, TestClass.class, CONFIG_PARAMS );
97 }
98
99 public static class TestClass
100 {
101 public void testMethod()
102 {
103 }
104 }
105 }