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.TestArtifactInfo;
32 import org.apache.maven.surefire.testset.TestRequest;
33 import org.apache.maven.surefire.util.NestedRuntimeException;
34
35 import junit.framework.TestCase;
36
37
38
39
40 public class SurefireReflectorTest
41 extends TestCase
42 {
43 public void testSetDirectoryScannerParameters()
44 throws Exception
45 {
46 SurefireReflector surefireReflector = getReflector();
47 Object foo = getFoo();
48
49 DirectoryScannerParameters directoryScannerParameters =
50 new DirectoryScannerParameters( new File( "ABC" ), new ArrayList(), new ArrayList(), Boolean.FALSE,
51 "hourly" );
52 surefireReflector.setDirectoryScannerParameters( foo, directoryScannerParameters );
53 assertTrue( isCalled( foo ).booleanValue() );
54
55 }
56
57 public void testTestSuiteDefinition()
58 throws Exception
59 {
60 SurefireReflector surefireReflector = getReflector();
61 Object foo = getFoo();
62
63 TestRequest testSuiteDefinition =
64 new TestRequest( Arrays.asList( new File[]{ new File( "file1" ), new File( "file2" ) } ),
65 new File( "TestSOurce" ), "aUserRequestedTest", "aMethodRequested" );
66 surefireReflector.setTestSuiteDefinition( foo, testSuiteDefinition );
67 assertTrue( isCalled( foo ).booleanValue() );
68 }
69
70 public void testProviderProperties()
71 throws Exception
72 {
73 SurefireReflector surefireReflector = getReflector();
74 Object foo = getFoo();
75
76 surefireReflector.setProviderProperties( foo, new Properties() );
77 assertTrue( isCalled( foo ).booleanValue() );
78 }
79
80 public void testReporterConfiguration()
81 throws Exception
82 {
83 SurefireReflector surefireReflector = getReflector();
84 Object foo = getFoo();
85
86 ReporterConfiguration reporterConfiguration = getReporterConfiguration();
87 surefireReflector.setReporterConfigurationAware( foo, reporterConfiguration );
88 assertTrue( isCalled( foo ).booleanValue() );
89 }
90
91 private ReporterConfiguration getReporterConfiguration()
92 {
93 return new ReporterConfiguration( new File( "CDE" ), Boolean.TRUE );
94 }
95
96 public void testTestClassLoaderAware()
97 throws Exception
98 {
99 SurefireReflector surefireReflector = getReflector();
100 Object foo = getFoo();
101
102 surefireReflector.setTestClassLoader( foo, getClass().getClassLoader(), getClass().getClassLoader() );
103 assertTrue( isCalled( foo ).booleanValue() );
104 }
105
106 public void testArtifactInfoAware()
107 throws Exception
108 {
109 SurefireReflector surefireReflector = getReflector();
110 Object foo = getFoo();
111
112 TestArtifactInfo testArtifactInfo = new TestArtifactInfo( "12.3", "test" );
113 surefireReflector.setTestArtifactInfo( foo, testArtifactInfo );
114 assertTrue( isCalled( foo ).booleanValue() );
115 }
116
117 private SurefireReflector getReflector()
118 {
119 return new SurefireReflector( this.getClass().getClassLoader() );
120 }
121
122 public Object getFoo()
123 {
124 return new Foo();
125 }
126
127
128 private Boolean isCalled( Object foo )
129 {
130 final Method isCalled;
131 try
132 {
133 isCalled = foo.getClass().getMethod( "isCalled", new Class[0] );
134 return (Boolean) isCalled.invoke( foo, new Object[0] );
135 }
136 catch ( IllegalAccessException e )
137 {
138 throw new NestedRuntimeException( e );
139 }
140 catch ( InvocationTargetException e )
141 {
142 throw new NestedRuntimeException( e );
143 }
144 catch ( NoSuchMethodException e )
145 {
146 throw new NestedRuntimeException( e );
147 }
148 }
149
150
151 }