View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.junitcore;
20  
21  
22  import junit.framework.TestCase;
23  import org.junit.Test;
24  
25  import java.util.Properties;
26  
27  import static org.junit.Assert.*;
28  
29  /*
30   * @author Kristian Rosenvold, kristian.rosenvold@gmail com
31   */
32  
33  public class JUnitCoreParametersTest extends TestCase
34  {
35      public void testIsParallelMethod()
36          throws Exception
37      {
38          assertFalse( getTestSetClasses().isParallelMethod() );
39          assertTrue( getTestSetMethods().isParallelMethod() );
40          assertFalse( getTestSetBoth().isParallelMethod() );
41      }
42  
43      public void testIsParallelClasses()
44          throws Exception
45      {
46          assertTrue( getTestSetClasses().isParallelClasses() );
47          assertFalse( getTestSetMethods().isParallelClasses() );
48          assertFalse( getTestSetBoth().isParallelClasses() );
49      }
50  
51      public void testIsParallelBoth()
52          throws Exception
53      {
54          assertFalse( getTestSetClasses().isParallelBoth() );
55          assertFalse( getTestSetMethods().isParallelBoth() );
56          assertTrue( getTestSetBoth().isParallelBoth() );
57      }
58  
59      public void testIsPerCoreThreadCount()
60          throws Exception
61      {
62          assertFalse( getTestSetClasses().isPerCoreThreadCount() );
63          assertFalse( getTestSetMethods().isPerCoreThreadCount() );
64          assertTrue( getTestSetBoth().isPerCoreThreadCount() );
65      }
66  
67      public void testGetThreadCount()
68          throws Exception
69      {
70          assertFalse( getTestSetClasses().isPerCoreThreadCount() );
71          assertFalse( getTestSetMethods().isPerCoreThreadCount() );
72          assertTrue( getTestSetBoth().isPerCoreThreadCount() );
73      }
74  
75      public void testIsUseUnlimitedThreads()
76          throws Exception
77      {
78          assertFalse( getTestSetClasses().isUseUnlimitedThreads() );
79          assertTrue( getTestSetMethods().isUseUnlimitedThreads() );
80          assertFalse( getTestSetBoth().isUseUnlimitedThreads() );
81      }
82  
83      public void testIsNoThreading()
84          throws Exception
85      {
86          assertFalse( getTestSetClasses().isNoThreading() );
87          assertFalse( getTestSetMethods().isNoThreading() );
88          assertFalse( getTestSetBoth().isNoThreading() );
89      }
90  
91      public void testIsAnyParallelitySelected()
92          throws Exception
93      {
94          assertTrue( getTestSetClasses().isAnyParallelitySelected() );
95          assertTrue( getTestSetMethods().isAnyParallelitySelected() );
96          assertTrue( getTestSetBoth().isAnyParallelitySelected() );
97      }
98  
99  
100     public void testToString()
101         throws Exception
102     {
103         assertNotNull( getTestSetBoth().toString() );
104     }
105 
106 
107     public Properties getPropsetClasses()
108     {
109         Properties props = new Properties();
110         props.setProperty( JUnitCoreParameters.PARALLEL_KEY, "classes" );
111         props.setProperty( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false" );
112         props.setProperty( JUnitCoreParameters.THREADCOUNT_KEY, "2" );
113         props.setProperty( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "false" );
114         return props;
115     }
116 
117     public Properties getPropsetMethods()
118     {
119         Properties props = new Properties();
120         props.setProperty( JUnitCoreParameters.PARALLEL_KEY, "methods" );
121         props.setProperty( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false" );
122         props.setProperty( JUnitCoreParameters.THREADCOUNT_KEY, "2" );
123         props.setProperty( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "true" );
124         return props;
125     }
126 
127     public Properties getPropsetBoth()
128     {
129         Properties props = new Properties();
130         props.setProperty( JUnitCoreParameters.PARALLEL_KEY, "both" );
131         props.setProperty( JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "true" );
132         props.setProperty( JUnitCoreParameters.THREADCOUNT_KEY, "7" );
133         props.setProperty( JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "false" );
134         return props;
135     }
136 
137     private JUnitCoreParameters getTestSetBoth()
138     {
139         return new JUnitCoreParameters( getPropsetBoth() );
140     }
141 
142     private JUnitCoreParameters getTestSetClasses()
143     {
144         return new JUnitCoreParameters( getPropsetClasses() );
145     }
146 
147     private JUnitCoreParameters getTestSetMethods()
148     {
149         return new JUnitCoreParameters( getPropsetMethods() );
150     }
151 }