Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend @As with a provider mechanism. #215

Merged
merged 3 commits into from
Jul 12, 2016
Merged

Conversation

Airblader
Copy link
Contributor

This change extends the @as annotation for step / stage methods and classes
with an AsProvider provider() method to allow a more flexible way of
customizing the result.

fixes #189

@Airblader
Copy link
Contributor Author

Airblader commented Jul 11, 2016

Obviously missing things:

  • Documentation
  • Make it more like CaseDescriptionGenerator with the special NO_VALUE value to (somehow) expose the nameWithSpaces functionality (and update the documentation).
  • Tests

@janschaefer I liked having two separate as() methods for the method versus class cases better. In fact, we could we even differentiate between calling this for a step method and for a test method, since the annotation works on both. Should we?

This change extends the @as annotation for step / stage methods and classes
with an AsProvider provider() method to allow a more flexible way of
customizing the result.

fixes TNG#189
This patch changes the behavior for the DefaultAsProvider by moving the
case of absent @as annotations into the provider. This allows us to just
fall back to the default provider and allows users to utilize the default
behavior by extending from DefaultAsProvider.

relates to TNG#189
@Airblader
Copy link
Contributor Author

@janschaefer OK, you can take a look at it now.

return annotation.value();
}

String methodName = method.getName();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think one can make either argument for or against having this in the DefaultAsProvider. My rationale is that this way, a user can extend from this provider and utilize this, e.g., in the spirit of the original motivation for #189:

@As( provider = ReplaceTodayProvider.class )
public SELF a_request_with_request_date_TODAY() { … }

public static class ReplaceTodayProvider extends DefaultAsProvider {
    @Override
    public String as( As annotation, Method method ) {
        String words = super.as( annotation, method );
        return String.replace( "TODAY", formatDate( new Date() ) );
    }
}

@Airblader
Copy link
Contributor Author

@janschaefer Updated.

@Airblader Airblader force-pushed the feature-189 branch 3 times, most recently from 9a38d8f to a1a8b0f Compare July 12, 2016 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format step method dynamically without parameters
2 participants