Given i have a cucumber feature
When I run the feature from my java class with annotations to a certain package
Then cucumber knows to go and find the right class
But how is it doing this?
If i duplicate the class, then it seems to run it twice (and blew up, I didn't really investigate). Does it just look in the package for any method that matches via annotation/java8-naming? Or does something else happen?
I'm curious because what if you have two Given for different scenarios, but the classes are in the same package - is that a problem? Is there a solution?
The mapping between Java and Gherkin is done the other way around. That is, the regular expressions the Java methods are annotated with are used to find matching steps.
If you have two Givens that are the same, the same Java method will be executed. This means that you can't have two Java methods annotated the exact same way. The error you will get is an ambiguous step. But when you think about it, getting an error may not be your biggest problem. If you say the same thing at two places in your system and mean two different things, then you probably have a bigger problem than an error complaining about an ambiguous steps.
The solution? Divide your system. If you want, you can see the stuff in say one module as a bounded context end mean the exact thing everywhere in that context. If you create a new module, it is possible to view it as another bounded context and use the same words to mean a different thing.