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  
22  import static org.apache.commons.collections4.CollectionUtils.*;
23  import static org.apache.creadur.whisker.it.CheckHasPassedPredicate.*;
24  import static org.apache.creadur.whisker.it.Not.*;
25  
26  import java.util.ArrayList;
27  import java.util.Collection;
28  
29  public class CheckHelpers {
30  
31      public static AnyCheck aLineContainsEither(final String value, final String alternative) {
32          return new AnyCheck(listAnyLineContains(value, alternative));
33      }
34  
35      private static Collection<Check> listAnyLineContains(final String value,
36              final String alternative) {
37          final Collection<Check> checks = new ArrayList<Check>();
38          checks.add(new AnyLineContainsCheck(value));
39          checks.add(new AnyLineContainsCheck(alternative));
40          return checks;
41      }
42  
43      public static AllCheck containsBothLines(final String value, final String alternative) {
44          return new AllCheck(listAnyLineContains(value, alternative));
45      }
46  
47      public static boolean anyPassed(final Collection<Check> checks) {
48          return exists(checks, checkPassed());
49      }
50  
51      public static boolean allPassed(final Collection<Check> checks) {
52          return not(anyFailed(checks));
53      }
54  
55      public static boolean anyFailed(final Collection<Check> checks) {
56          return exists(checks, checkFailed());
57      }
58  
59      public static ReportClosure to(final Results results) {
60          return new ReportClosure(results);
61      }
62  
63      public static DoCheckClosure doCheck(final String line) {
64          return new DoCheckClosure(line);
65      }
66  
67  }