Coverage Report - com.lexicalscope.fluentreflection.ReflectionMatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
ReflectionMatcher
100%
24/24
N/A
1
 
 1  
 package com.lexicalscope.fluentreflection;
 2  
 
 3  
 /*
 4  
  * Copyright 2011 Tim Wood
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * 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, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import static com.lexicalscope.fluentreflection.MatcherAnd.andOf;
 20  
 import static com.lexicalscope.fluentreflection.MatcherOr.orOf;
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 import org.hamcrest.Matcher;
 26  
 import org.hamcrest.TypeSafeMatcher;
 27  
 
 28  8634
 /**
 29  
  * Base class for all the matchers included in the library.
 30  
  *
 31  
  * @author tim
 32  
  *
 33  
  * @param <T>
 34  
  */
 35  2908
 public abstract class ReflectionMatcher<T> extends TypeSafeMatcher<T> {
 36  
     /**
 37  
      * Creates an "and" matcher combining this matcher and the given one
 38  1344
      *
 39  1344
      * @param matcher
 40  1344
      *            The matcher to be put in and with this one
 41  1344
      * @return A matcher that return true if this matcher and the passed one
 42  
      *         return true
 43  
      */
 44  
     public ReflectionMatcher<T> and(final Matcher<? super T> matcher) {
 45  434
         final List<Matcher<? super T>> list = new ArrayList<Matcher<? super T>>();
 46  434
         list.add(this);
 47  434
         list.add(matcher);
 48  434
         return andOf(list);
 49  
     }
 50  
 
 51  
     /**
 52  
      * Creates an "or" matcher combining this matcher and the given one
 53  6
      *
 54  6
      * @param matcher
 55  6
      *            The matcher to be put in or with this one
 56  6
      * @return A matcher that return true if this matcher or the passed one
 57  
      *         return true
 58  
      */
 59  
     public ReflectionMatcher<T> or(final Matcher<? super T> matcher) {
 60  4
         final List<Matcher<? super T>> list = new ArrayList<Matcher<? super T>>();
 61  4
         list.add(this);
 62  28
         list.add(matcher);
 63  28
         return orOf(list);
 64  24
     }
 65  24
 
 66  
     static <T> Matcher<T> allOf(
 67  
             final Matcher<? super T> T0,
 68  
             final Matcher<? super T> T1) {
 69  26
         final List<Matcher<? super T>> list = new ArrayList<Matcher<? super T>>();
 70  26
         list.add(T0);
 71  26
         list.add(T1);
 72  26
         return andOf(list);
 73  
     }
 74  
 }