Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.
Also see the following revisions: ------------------------------------------------------------------------ r593144 | skestle | 2007-11-08 04:21:55 -0800 (Thu, 08 Nov 2007) | 3 lines Updated CollectionUtils and test. Probably 80-90% complete for generics. Very open to review / patches. Jira: COLLECTIONS-245 ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815135 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a5422f9b40
commit
7ffce465db
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.collections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.easymock.IExpectationSetters;
|
||||
|
||||
/**
|
||||
* Provides utilities for making mock-based tests. Most notable is the generic "type-safe"
|
||||
* {@link #createMock(Class)} method, and {@link #replay()} and {@link #verify()} methods
|
||||
* that call the respective methods on all created mock objects.
|
||||
*
|
||||
* @author Stephen Kestle
|
||||
*/
|
||||
public abstract class MockTestCase {
|
||||
private List<Object> mockObjects = new ArrayList<Object>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> T createMock(Class name) {
|
||||
T mock = (T) EasyMock.createMock(name);
|
||||
return registerMock(mock);
|
||||
}
|
||||
|
||||
private <T> T registerMock(T mock) {
|
||||
mockObjects.add(mock);
|
||||
return mock;
|
||||
}
|
||||
|
||||
protected <T> IExpectationSetters<T> expect(T t) {
|
||||
return EasyMock.expect(t);
|
||||
}
|
||||
|
||||
protected final void replay() {
|
||||
for (Object o : mockObjects) {
|
||||
EasyMock.replay(o);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void verify() {
|
||||
for (ListIterator<Object> i = mockObjects.listIterator(); i.hasNext();) {
|
||||
try {
|
||||
EasyMock.verify(i.next());
|
||||
} catch (AssertionError e) {
|
||||
throw new AssertionError((i.previousIndex() + 1) + ""
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue