Clover coverage report - jMock - 1.0-beta1
Coverage timestamp: Sat Nov 29 2003 19:35:59 GMT
file stats: LOC: 77   Methods: 10
NCLOC: 60   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
CoreMock.java 100% 100% 100% 100%
coverage
 1   
 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
 2   
 package org.jmock.dynamic;
 3   
 
 4   
 import junit.framework.AssertionFailedError;
 5   
 
 6   
 import java.lang.reflect.Method;
 7   
 import java.lang.reflect.Proxy;
 8   
 
 9   
 public class CoreMock implements DynamicMock {
 10   
     private InvocationDispatcher invocationDispatcher;
 11   
     private Object proxy;
 12   
     private String name;
 13   
 
 14  98
     public CoreMock(Class mockedClass, String name, InvocationDispatcher invocationDispatcher) {
 15  98
         this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{mockedClass}, this);
 16  98
         this.name = name;
 17  98
         this.invocationDispatcher = invocationDispatcher;
 18   
 
 19   
 // callables.addStub(new ProxyIsEqual(this.mock));
 20   
     }
 21   
 
 22  86
     public Object proxy() {
 23  86
         return this.proxy;
 24   
     }
 25   
 
 26  56
     public Object invoke(Object proxy, Method method, Object[] args)
 27   
             throws Throwable {
 28  56
         Invocation invocation = new Invocation(method, args);
 29  56
         try {
 30  56
             if (invocation.isCheckingEqualityOnProxy()) {
 31  2
                 return new Boolean(args[0] == this.proxy);
 32  54
             } else if (invocation.isMockNameGetter()) {
 33  8
                 return this.getMockName();
 34   
             } else {
 35  46
                 return invocationDispatcher.dispatch(invocation);
 36   
             }
 37   
         } catch (AssertionFailedError ex) {
 38  18
             DynamicMockError error = new DynamicMockError(invocation, name + ": " + ex.getMessage());
 39  18
             error.fillInStackTrace();
 40  18
             throw error;
 41   
         }
 42   
     }
 43   
 
 44  24
     public void verify() {
 45  24
         try {
 46  24
             invocationDispatcher.verify();
 47   
         } catch (AssertionFailedError ex) {
 48  8
             throw new AssertionFailedError(name + ": " + ex.getMessage());
 49   
         }
 50   
     }
 51   
 
 52  14
     public String toString() {
 53  14
         return this.name;
 54   
     }
 55   
 
 56  8
     public String getMockName() {
 57  8
         return this.name;
 58   
     }
 59   
 
 60  38
     public void add(Invokable invokable) {
 61  38
         invocationDispatcher.add(invokable);
 62   
     }
 63   
 
 64  2
     public void reset() {
 65  2
         invocationDispatcher.clear();
 66   
     }
 67   
 
 68  62
     public static String mockNameFromClass(Class c) {
 69  62
         return "mock" + className(c);
 70   
     }
 71   
 
 72  62
     public static String className(Class c) {
 73  62
         String name = c.getName();
 74  62
         return name.substring(name.lastIndexOf('.') + 1);
 75   
     }
 76   
 }
 77