RuleScenarioRunnerHelper extends AbstractRunnerHelper { protected Function<Object, ValueWrapper> createExtractorFunction(ExpressionEvaluator expressionEvaluator, FactMappingValue expectedResult, ScesimModelDescriptor scesimModelDescriptor) { return objectToCheck -> { ExpressionIdentifier expressionIdentifier = expectedResult.getExpressionIdentifier(); FactMapping factMapping = scesimModelDescriptor.getFactMapping(expectedResult.getFactIdentifier(), expressionIdentifier) .orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen")); List<String> pathToValue = factMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(toList()); ScenarioBeanWrapper<?> scenarioBeanWrapper = ScenarioBeanUtil.navigateToObject(objectToCheck, pathToValue, false); Object resultValue = scenarioBeanWrapper.getBean(); Object expectedResultValue = expectedResult.getRawValue(); return getResultWrapper(factMapping.getClassName(), expectedResult, expressionEvaluator, expectedResultValue, resultValue, scenarioBeanWrapper.getBeanClass()); }; }    }
@Test public void createExtractorFunctionTest() { String personName = "Test"; FactMappingValue factMappingValue = new FactMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, personName); Function<Object, ValueWrapper> extractorFunction = runnerHelper.createExtractorFunction(expressionEvaluator, factMappingValue, simulation.getScesimModelDescriptor()); Person person = new Person(); person.setFirstName(personName); assertTrue(extractorFunction.apply(person).isValid()); person.setFirstName("OtherString"); assertFalse(extractorFunction.apply(person).isValid()); Function<Object, ValueWrapper> extractorFunction1 = runnerHelper.createExtractorFunction(expressionEvaluator, new FactMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, null), simulation.getScesimModelDescriptor()); ValueWrapper nullValue = extractorFunction1.apply(new Person()); assertTrue(nullValue.isValid()); assertNull(nullValue.getValue()); }