net.anotheria.anoprise.mocking.MockFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ano-prise Show documentation
Show all versions of ano-prise Show documentation
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.
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