SHARE
TWEET

Easy mock factory

MatthijsFontys Jan 21st, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class LogicFactory {
  2.  
  3.     // Check for test mode
  4.     private static boolean isTestMode = false;
  5.     private static boolean canChangeMode = true;
  6.  
  7.     private LogicFactory(){
  8.         // Empty constructor for readability. Class will only contain static methods
  9.     }
  10.  
  11.     public static void setTestMode(boolean isTestMode){
  12.         if(LogicFactory.canChangeMode) {
  13.             LogicFactory.isTestMode = isTestMode;
  14.             canChangeMode = false;
  15.         }
  16.         else
  17.             throw new IllegalStateException("Logic factory state already has been defined and can only be defined once");
  18.     }
  19.  
  20.  
  21.     public static IMessageCreator createMessageCreator(){
  22.         if(isTestMode)
  23.             return new MessageCreatorMock();
  24.         else
  25.             return new MessageCreator();
  26.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top