001/**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.test;
017
018import java.util.ArrayList;
019import java.util.Calendar;
020import java.util.Collections;
021import java.util.Date;
022import java.util.List;
023
024/**
025 * A generic, reusable fake service that records invocations, for testing purposes
026 * TODO: consider merging with {@link TestServiceInterface}/{@link GenericTestService} in KSB module 
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 * @see FakeService
029 * @see GenericTestService
030 */
031public class FakeServiceImpl implements FakeService {
032    /**
033     * Record of a method invocation
034     */
035    public static class Invocation {
036        public long timestamp;
037        public String methodName;
038        public List<Object> arguments = new ArrayList<Object>();
039        public Object returnValue;
040        public Invocation(String methodName) {
041            this.timestamp = Calendar.getInstance().getTimeInMillis();
042            this.methodName = methodName;
043        }
044    }
045
046    private List<Invocation> invocations = Collections.synchronizedList(new ArrayList<Invocation>(0));
047
048    /**
049     * @return the invocations made up to this point
050     */
051    public List<Invocation> getInvocations() {
052        return invocations;
053    }
054
055    /**
056     * An arbitrary method
057     * @param arg1 doesn't matter
058     * @param arg2 doesn't matter
059     */
060    public void method1(Object arg1, Object arg2) {
061        Invocation i = new Invocation("method1");
062        i.arguments.add(arg1);
063        i.arguments.add(arg2);
064        invocations.add(i);
065    }
066
067    /**
068     * An arbitrary method
069     * @param arg1 doesn't matter
070     * @return a {@link java.util.Date} instance
071     */
072    public Object method2(Object arg1) {
073        Invocation i = new Invocation("method2");
074        i.arguments.add(arg1);
075        i.returnValue = new Date();
076        invocations.add(i);
077        return i.returnValue;
078    }
079}