1 package org.apache.maven.surefire.junitcore;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.junit.Test;
26
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertThat;
29 import static org.junit.Assert.assertTrue;
30 import static org.hamcrest.core.Is.is;
31
32
33
34
35 @SuppressWarnings( "checkstyle:magicnumber" )
36 public class JUnitCoreParametersTest
37 {
38 @Test
39 public void defaultParameters()
40 {
41 assertFalse( newTestSetDefault().isParallelismSelected() );
42 assertTrue( newTestSetDefault().isPerCoreThreadCount() );
43 assertThat( newTestSetDefault().getThreadCount(), is( 0 ) );
44 assertThat( newTestSetDefault().getThreadCountMethods(), is( 0 ) );
45 assertThat( newTestSetDefault().getThreadCountClasses(), is( 0 ) );
46 assertThat( newTestSetDefault().getThreadCountSuites(), is( 0 ) );
47 assertFalse( newTestSetDefault().isUseUnlimitedThreads() );
48 assertThat( newTestSetDefault().getParallelTestsTimeoutInSeconds(), is( 0d ) );
49 assertThat( newTestSetDefault().getParallelTestsTimeoutForcedInSeconds(), is( 0d ) );
50 assertTrue( newTestSetDefault().isParallelOptimization() );
51 }
52
53 @Test
54 public void optimizationParameter()
55 {
56 assertFalse( newTestSetOptimization( false ).isParallelOptimization() );
57 }
58
59 @Test
60 public void timeoutParameters()
61 {
62 JUnitCoreParameters parameters = newTestSetTimeouts( 5.5d, 11.1d );
63 assertThat( parameters.getParallelTestsTimeoutInSeconds(), is( 5.5d ) );
64 assertThat( parameters.getParallelTestsTimeoutForcedInSeconds(), is( 11.1d ) );
65 }
66
67 @Test
68 public void isParallelMethod()
69 {
70 assertFalse( newTestSetClasses().isParallelMethods() );
71 assertTrue( newTestSetMethods().isParallelMethods() );
72 assertTrue( newTestSetBoth().isParallelMethods() );
73 }
74
75 @Test
76 public void isParallelClasses()
77 {
78 assertTrue( newTestSetClasses().isParallelClasses() );
79 assertFalse( newTestSetMethods().isParallelClasses() );
80 assertTrue( newTestSetBoth().isParallelClasses() );
81 }
82
83 @Test
84 public void isParallelBoth()
85 {
86 assertFalse( isParallelMethodsAndClasses( newTestSetClasses() ) );
87 assertFalse( isParallelMethodsAndClasses( newTestSetMethods() ) );
88 assertTrue( isParallelMethodsAndClasses( newTestSetBoth() ) );
89 }
90
91 @Test
92 public void isPerCoreThreadCount()
93 {
94 assertFalse( newTestSetClasses().isPerCoreThreadCount() );
95 assertFalse( newTestSetMethods().isPerCoreThreadCount() );
96 assertTrue( newTestSetBoth().isPerCoreThreadCount() );
97 }
98
99 @Test
100 public void getThreadCount()
101 {
102 assertFalse( newTestSetClasses().isPerCoreThreadCount() );
103 assertFalse( newTestSetMethods().isPerCoreThreadCount() );
104 assertTrue( newTestSetBoth().isPerCoreThreadCount() );
105 }
106
107 @Test
108 public void isUseUnlimitedThreads()
109 {
110 assertFalse( newTestSetClasses().isUseUnlimitedThreads() );
111 assertTrue( newTestSetMethods().isUseUnlimitedThreads() );
112 assertFalse( newTestSetBoth().isUseUnlimitedThreads() );
113 }
114
115 @Test
116 public void isNoThreading()
117 {
118 assertFalse( newTestSetClasses().isNoThreading() );
119 assertFalse( newTestSetMethods().isNoThreading() );
120 assertFalse( newTestSetBoth().isNoThreading() );
121 }
122
123 @Test
124 public void isAnyParallelismSelected()
125 {
126 assertTrue( newTestSetClasses().isParallelismSelected() );
127 assertTrue( newTestSetMethods().isParallelismSelected() );
128 assertTrue( newTestSetBoth().isParallelismSelected() );
129 }
130
131 private Map<String, String> newDefaultProperties()
132 {
133 return new HashMap<>();
134 }
135
136
137 private Map<String, String> newPropertiesClasses()
138 {
139 Map<String, String> props = new HashMap<>();
140 props.put( JUnitCoreParameters.PARALLEL_KEY, "classes" );
141 props.put( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false" );
142 props.put( JUnitCoreParameters.THREADCOUNT_KEY, "2" );
143 props.put( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "false" );
144 return props;
145 }
146
147 private Map<String, String> newPropertiesMethods()
148 {
149 Map<String, String> props = new HashMap<>();
150 props.put( JUnitCoreParameters.PARALLEL_KEY, "methods" );
151 props.put( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false" );
152 props.put( JUnitCoreParameters.THREADCOUNT_KEY, "2" );
153 props.put( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "true" );
154 return props;
155 }
156
157 private Map<String, String> newPropertiesBoth()
158 {
159 Map<String, String> props = new HashMap<>();
160 props.put( JUnitCoreParameters.PARALLEL_KEY, "both" );
161 props.put( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "true" );
162 props.put( JUnitCoreParameters.THREADCOUNT_KEY, "7" );
163 props.put( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "false" );
164 return props;
165 }
166
167 private Map<String, String> newPropertiesTimeouts( double timeout, double forcedTimeout )
168 {
169 Map<String, String> props = new HashMap<>();
170 props.put( JUnitCoreParameters.PARALLEL_TIMEOUT_KEY, Double.toString( timeout ) );
171 props.put( JUnitCoreParameters.PARALLEL_TIMEOUTFORCED_KEY, Double.toString( forcedTimeout ) );
172 return props;
173 }
174
175 private Map<String, String> newPropertiesOptimization( boolean optimize )
176 {
177 Map<String, String> props = new HashMap<>();
178 props.put( JUnitCoreParameters.PARALLEL_OPTIMIZE_KEY, Boolean.toString( optimize ) );
179 return props;
180 }
181
182 private JUnitCoreParameters newTestSetDefault()
183 {
184 return new JUnitCoreParameters( newDefaultProperties() );
185 }
186
187 private JUnitCoreParameters newTestSetBoth()
188 {
189 return new JUnitCoreParameters( newPropertiesBoth() );
190 }
191
192 private JUnitCoreParameters newTestSetClasses()
193 {
194 return new JUnitCoreParameters( newPropertiesClasses() );
195 }
196
197 private JUnitCoreParameters newTestSetMethods()
198 {
199 return new JUnitCoreParameters( newPropertiesMethods() );
200 }
201
202 private JUnitCoreParameters newTestSetOptimization( boolean optimize )
203 {
204 return new JUnitCoreParameters( newPropertiesOptimization( optimize ) );
205 }
206
207 private JUnitCoreParameters newTestSetTimeouts( double timeout, double forcedTimeout )
208 {
209 return new JUnitCoreParameters( newPropertiesTimeouts( timeout, forcedTimeout ) );
210 }
211
212 private boolean isParallelMethodsAndClasses( JUnitCoreParameters jUnitCoreParameters )
213 {
214 return jUnitCoreParameters.isParallelMethods() && jUnitCoreParameters.isParallelClasses();
215 }
216 }