private void ensureThatThisFieldIsNotCyclicOrRecursive(StepsAnnotatedField stepsAnnotatedField) { StackTraceElement[] stackTrace = new Exception().getStackTrace(); long levelsOfNesting = Stream.of(stackTrace).filter( element -> element.getMethodName().equals("instantiateAnyUnitiaializedSteps")) .count(); int maxAllowedNesting = SERENITY_MAXIMUM_STEP_NESTING_DEPTH.integerFrom(environmentVariables, 32); if (levelsOfNesting > maxAllowedNesting) { String message = String.format( "A recursive or cyclic reference was detected for the @Steps-annotated field %s in class %s. " + "You may need to use @Steps(shared=true) to ensure that the same step library instance is used everywhere.", stepsAnnotatedField.getFieldName(), stepsAnnotatedField.getFieldClass().getName()); throw new RecursiveOrCyclicStepLibraryReferenceException(message); } }
private static void instantiateAnyUnitiaializedSteps(Object testCaseOrSteps, StepFactory stepFactory, StepsAnnotatedField stepsField) { if (!stepsField.isInstantiated(testCaseOrSteps)) { Class<?> scenarioStepsClass = stepsField.getFieldClass(); Object steps = stepFactory.getStepLibraryFor(scenarioStepsClass); stepsField.setValue(testCaseOrSteps, steps); injectNestedScenarioStepsInto(steps, stepFactory, scenarioStepsClass); } }
private static void instantiateAnyUnitiaializedSteps(Object testCaseOrSteps, StepFactory stepFactory, StepsAnnotatedField stepsField) { if (!stepsField.isInstantiated(testCaseOrSteps)) { Class<?> scenarioStepsClass = stepsField.getFieldClass(); Object steps = stepFactory.getStepLibraryFor(scenarioStepsClass); stepsField.setValue(testCaseOrSteps, steps); injectNestedScenarioStepsInto(steps, stepFactory, scenarioStepsClass); } }
private void instantiateAnyUnitiaializedSteps(Object testCaseOrSteps, StepFactory stepFactory, StepsAnnotatedField stepsField) { if (!stepsField.isInstantiated(testCaseOrSteps)) { ensureThatThisFieldIsNotCyclicOrRecursive(stepsField); Class<?> scenarioStepsClass = stepsField.getFieldClass(); Object steps = StepLibraryCreator.usingConfiguredCreationStrategy(stepFactory, stepsField, environmentVariables) .initiateStepsFor(scenarioStepsClass); stepsField.setValue(testCaseOrSteps, steps); stepsField.assignActorNameIn(steps); injectNestedScenarioStepsInto(steps, stepFactory, scenarioStepsClass); } }