/* * Created on Apr 22, 2007 * * Licensed 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. * * Copyright @2007 the original author or authors. */ package org.fest.mocks; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.List; import net.sf.cglib.proxy.Enhancer; import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; /** * Understands a template for usage of EasyMock mocks. *
* Here is an small example that uses EasyMock to verify that
* EmployeeBO uses a EmployeeDAO to store employee information in the database:
*
*
* @Test public void shouldAddNewEmployee() {
* mockEmployeeDao.insert(employee);
* replay(mockEmployeeDao);
* employeeBo.addNewEmployee(employee);
* verify(mockEmployeeDao);
* }
*
*
*
*
* In this example, it is easy to distinguish the expectations made on the mock object (mockEmployeeDao).
* But in a more complex scenario, that distinction could be more difficult to spot. We can use the
* EasyMockTemplate to separate the code to be tested from the mock expectations:
*
*
* @Test public void shouldAddNewEmployee() {
* EasyMockTemplate t = new EasyMockTemplate(mockEmployeeDao) {
* @Override protected void expectations() {
* mockEmployeeDao.insert(employee);
* }
*
* @Override protected void codeToTest() {
* employeeBo.addNewEmployee(employee);
* }
* };
* t.run();
* }
*
*
*
*
* The benefits of EasyMockTemplate are:
*
replay and verify anymore)