forked from TNG/JGiven
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend @as with a provider mechanism.
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
- Loading branch information
Showing
6 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
jgiven-core/src/main/java/com/tngtech/jgiven/annotation/AsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.tngtech.jgiven.annotation; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Provides a representation of a stage method, scenario or scenario class. | ||
* @since 0.12.0 | ||
*/ | ||
public interface AsProvider { | ||
|
||
/** | ||
* Provide the representation for a stage method or scenario. | ||
* @param annotation The {@link As} annotation using this provider. | ||
* @param method The method of which a representation is requested. | ||
* @return A representation of the method. | ||
* | ||
* @since 0.12.0 | ||
*/ | ||
String as( As annotation, Method method ); | ||
|
||
/** | ||
* Provide the representation for a scenario class. | ||
* @param annotation The {@link As} annotation using this provider. | ||
* @param scenarioClass The scenario class of which a representation is requested. | ||
* @return A representation of the scenario class. | ||
* | ||
* @since 0.12.0 | ||
*/ | ||
String as( As annotation, Class<?> scenarioClass ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
jgiven-core/src/main/java/com/tngtech/jgiven/impl/params/DefaultAsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.tngtech.jgiven.impl.params; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import com.tngtech.jgiven.annotation.As; | ||
import com.tngtech.jgiven.annotation.AsProvider; | ||
|
||
/** | ||
* The default provider for a stage method, scenario or scenario class. | ||
* | ||
*/ | ||
public class DefaultAsProvider implements AsProvider { | ||
|
||
/** | ||
* Returns the value of the {@link As} annotation. | ||
*/ | ||
@Override | ||
public String as( As annotation, Method method ) { | ||
return annotation.value(); | ||
} | ||
|
||
/** | ||
* Returns the value of the {@link As} annotation. | ||
*/ | ||
@Override | ||
public String as( As annotation, Class<?> scenarioClass ) { | ||
return annotation.value(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters