private static boolean isFieldAnnotated(final Field field) { return (fieldIsAnnotatedCorrectly(field)); }
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 boolean fieldIsAnnotated(final Field aField) { Steps fieldAnnotation = annotationFrom(aField); return (fieldAnnotation != null); }
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); } }
/** * Find the fields in the class annotated with the <b>Step</b> annotation. */ public static List<StepsAnnotatedField> findOptionalAnnotatedFields(final Class<?> clazz) { List<StepsAnnotatedField> annotatedFields = new ArrayList<StepsAnnotatedField>(); for (Field field : Fields.of(clazz).allFields()) { if (fieldIsAnnotated(field)) { annotatedFields.add( new StepsAnnotatedField(field)); } } return annotatedFields; }
/** * Instantiates the step scenario fields in a test case. */ public static void injectScenarioStepsInto(final Object testCase, final StepFactory stepFactory) { List<StepsAnnotatedField> stepsFields = StepsAnnotatedField.findOptionalAnnotatedFields(testCase.getClass()); instanciateScenarioStepFields(testCase, stepFactory, stepsFields); }
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); } }
public void setValue(final Object testCase, final Object steps) { try { set(testCase).to(steps); } catch (IllegalAccessException e) { throw new InvalidStepsFieldException("Could not access or set @Steps field: " + field, e); } }
private static Steps annotationFrom(final Field aField) { Steps annotationOnField = null; if (isFieldAnnotated(aField)) { annotationOnField = aField.getAnnotation(Steps.class); } return annotationOnField; }
/** * Find the fields in the class annotated with the <b>Step</b> annotation. */ public static List<StepsAnnotatedField> findOptionalAnnotatedFields(final Class<?> clazz) { List<StepsAnnotatedField> annotatedFields = new ArrayList<StepsAnnotatedField>(); for (Field field : Fields.of(clazz).allFields()) { if (fieldIsAnnotated(field)) { annotatedFields.add( new StepsAnnotatedField(field)); } } return annotatedFields; }
/** * Instantiates the step scenario fields in a test case. */ public static void injectScenarioStepsInto(final Object testCase, final StepFactory stepFactory) { List<StepsAnnotatedField> stepsFields = StepsAnnotatedField.findOptionalAnnotatedFields(testCase.getClass()); instanciateScenarioStepFields(testCase, stepFactory, stepsFields); }
public void setValue(final Object testCase, final Object steps) { try { set(testCase).to(steps); } catch (IllegalAccessException e) { throw new InvalidStepsFieldException("Could not access or set @Steps field: " + field, e); } }
private static Steps annotationFrom(final Field aField) { Steps annotationOnField = null; if (isFieldAnnotated(aField)) { annotationOnField = aField.getAnnotation(Steps.class); } return annotationOnField; }
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); } }
/** * Find the fields in the class annotated with the <b>Step</b> annotation. */ public static List<StepsAnnotatedField> findOptionalAnnotatedFields(final Class<?> clazz) { List<StepsAnnotatedField> annotatedFields = new ArrayList<StepsAnnotatedField>(); for (Field field : Fields.of(clazz).allFields()) { if (fieldIsAnnotated(field)) { annotatedFields.add( new StepsAnnotatedField(field)); } } return annotatedFields; }
/** * Instantiates the step scenario fields in a test case. */ void injectNestedScenarioStepsInto(final Object scenarioSteps, final StepFactory stepFactory, final Class<?> scenarioStepsClass) { List<StepsAnnotatedField> stepsFields = StepsAnnotatedField.findOptionalAnnotatedFields(scenarioStepsClass); instanciateScenarioStepFields(scenarioSteps, stepFactory, stepsFields); }
public void setValue(final Object field, final Object value) { try { set(field).to(value); } catch (IllegalAccessException e) { throw new InvalidStepsFieldException("Could not access or set field: " + field, e); } }
private static boolean isFieldAnnotated(final Field field) { return (fieldIsAnnotatedCorrectly(field)); }
private static boolean fieldIsAnnotated(final Field aField) { Steps fieldAnnotation = annotationFrom(aField); return (fieldAnnotation != null); }
/** * Find the first field in the class annotated with the <b>Managed</b> annotation. */ public static List<StepsAnnotatedField> findMandatoryAnnotatedFields(final Class<?> clazz) { List<StepsAnnotatedField> annotatedFields = findOptionalAnnotatedFields(clazz); if (annotatedFields.isEmpty()) { throw new InvalidStepsFieldException(NO_ANNOTATED_FIELD_ERROR); } return annotatedFields; }