001/***************************************************************************** 002 * Copyright (C) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 * * 008 * Original code by Mauro Talevi * 009 *****************************************************************************/ 010package org.picocontainer.tck; 011 012import org.jmock.Mockery; 013import org.jmock.lib.CamelCaseNamingScheme; 014 015public class MockFactory { 016 017 /** 018 * Returns a Mockery instance with a counting naming scheme. 019 * From jMock 2.4, default behaviour does not allow more than one mock with same name. 020 * This can be over-restrictive. A workaround is to append a counting integer. 021 * 022 * @return A Mockery instance 023 */ 024 public static Mockery mockeryWithCountingNamingScheme() { 025 return new Mockery() { 026 { 027 setNamingScheme(new CamelCaseNamingScheme() { 028 private int count; 029 030 public String defaultNameFor(Class<?> typeToMock) { 031 count++; 032 return super.defaultNameFor(typeToMock) + count; 033 } 034 }); 035 } 036 }; 037 } 038}