Coverage Report - jaggregate.junit.framework.ObjectAssert
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectAssert
100%
8/8
100%
2/2
0
 
 1  
 /*
 2  
  Copyright 2004-2008 Paul R. Holser, Jr.  All rights reserved.
 3  
  Licensed under the Academic Free License version 3.0
 4  
  */
 5  
 
 6  
 package jaggregate.junit.framework;
 7  
 
 8  
 import static java.lang.String.format;
 9  
 
 10  
 import jaggregate.UnaryCondition;
 11  
 import jaggregate.UnaryPredicate;
 12  
 import static junit.framework.Assert.*;
 13  
 
 14  
 /**
 15  
  * Additional assertions for <a href="http://www.junit.org">JUnit</a> that apply to
 16  
  * Java objects in general.
 17  
  *
 18  
  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
 19  
  * @version $Id: ObjectAssert.java,v 1.5 2008/05/08 03:49:38 pholser Exp $
 20  
  */
 21  
 public class ObjectAssert {
 22  
     /**
 23  
      * Discourages instantiation.
 24  
      *
 25  
      * @throws UnsupportedOperationException always
 26  
      */
 27  1
     protected ObjectAssert() {
 28  1
         throw new UnsupportedOperationException();
 29  
     }
 30  
 
 31  
     /**
 32  
      * Asserts that a given object satisfies a given constraint.
 33  
      *
 34  
      * @param <T> a restriction on the type of the target object
 35  
      * @param target the object to query
 36  
      * @param constraint the constraint that {@code target} must satisfy
 37  
      * @throws junit.framework.AssertionFailedError if the constraint is not satisfied
 38  
      * @see <a href="http://joe.truemesh.com/blog/000511.html">Flexible JUnit assertions
 39  
      * with <code>assertThat()</code></a>
 40  
      */
 41  
     public static <T> void assertThat( T target, UnaryPredicate<? super T> constraint ) {
 42  7
         if ( !constraint.matches( target ) )
 43  1
             fail( format(
 44  
                 "expected: <%1$s> but got: <%2$s>", constraint.describe(), target ) );
 45  5
     }
 46  
 
 47  
     /**
 48  
      * Asserts that a given object satisfies a given constraint.
 49  
      *
 50  
      * @param <T> a restriction on the type of the target object
 51  
      * @param target the object to query
 52  
      * @param constraint the constraint that {@code target} must satisfy
 53  
      * @throws junit.framework.AssertionFailedError if the constraint is not satisfied
 54  
      * @see <a href="http://joe.truemesh.com/blog/000511.html">Flexible JUnit assertions
 55  
      * with <code>assertThat()</code></a>
 56  
      */
 57  
     public static <T> void assertMatches( T target,
 58  
         UnaryCondition<? super T> constraint ) {
 59  
 
 60  2
         if ( !constraint.matches( target ) )
 61  1
             fail();
 62  1
     }
 63  
 }