File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\test\java\hudson\matrix\CombinationTest.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.matrix;
25
26 import junit.framework.TestCase;
27
28 import java.util.Map;
29 import java.util.HashMap;
30
31 /**
32 * @author Kohsuke Kawaguchi
33 */
34 public class CombinationTest extends TestCase {
35 AxisList axes = new AxisList(
36 new Axis("a","X","x"),
37 new Axis("b","Y","y"));
38
39 @SuppressWarnings({"RedundantStringConstructorCall"})
40 public void testEval() {
41 Map<String,String> r = new HashMap<String, String>();
42 r.put("a","X");
43 r.put("b",new String("Y")); // make sure this 'Y' is not the same object as literal "Y".
44 Combination c = new Combination(r);
45
46 r.put("a","x");
47 Combination d = new Combination(r);
48
49 assertTrue(eval(c, null));
50 assertTrue(eval(c," "));
51 assertTrue(eval(c,"true"));
52 assertTrue(eval(c,"a=='X'"));
53 assertTrue(eval(c,"b=='Y'"));
54 assertTrue(eval(c,"(a=='something').implies(b=='other')"));
55 assertTrue(eval(c,"index%2==0")^eval(d,"index%2==0"));
56 assertTrue(eval(c,"index%2==1")^eval(d,"index%2==1"));
57 }
58
59 private boolean eval(Combination c, String exp) {
60 return c.evalGroovyExpression(axes, exp);
61 }
62 }
63