### Question:
ExecutionScriptHandlerDispatcher implements ExecutionScriptHandler<T> { @Override public void setUp(ExecutionMonitor monitor, ExecutionContext context) throws InterruptedException, IOException { ExecutionScriptHandler<T> target; if (forceSetUp != null) { target = delegations.get(forceSetUp); } else { target = resolve(context, null); } assert target != null; YSLOG.info("I01001", target.getHandlerId(), context.getBatchId(), context.getFlowId(), context.getPhase(), context.getExecutionId()); target.setUp(monitor, context); } protected  ExecutionScriptHandlerDispatcher(Class<? extends ExecutionScriptHandler<T>> handlerKind); @Override void configure(ServiceProfile<?> profile); @Override String getHandlerId(); @Override String getResourceId(
            ExecutionContext context,
            ExecutionScript script); @Override Map<String, String> getProperties(
            ExecutionContext context,
            ExecutionScript script); @Override Map<String, String> getEnvironmentVariables(
            ExecutionContext context,
            ExecutionScript script); @Override void setUp(ExecutionMonitor monitor, ExecutionContext context); @Override void execute(
            ExecutionMonitor monitor,
            ExecutionContext context,
            T script); @Override void cleanUp(ExecutionMonitor monitor, ExecutionContext context);  }### Answer:
@Test public void setUp() throws Exception { Map<String, String> conf = createConf(); declare(conf, "default", FailCommandScriptHandler.class); declare(conf, "other", FailCommandScriptHandler.class); declare(conf, "specified", FailCommandScriptHandler.class); CommandScriptHandlerDispatcher dispatcher = create(conf); ExecutionContext something = context("testing", ExecutionPhase.SETUP); try { dispatcher.setUp(ExecutionMonitor.NULL, something); fail(); } catch (MessageException e) { assertThat(e.message, is("default")); assertThat(e.context.getPhase(), is(ExecutionPhase.SETUP)); } }
@Test public void setUp_match() throws Exception { put("testing.*=other"); Map<String, String> conf = createConf(); declare(conf, "default", FailCommandScriptHandler.class); declare(conf, "other", FailCommandScriptHandler.class); declare(conf, "specified", FailCommandScriptHandler.class); CommandScriptHandlerDispatcher dispatcher = create(conf); ExecutionContext something = context("testing", ExecutionPhase.SETUP); try { dispatcher.setUp(ExecutionMonitor.NULL, something); fail(); } catch (MessageException e) { assertThat(e.message, is("other")); assertThat(e.context.getPhase(), is(ExecutionPhase.SETUP)); } }
@Test public void setUp_specified() throws Exception { put("testing.*=other"); Map<String, String> conf = createConf(); declare(conf, "default", FailCommandScriptHandler.class); declare(conf, "other", FailCommandScriptHandler.class); declare(conf, "specified", FailCommandScriptHandler.class); declare(conf, ExecutionScriptHandlerDispatcher.KEY_SETUP, "specified"); CommandScriptHandlerDispatcher dispatcher = create(conf); ExecutionContext something = context("testing", ExecutionPhase.SETUP); try { dispatcher.setUp(ExecutionMonitor.NULL, something); fail(); } catch (MessageException e) { assertThat(e.message, is("specified")); assertThat(e.context.getPhase(), is(ExecutionPhase.SETUP)); } }