NewDMNRuntimeCommand implements ExecutableCommand<DMNRuntime> { @Override public DMNRuntime execute(Context context) { RegistryContext registryContext = (RegistryContext) context; KieContainer kieContainer = registryContext.lookup(KieContainer.class); if (kieContainer == null) { throw new IllegalStateException("There is no existing KieContainer assigned to the Registry"); } DMNRuntime dmnRuntime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class); registryContext.register(DMNRuntime.class, dmnRuntime); return dmnRuntime; }  @Override DMNRuntime execute(Context context);  }
@Test public void execute() { RegistryContext registryContext = new ContextImpl(); NewDMNRuntimeCommand newDMNRuntimeCommand = new NewDMNRuntimeCommand(); assertThatThrownBy(() -> newDMNRuntimeCommand.execute(registryContext)) .isInstanceOf(IllegalStateException.class) .hasMessage("There is no existing KieContainer assigned to the Registry"); registryContext.register(KieContainer.class, new KieHelper().getKieContainer()); newDMNRuntimeCommand.execute(registryContext); assertNotNull(registryContext.lookup(DMNRuntime.class)); }