All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.anoprise.mocking.MockFactory Maven / Gradle / Ivy

Go to download

Collection of utils for different enterprise class projects. Among other stuff contains Caches, Mocking, DualCrud, MetaFactory and SessionDistributorService. Visit https://opensource.anotheria.net for details.

There is a newer version: 4.0.0
Show newest version
package net.anotheria.anoprise.mocking;

import java.lang.reflect.Proxy;
import java.util.Arrays;

/**
 * Factory for mock objects.
 * @author lrosenberg.
 *
 */
public final class MockFactory {
	/**
	 * Creates a new Mock of type T.
	 * @param  interface type to mock.
	 * @param clazz class of the interface (T.class).
	 * @param mockings some mockings with method implementations for methods in T.
	 * @return
	 */
	public static  T createMock(Class clazz, Mocking ... mockings){
		Mock mock = new Mock(clazz, Arrays.asList(mockings));
		return clazz.cast(Proxy.newProxyInstance(MockFactory.class.getClassLoader(), new Class[]{ clazz }, mock)); 		
	}
	
	private MockFactory(){
		//prevent initialization.
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy