-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement description generator (#55)
- Loading branch information
Jan Schäfer
committed
Jan 18, 2015
1 parent
7fa92d7
commit b43561c
Showing
8 changed files
with
175 additions
and
24 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
jgiven-core/src/main/java/com/tngtech/jgiven/annotation/DefaultTagDescriptionGenerator.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,18 @@ | ||
package com.tngtech.jgiven.annotation; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import com.tngtech.jgiven.config.TagConfiguration; | ||
|
||
/** | ||
* A default implementation of {@link com.tngtech.jgiven.annotation.TagDescriptionGenerator}. | ||
* It just calls {@code tagConfiguration.getDescription()}. | ||
* | ||
* @since v0.6.3 | ||
*/ | ||
public class DefaultTagDescriptionGenerator implements TagDescriptionGenerator { | ||
@Override | ||
public String generateDescription( TagConfiguration tagConfiguration, Annotation annotation, Object value ) { | ||
return tagConfiguration.getDescription(); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
jgiven-core/src/main/java/com/tngtech/jgiven/annotation/TagDescriptionGenerator.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,35 @@ | ||
package com.tngtech.jgiven.annotation; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import com.tngtech.jgiven.config.TagConfiguration; | ||
|
||
/** | ||
* Is used as an attribute of the {@link com.tngtech.jgiven.annotation.IsTag} annotation | ||
* to dynamically generate a description for an annotation depending on its value. | ||
* <p> | ||
* Implementations of this interface must be a public non-abstract class that is not a non-static inner class | ||
* and must have a public default constructor. | ||
* </p> | ||
* | ||
* @since v0.6.3 | ||
*/ | ||
public interface TagDescriptionGenerator { | ||
|
||
/** | ||
* Implement this method to generate the description for the given annotation and its value. | ||
* <p> | ||
* Note that when the value of the annotation is an array and {@link com.tngtech.jgiven.annotation.IsTag#explodeArray()} | ||
* is {@code true}, then this method is called for each value of the array and not once for the whole array. | ||
* Otherwise it is called only once. | ||
* </p> | ||
* @param tagConfiguration the configuration of the tag. The values typically correspond to the {@link IsTag annotation}. | ||
* However, it is also possible to configure annotations to be tags using {@link com.tngtech.jgiven.annotation.JGivenConfiguration}, | ||
* in which case there is no {@link IsTag} annotation. | ||
* @param annotation the actual annotation that was used as a tag | ||
* @param value the value of the annotation. If the annotation has no value the default value is passed ({@link com.tngtech.jgiven.annotation.IsTag#value()} | ||
* | ||
* @return the description of the annotation for the given value | ||
*/ | ||
String generateDescription( TagConfiguration tagConfiguration, Annotation annotation, Object 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
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
16 changes: 16 additions & 0 deletions
16
jgiven-tests/src/main/java/com/tngtech/jgiven/tags/IssueDescriptionGenerator.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,16 @@ | ||
package com.tngtech.jgiven.tags; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import com.tngtech.jgiven.annotation.TagDescriptionGenerator; | ||
import com.tngtech.jgiven.config.TagConfiguration; | ||
|
||
public class IssueDescriptionGenerator implements TagDescriptionGenerator { | ||
private static final String ISSUE_URL = "https://github.com/TNG/JGiven/issues/"; | ||
|
||
@Override | ||
public String generateDescription( TagConfiguration tagConfiguration, Annotation annotation, Object value ) { | ||
String valueAsString = String.valueOf( value ); | ||
return String.format( "Scenarios of <a href='%s%s'>Issue %s</a>", ISSUE_URL, valueAsString.substring( 1 ), valueAsString ); | ||
} | ||
} |
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