1 package org.apache.maven.surefire.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.io.File;
24 import java.lang.reflect.InvocationTargetException;
25 import java.lang.reflect.Method;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Properties;
29 import org.apache.maven.surefire.report.ReporterConfiguration;
30 import org.apache.maven.surefire.testset.DirectoryScannerParameters;
31 import org.apache.maven.surefire.testset.RunOrderParameters;
32 import org.apache.maven.surefire.testset.TestArtifactInfo;
33 import org.apache.maven.surefire.testset.TestRequest;
34 import org.apache.maven.surefire.util.NestedRuntimeException;
35 import org.apache.maven.surefire.util.RunOrder;
36
37 import junit.framework.TestCase;
38
39
40
41
42 public class SurefireReflectorTest
43 extends TestCase
44 {
45 public void testSetDirectoryScannerParameters()
46 throws Exception
47 {
48 SurefireReflector surefireReflector = getReflector();
49 Object foo = getFoo();
50
51 DirectoryScannerParameters directoryScannerParameters =
52 new DirectoryScannerParameters( new File( "ABC" ), new ArrayList(), new ArrayList(), new ArrayList(),
53 Boolean.FALSE, "hourly" );
54 surefireReflector.setDirectoryScannerParameters( foo, directoryScannerParameters );
55 assertTrue( isCalled( foo ) );
56
57 }
58
59 public void testRunOrderParameters()
60 throws Exception
61 {
62 SurefireReflector surefireReflector = getReflector();
63 Object foo = getFoo();
64
65 RunOrderParameters runOrderParameters = new RunOrderParameters( RunOrder.DEFAULT, new File( "." ) );
66 surefireReflector.setRunOrderParameters( foo, runOrderParameters );
67 assertTrue( isCalled( foo ) );
68
69 }
70
71 public void testTestSuiteDefinition()
72 throws Exception
73 {
74 SurefireReflector surefireReflector = getReflector();
75 Object foo = getFoo();
76
77 TestRequest testSuiteDefinition =
78 new TestRequest( Arrays.asList( new File( "file1" ), new File( "file2" ) ),
79 new File( "TestSOurce" ), "aUserRequestedTest", "aMethodRequested" );
80 surefireReflector.setTestSuiteDefinition( foo, testSuiteDefinition );
81 assertTrue( isCalled( foo ) );
82 }
83
84 public void testProviderProperties()
85 throws Exception
86 {
87 SurefireReflector surefireReflector = getReflector();
88 Object foo = getFoo();
89
90 surefireReflector.setProviderProperties( foo, new Properties() );
91 assertTrue( isCalled( foo ) );
92 }
93
94 public void testReporterConfiguration()
95 throws Exception
96 {
97 SurefireReflector surefireReflector = getReflector();
98 Object foo = getFoo();
99
100 ReporterConfiguration reporterConfiguration = getReporterConfiguration();
101 surefireReflector.setReporterConfigurationAware( foo, reporterConfiguration );
102 assertTrue( isCalled( foo ) );
103 }
104
105 private ReporterConfiguration getReporterConfiguration()
106 {
107 return new ReporterConfiguration( new File( "CDE" ), Boolean.TRUE );
108 }
109
110 public void testTestClassLoaderAware()
111 throws Exception
112 {
113 SurefireReflector surefireReflector = getReflector();
114 Object foo = getFoo();
115
116 surefireReflector.setTestClassLoader( foo, getClass().getClassLoader() );
117 assertTrue( isCalled( foo ) );
118 }
119
120 public void testArtifactInfoAware()
121 throws Exception
122 {
123 SurefireReflector surefireReflector = getReflector();
124 Object foo = getFoo();
125
126 TestArtifactInfo testArtifactInfo = new TestArtifactInfo( "12.3", "test" );
127 surefireReflector.setTestArtifactInfo( foo, testArtifactInfo );
128 assertTrue( isCalled( foo ) );
129 }
130
131 private SurefireReflector getReflector()
132 {
133 return new SurefireReflector( this.getClass().getClassLoader() );
134 }
135
136 public Object getFoo()
137 {
138 return new Foo();
139 }
140
141
142 private Boolean isCalled( Object foo )
143 {
144 final Method isCalled;
145 try
146 {
147 isCalled = foo.getClass().getMethod( "isCalled", new Class[0] );
148 return (Boolean) isCalled.invoke( foo );
149 }
150 catch ( IllegalAccessException e )
151 {
152 throw new NestedRuntimeException( e );
153 }
154 catch ( InvocationTargetException e )
155 {
156 throw new NestedRuntimeException( e );
157 }
158 catch ( NoSuchMethodException e )
159 {
160 throw new NestedRuntimeException( e );
161 }
162 }
163
164
165 }