io.ebean.WithStaticFinders Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ebean-mocker Show documentation
Show all versions of ebean-mocker Show documentation
Ability to set a Mockito mock EbeanServer as 'default' EbeanServer
package io.ebean;
import java.util.ArrayList;
import java.util.List;
/**
* Manages the set of WithStaticFinder.
*
*/
public class WithStaticFinders {
protected List> staticFinderReplacement = new ArrayList>();
/**
* Create and return a WithStaticFinder. Expects a static 'finder' field on the beanType class.
*/
public WithStaticFinder withFinder(Class beanType) {
WithStaticFinder withFinder = new WithStaticFinder(beanType);
staticFinderReplacement.add(withFinder);
return withFinder;
}
/**
* Use test doubles replacing original implementations.
*/
public void useTestDoubles() {
for (WithStaticFinder> withStaticFinder : staticFinderReplacement) {
withStaticFinder.useTestDouble();
}
}
/**
* Restore the original implementations.
*/
public void restoreOriginal() {
for (WithStaticFinder> withStaticFinder : staticFinderReplacement) {
withStaticFinder.restoreOriginal();
}
}
/**
* Before the start of a MockiEbean run calls useTestDoubles().
*/
public void beforeRun() {
useTestDoubles();
}
/**
* After the end of a MockiEbean run calls restoreOriginal().
*/
public void afterRun() {
restoreOriginal();
}
}