Skip to content

add required parameter to FromContext annotation#93

Merged
valfirst merged 2 commits into
jbehave:masterfrom
groov1kk:add-non-required-parameter
Mar 5, 2026
Merged

add required parameter to FromContext annotation#93
valfirst merged 2 commits into
jbehave:masterfrom
groov1kk:add-non-required-parameter

Conversation

@groov1kk

@groov1kk groov1kk commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

Added boolean required property for the @FromContext annotation.

In case of required=false and absence of a specific property in the context, the default value would be returned (null, false, 0, 0L, etc., depending on the property type) instead of ObjectNotStoredException.

For example:

// None of these values were set in context
public void myAwesomeStep(
        @FromContext(value="myStringKey", required=false) String stringValue,
        @FromContext(value="myIntKey", required=false) int intValue,
        @FromContext(value="myDoubleKey", required=false) double doubleValue,
) {
    System.out.println(stringValue); // prints null
    System.out.println(intValue); // prints 0
    System.out.println(doubleValue); // prints 0.0
}

Comment thread jbehave-core/src/main/java/org/jbehave/core/steps/StepCreator.java
Comment thread jbehave-core/src/main/java/org/jbehave/core/steps/StepCreator.java Outdated
@groov1kk groov1kk force-pushed the add-non-required-parameter branch from 16872d2 to 69a8cde Compare March 2, 2026 11:38
@groov1kk groov1kk force-pushed the add-non-required-parameter branch from 69a8cde to e000fd7 Compare March 2, 2026 11:45
@valfirst valfirst linked an issue Mar 5, 2026 that may be closed by this pull request
@valfirst valfirst merged commit 52c055e into jbehave:master Mar 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do we really need ObjectNotStoredException?

3 participants