private <T> Class<?> createProxyClass(Class<?> possibleMockedType,
			Class<?>... ancilliaryTypes) {
		Class<?> mockedType = possibleMockedType == Object.class ? ClassWithSuperclassToWorkAroundCglibBug.class
				: possibleMockedType;

		Enhancer enhancer = new Enhancer() {
			@SuppressWarnings("rawtypes")
			@Override
			protected void filterConstructors(Class sc, List constructors) {
				// Don't filter
			}
		};
		enhancer.setClassLoader(SearchingClassLoader.combineLoadersOf(
				mockedType, ancilliaryTypes));
		enhancer.setUseFactory(true);
		if (mockedType.isInterface()) {
			enhancer.setSuperclass(Object.class);
			enhancer.setInterfaces(prepend(mockedType, ancilliaryTypes));
		} else {
			enhancer.setSuperclass(mockedType);
			enhancer.setInterfaces(ancilliaryTypes);
		}
		enhancer.setCallbackTypes(new Class[] { InvocationHandler.class,
				NoOp.class });
		enhancer.setCallbackFilter(IGNORE_BRIDGE_METHODS);
		if (mockedType.getSigners() != null) {
			enhancer
					.setNamingPolicy(NAMING_POLICY_THAT_ALLOWS_IMPOSTERISATION_OF_CLASSES_IN_SIGNED_PACKAGES);
		}

		try {
			return enhancer.createClass();
		} catch (CodeGenerationException e) {
			// Note: I've only been able to manually test this. It exists to
			// help people writing
			// Eclipse plug-ins or using other environments that have
			// sophisticated class loader
			// structures.
			throw new IllegalArgumentException("could not imposterise "
					+ mockedType, e);
		}
	}