package gov.nih.nci.cabig.ctms.testing;

import static org.easymock.classextension.EasyMock.*;
import org.apache.commons.logging.Log;

import java.util.Set;
import java.util.LinkedHashSet;
import java.lang.reflect.Method;

/**
 * @author Rhett Sutphin
 */
public class MockRegistry {
    private Log log;
    private Set<Object> mocks;

    public MockRegistry() {
        this(null);
    }

    public MockRegistry(Log log) {
        this.log = log;
        mocks = new LinkedHashSet<Object>();
    }

    public <T> T registerMockFor(Class<T> forClass) {
        return registered(createMock(forClass));
    }

    public <T> T registerMockFor(Class<T> forClass, Method... methodsToMock) {
        return registered(createMock(forClass, methodsToMock));
    }

    public void replayMocks() {
        for (Object mock : mocks) {
            debug("Replaying %s", mock);
            replay(mock);
        }
    }

    public void verifyMocks() {
        for (Object mock : mocks) {
            debug("Verifying %s", mock);
            verify(mock);
        }
    }

    public void resetMocks() {
        for (Object mock : mocks) {
            debug("Resetting %s", mock);
            reset(mock);
        }
    }

    private <T> T registered(T mock) {
        mocks.add(mock);
        return mock;
    }

    private void debug(String msg, Object... params) {
        if (log != null) log.debug(String.format(msg, params));
    }
}

@@ -30,24 +30,63 @@
 s.testing;%0A%0A
+import org.apache.commons.logging.Log;%0A
 import stati
@@ -131,68 +131,40 @@
 .*;%0A
+%0A
 import 
-org.apache.commons.logging.Log;%0A%0Aimport java.util.Set
+java.lang.reflect.Method
 ;%0Aim
@@ -205,35 +205,24 @@
 rt java.
-lang.reflect.Method
+util.Set
 ;%0A%0A/**%0A 
@@ -550,58 +550,248 @@
 lass
-) %7B%0A        return registered(createMock(forClass)
+, Method... methodsToMock) %7B%0A        T mock;%0A        if (methodsToMock.length == 0) %7B%0A            mock = createMock(forClass);%0A        %7D else %7B%0A            mock = createMock(forClass, methodsToMock);%0A        %7D%0A        return registered(mock
 );%0A 
@@ -813,32 +813,36 @@
 c %3CT%3E T register
+Nice
 MockFor(Class%3CT%3E
@@ -891,32 +891,148 @@
     
-return registered(
+T mock;%0A        if (methodsToMock.length == 0) %7B%0A            mock = createNiceMock(forClass);%0A        %7D else %7B%0A            mock = 
 create
+Nice
 Mock
@@ -1056,16 +1056,58 @@
 sToMock)
+;%0A        %7D%0A        return registered(mock
 );%0A    %7D

Add registerNiceMockFor method; consolidate two registerMockFor methods into one with varargs