Skip to content

Add ParameterType.fromEnum(Class enumClass) - #423

Merged
mpkorstanje merged 2 commits into
masterfrom
cucumber-expressions-enum-simplification
Jul 27, 2018
Merged

Add ParameterType.fromEnum(Class enumClass)#423
mpkorstanje merged 2 commits into
masterfrom
cucumber-expressions-enum-simplification

Conversation

@aslakhellesoy

Copy link
Copy Markdown
Contributor

Summary

Simplify creation of ParameterType from an enum class

Details

The enum constants' names are used to build a regexp for the match (red|green|blue), and the name is the simplified name of the enum class (Color).

Motivation and Context

See cucumber/cucumber-jvm#1393 (comment)

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • I've added tests for my code.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@Test
public void converts_to_enum() {
ParameterTypeRegistry registry = new ParameterTypeRegistry(Locale.ENGLISH);
registry.defineParameterType(ParameterType.fromEnum(Mood.class));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this a parameter type fromEnum or forEnum?

When using a static import I think registry.defineParameterType(forEnum(Mood.class)); reads a bit better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OTOH: fromEnum is kinda the well known standard.

@mpkorstanje
mpkorstanje merged commit bea3046 into master Jul 27, 2018
@mpkorstanje
mpkorstanje deleted the cucumber-expressions-enum-simplification branch July 27, 2018 11:15
aslakhellesoy added a commit that referenced this pull request Aug 29, 2018
@lock

lock Bot commented Jul 27, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Jul 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants