View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.test;
17  
18  import java.util.ArrayList;
19  import java.util.Calendar;
20  import java.util.Collections;
21  import java.util.Date;
22  import java.util.List;
23  
24  /**
25   * A generic, reusable fake service that records invocations, for testing purposes
26   * TODO: consider merging with {@link TestServiceInterface}/{@link GenericTestService} in KSB module 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   * @see FakeService
29   * @see GenericTestService
30   */
31  public class FakeServiceImpl implements FakeService {
32      /**
33       * Record of a method invocation
34       */
35      public static class Invocation {
36          public long timestamp;
37          public String methodName;
38          public List<Object> arguments = new ArrayList<Object>();
39          public Object returnValue;
40          public Invocation(String methodName) {
41              this.timestamp = Calendar.getInstance().getTimeInMillis();
42              this.methodName = methodName;
43          }
44      }
45  
46      private List<Invocation> invocations = Collections.synchronizedList(new ArrayList<Invocation>(0));
47  
48      /**
49       * @return the invocations made up to this point
50       */
51      public List<Invocation> getInvocations() {
52          return invocations;
53      }
54  
55      /**
56       * An arbitrary method
57       * @param arg1 doesn't matter
58       * @param arg2 doesn't matter
59       */
60      public void method1(Object arg1, Object arg2) {
61          Invocation i = new Invocation("method1");
62          i.arguments.add(arg1);
63          i.arguments.add(arg2);
64          invocations.add(i);
65      }
66  
67      /**
68       * An arbitrary method
69       * @param arg1 doesn't matter
70       * @return a {@link java.util.Date} instance
71       */
72      public Object method2(Object arg1) {
73          Invocation i = new Invocation("method2");
74          i.arguments.add(arg1);
75          i.returnValue = new Date();
76          invocations.add(i);
77          return i.returnValue;
78      }
79  }