ValidateFactCommand implements ExecutableCommand<Void> { @Override public Void execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup(KieSession.class); Collection<?> objects = ksession.getObjects(new ConditionFilter(factToCheck)); if (objects.size() > 0) { factToCheck.forEach(fact -> fact.getScenarioResult().setResult(true)); } else { factToCheck.forEach(fact -> fact.getScenarioResult().getFactMappingValue().setExceptionMessage("There is no instance which satisfies the expected conditions")); } return null; } ValidateFactCommand(List<FactCheckerHandle> factToCheck); @Override Void execute(Context context);  }
@Test public void executeTest() { when(registryContext.lookup(KieSession.class)).thenReturn(kieSession); Function<Object, ValueWrapper> alwaysMatchFunction = ValueWrapper::of; ValidateFactCommand validateFactCommand = new ValidateFactCommand(asList(new FactCheckerHandle(String.class, alwaysMatchFunction, scenarioResult))); when(kieSession.getObjects(any(ObjectFilter.class))).thenReturn(Collections.singleton(null)); validateFactCommand.execute(registryContext); verify(scenarioResult, times(1)).setResult(anyBoolean()); reset(scenarioResult); when(kieSession.getObjects(any(ObjectFilter.class))).thenReturn(Collections.emptyList()); when(scenarioResult.getFactMappingValue()).thenReturn(factMappingValue); when(factMappingValue.getStatus()).thenReturn(FactMappingValueStatus.FAILED_WITH_EXCEPTION); validateFactCommand.execute(registryContext); verify(scenarioResult, times(0)).setResult(anyBoolean()); }