Clover coverage report - jMock - 1.0-beta1
Coverage timestamp: Sat Nov 29 2003 19:35:59 GMT
file stats: LOC: 104   Methods: 8
NCLOC: 79   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
MapEntry.java 83.3% 90% 87.5% 88.3%
coverage coverage
 1   
 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
 2   
 package org.jmock.expectation;
 3   
 
 4   
 import java.lang.reflect.Array;
 5   
 import java.util.Map;
 6   
 
 7   
 /**
 8   
  * A public MapEntry data type that can be used where the Map.Entry interface is required
 9   
  * (needed because the Sun implementation is package protected)
 10   
  */
 11   
 
 12   
 public class MapEntry implements Map.Entry {
 13   
     private Object myKey;
 14   
     private Object myValue;
 15   
 
 16  48
     public MapEntry(Object aKey, Object aValue) {
 17  48
         myKey = (aKey == null ? new Null() : aKey);
 18  48
         myValue = (aValue == null ? new Null() : aValue);
 19   
     }
 20   
 
 21  26
     public boolean equals(Object o) {
 22  26
         if (!(o instanceof MapEntry)) {
 23  0
             return false;
 24   
         }
 25  26
         MapEntry other = (MapEntry) o;
 26   
 
 27  26
         if (myValue.getClass().isArray() && other.getValue().getClass().isArray()) {
 28  6
             return arrayEquals(other.getValue());
 29   
         } else {
 30  20
             return myKey.equals(other.getKey()) && myValue.equals(other.getValue());
 31   
         }
 32   
     }
 33   
 
 34  6
     private final boolean arrayEquals(Object anArray) {
 35  6
         int i = 0;
 36  6
         boolean endOfThisArray = false;
 37  6
         boolean endOfAnotherArray = false;
 38   
 
 39  6
         while (true) {
 40  12
             Object valueOfThis = null;
 41  12
             Object valueOfAnother = null;
 42   
 
 43  12
             try {
 44  12
                 valueOfThis = Array.get(myValue, i);
 45   
             } catch (ArrayIndexOutOfBoundsException e) {
 46  4
                 endOfThisArray = true;
 47   
             }
 48   
 
 49  12
             try {
 50  12
                 valueOfAnother = Array.get(anArray, i);
 51   
             } catch (ArrayIndexOutOfBoundsException e) {
 52  4
                 endOfAnotherArray = true;
 53   
             }
 54   
 
 55  12
             if (endOfThisArray && endOfAnotherArray) {
 56  2
                 return true;
 57   
             }
 58   
 
 59  10
             if (valueOfThis != null || valueOfAnother != null) {
 60  10
                 if (valueOfThis == null || !valueOfThis.equals(valueOfAnother)) {
 61  4
                     return false;
 62   
                 }
 63   
             }
 64   
 
 65  6
             i++;
 66   
         }
 67   
     }
 68   
 
 69  20
     public Object getKey() {
 70  20
         return myKey;
 71   
     }
 72   
 
 73  30
     public Object getValue() {
 74  30
         return myValue;
 75   
     }
 76   
 
 77  32
     public int hashCode() {
 78  32
         int hash = myKey.hashCode();
 79  32
         if (myValue.getClass().isArray()) {
 80  4
             int i = 0;
 81   
 
 82  4
             try {
 83  4
                 while (true) {
 84  8
                     hash = hash ^ Array.get(myValue, i++).hashCode();
 85   
                 }
 86   
             } catch (ArrayIndexOutOfBoundsException e) {
 87   
             }
 88   
         } else {
 89  28
             hash = hash ^ myValue.hashCode();
 90   
         }
 91  32
         return hash;
 92   
     }
 93   
 
 94  0
     public Object setValue(Object aValue) {
 95  0
         Object oldValue = myValue;
 96  0
         myValue = (null == aValue ? new Null() : aValue);
 97  0
         return oldValue;
 98   
     }
 99   
 
 100  4
     public String toString() {
 101  4
         return myKey.toString() + "=" + myValue.toString();
 102   
     }
 103   
 }
 104