001package com.avaje.ebean;
002
003import java.util.ArrayList;
004import java.util.List;
005
006/**
007 * Manages the set of WithStaticFinder.
008 *
009 */
010public class WithStaticFinders {
011
012  protected List<WithStaticFinder<?>> staticFinderReplacement = new ArrayList<WithStaticFinder<?>>();
013
014  /**
015   * Create and return a WithStaticFinder. Expects a static 'finder' field on the beanType class.
016   */
017  public <T> WithStaticFinder<T> withFinder(Class<T> beanType) {
018    WithStaticFinder withFinder = new WithStaticFinder<T>(beanType);
019    staticFinderReplacement.add(withFinder);
020    return withFinder;
021  }
022
023  /**
024   * Use test doubles replacing original implementations.
025   */
026  public void useTestDoubles() {
027
028    for (WithStaticFinder<?> withStaticFinder : staticFinderReplacement) {
029      withStaticFinder.useTestDouble();
030    }
031  }
032
033  /**
034   * Restore the original implementations.
035   */
036  public void restoreOriginal() {
037
038    for (WithStaticFinder<?> withStaticFinder : staticFinderReplacement) {
039      withStaticFinder.restoreOriginal();
040    }
041  }
042
043  /**
044   * Before the start of a MockiEbean run calls useTestDoubles().
045   */
046  public void beforeRun() {
047    useTestDoubles();
048  }
049
050  /**
051   * After the end of a MockiEbean run calls restoreOriginal().
052   */
053  public void afterRun() {
054    restoreOriginal();
055  }
056}