1 package org.apache.maven.repository.reporting;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import java.lang.reflect.InvocationHandler;
20 import java.lang.reflect.Method;
21 import java.util.HashMap;
22 import java.util.List;
26 * @author Edwin Punzalan
28 public class GenericMockObject
29 implements InvocationHandler
31 Map invocations = new HashMap();
33 public GenericMockObject()
38 public GenericMockObject( Map returnMap )
40 invocations = returnMap;
43 public void setExpectedReturns( Method method, List returnList )
45 invocations.put( method, returnList );
48 public Object invoke( Object proxy, Method method, Object[] args )
51 if ( !invocations.containsKey( method ) )
53 throw new UnsupportedOperationException( "No expected return values defined." );
56 List returnList = (List) invocations.get( method );
57 if ( returnList.size() < 1 )
59 throw new UnsupportedOperationException( "Too few expected return values defined." );
61 return returnList.remove( 0 );