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.creadur.whisker.it;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.Collections;
24  
25  import junit.framework.TestCase;
26  
27  public class TestAnyCheck extends TestCase  {
28  
29      Collection<Check> checks;
30      Results results;
31      AnyCheck subject;
32  
33  
34      protected void setUp() throws Exception {
35          super.setUp();
36          results = new Results();
37          checks = new ArrayList<Check>();
38      }
39  
40      protected void tearDown() throws Exception {
41          super.tearDown();
42      }
43  
44      public void testNoChecksPass() {
45          subject = new AnyCheck(Collections.<Check> emptyList());
46          subject.check("a line");
47          verifyPass();
48      }
49  
50      public void testOneCheckFail() {
51          final String value = "some value";
52          checks.add(new AnyLineContainsCheck(value));
53  
54          subject = new AnyCheck(checks);
55          subject.check("a line");
56          verifyFail();
57      }
58  
59      private void verifyFail() {
60          assertFalse(subject.hasPassed());
61          subject.report(results);
62          assertTrue(results.hasFailed());
63      }
64  
65      public void testOneCheckPass() {
66          final String value = "some value";
67          checks.add(new AnyLineContainsCheck(value));
68  
69          subject = new AnyCheck(checks);
70          subject.check(value);
71          verifyPass();
72      }
73  
74      private void verifyPass() {
75          assertTrue(subject.hasPassed());
76          subject.report(results);
77          assertFalse(results.hasFailed());
78      }
79  
80      public void testTwoChecksPass() {
81          final String value = "some value";
82          final String anotherValue = "another value";
83          checks.add(new AnyLineContainsCheck(value));
84          checks.add(new AnyLineContainsCheck(anotherValue));
85          subject = new AnyCheck(checks);
86          subject.check(value);
87          subject.check(anotherValue);
88          verifyPass();
89      }
90  
91      public void testTwoChecksFail() {
92          final String value = "some value";
93          final String anotherValue = "another value";
94          checks.add(new AnyLineContainsCheck(value));
95          checks.add(new AnyLineContainsCheck(anotherValue));
96          subject = new AnyCheck(checks);
97          subject.check("not");
98          verifyFail();
99      }
100 
101     public void testTwoChecksPassWhenOneMatchFails() {
102         final String value = "some value";
103         final String anotherValue = "another value";
104         checks.add(new AnyLineContainsCheck(value));
105         checks.add(new AnyLineContainsCheck(anotherValue));
106         subject = new AnyCheck(checks);
107         subject.check("not");
108         subject.check(value);
109         verifyPass();
110     }
111 
112 }