Skip to content

Commit

Permalink
use full class name as ID of a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Oct 9, 2016
1 parent 4af39dd commit cf096af
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public class TagConfiguration {
private final String annotationType;
private final String annotationFullType;
private boolean ignoreValue;
private boolean explodeArray = true;
private boolean prependType;
Expand All @@ -33,6 +34,7 @@ public class TagConfiguration {

public TagConfiguration( Class<? extends Annotation> tagAnnotation ) {
this.annotationType = tagAnnotation.getSimpleName();
this.annotationFullType = tagAnnotation.getName();
}

public static Builder builder( Class<? extends Annotation> tagAnnotation ) {
Expand Down Expand Up @@ -218,6 +220,10 @@ public String getAnnotationType() {
return annotationType;
}

public String getAnnotationFullType() {
return annotationFullType;
}

/**
* @see com.tngtech.jgiven.annotation.IsTag#href
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ public List<Tag> toTags( Annotation annotation ) {
}

private List<Tag> toTags( TagConfiguration tagConfig, Optional<Annotation> annotation ) {
Tag tag = new Tag( tagConfig.getAnnotationType() );
Tag tag = new Tag( tagConfig.getAnnotationFullType() );

tag.setType( tagConfig.getAnnotationType() );

if( !Strings.isNullOrEmpty( tagConfig.getName() ) ) {
tag.setName( tagConfig.getName() );
Expand Down
44 changes: 29 additions & 15 deletions jgiven-core/src/main/java/com/tngtech/jgiven/report/model/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
*/
public class Tag {
/**
* The type of the annotation of the tag
* The full type of the annotation of the tag
*/
private final String type;
private final String fullType;

/**
* The simple type of the annotation of the tag
*/
private String type;

/**
* An optional name of the tag. If not set, the type is the name
Expand Down Expand Up @@ -75,17 +80,17 @@ public class Tag {
*/
private Boolean hideInNav;

public Tag( String type ) {
this.type = type;
public Tag( String fullType ) {
this.fullType = fullType;
}

public Tag( String type, Object value ) {
this( type );
public Tag( String fullType, Object value ) {
this( fullType );
this.value = value;
}

public Tag( String type, String name, Object value ) {
this( type, value );
public Tag( String fullType, String name, Object value ) {
this( fullType, value );
this.name = name;
}

Expand Down Expand Up @@ -137,6 +142,14 @@ public String getStyle() {
return style;
}

public void setType( String type ) {
this.type = type;
}

public String getType() {
return type;
}

public String getHref() {
return href;
}
Expand Down Expand Up @@ -194,14 +207,14 @@ public String getValueString() {

public String toIdString() {
if( value != null ) {
return type + "-" + getValueString();
return fullType + "-" + getValueString();
}
return type;
return fullType;
}

@Override
public int hashCode() {
return Objects.hashCode( getType(), getName(), value );
return Objects.hashCode( getFullType(), getName(), value );
}

@Override
Expand All @@ -216,7 +229,7 @@ public boolean equals( Object obj ) {
return false;
}
Tag other = (Tag) obj;
return Objects.equal( getType(), other.getType() )
return Objects.equal( getFullType(), other.getFullType() )
&& Objects.equal( getName(), other.getName() )
&& Objects.equal( value, other.value );
}
Expand All @@ -242,8 +255,8 @@ public void setName( String name ) {
this.name = name;
}

public String getType() {
return type;
public String getFullType() {
return fullType;
}

public boolean getShownInNavigation() {
Expand All @@ -264,7 +277,8 @@ public void setTags( List<String> tags ) {
}

public Tag copy() {
Tag tag = new Tag( type, name, value );
Tag tag = new Tag( fullType, name, value );
tag.type = this.type;
tag.cssClass = this.cssClass;
tag.color = this.color;
tag.style = this.style;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testAnnotationWithName() throws Exception {
Tag tag = tags.get( 0 );
assertThat( tag.getName() ).isEqualTo( "AnotherName" );
assertThat( tag.getValues() ).isEmpty();
assertThat( tag.toIdString() ).isEqualTo( "AnnotationWithName" );
assertThat( tag.toIdString() ).isEqualTo( this.getClass().getName() + "$AnnotationWithName" );
}

@IsTag( ignoreValue = true )
Expand All @@ -110,7 +110,7 @@ public void testAnnotationWithIgnoredValueParsing() throws Exception {
Tag tag = tags.get( 0 );
assertThat( tag.getName() ).isEqualTo( "AnnotationWithIgnoredValue" );
assertThat( tag.getValues() ).isEmpty();
assertThat( tag.toIdString() ).isEqualTo( "AnnotationWithIgnoredValue" );
assertThat( tag.toIdString() ).isEqualTo( this.getClass().getName() + "$AnnotationWithIgnoredValue" );
}

@IsTag
Expand Down Expand Up @@ -206,7 +206,7 @@ public void testAnnotationWithParentTag() throws Exception {
List<Tag> tags = getScenarioModelBuilder().toTags( AnnotationWithParentTag.class.getAnnotations()[0] );
assertThat( tags ).hasSize( 1 );
assertThat( tags.get( 0 ).getTags() ).containsAll( Arrays.asList(
"ParentTag", "ParentTagWithValue-SomeValue" ) );
this.getClass().getName() + "$ParentTag", this.getClass().getName() + "$ParentTagWithValue-SomeValue" ) );
}

@IsTag( value = "default" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void configured_tags_are_reported() throws Throwable {
assertThat( tagIds ).isNotEmpty();
String tagId = tagIds.get( 0 );
assertThat( tagId ).isNotNull();
assertThat( tagId ).isEqualTo( "ConfiguredTag-Test" );
assertThat( tagId ).isEqualTo( ConfiguredTag.class.getName() + "-Test" );
}

@Test
Expand Down Expand Up @@ -333,7 +333,7 @@ public void tags_can_be_added_using_the_current_scenario() {

List<String> tagIds = getScenario().getScenarioModel().getTagIds();
assertThat( tagIds ).hasSize( 1 );
assertThat( tagIds.get( 0 ) ).isEqualTo( "DynamicTag-value" );
assertThat( tagIds.get( 0 ) ).isEqualTo( this.getClass().getName() + "$DynamicTag-value" );
}

static abstract class AbstractStage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void annotations_are_translated_to_tags() throws Throwable {
assertThat( model.getTagIds() ).hasSize( 1 );

String tagId = model.getTagIds().get( 0 );
assertThat( tagId ).isEqualTo( "TestTag-foo, bar, baz" );
assertThat( tagId ).isEqualTo( this.getClass().getName() + "$TestTag-foo, bar, baz" );

Tag tag = reportModel.getTagWithId( tagId );
assertThat( tag ).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void tag_on_step_method_is_recognized() throws Throwable {

getScenario().finished();

assertThat( getScenario().getModel().getTagMap().keySet() ).contains( "StepMethodTag" );
assertThat( getScenario().getModel().getTagMap().keySet() ).contains( "com.tngtech.jgiven.junit.test.GivenTestStep$StepMethodTag" );
}

@Test
Expand All @@ -46,6 +46,6 @@ public void tag_on_stage_class_is_recognized() throws Throwable {

getScenario().finished();

assertThat( getScenario().getModel().getTagMap().keySet() ).contains( "StageTag" );
assertThat( getScenario().getModel().getTagMap().keySet() ).contains( "com.tngtech.jgiven.junit.test.GivenTaggedTestStep$StageTag" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ensure_all_tags_are_found() throws Throwable {
getScenario().finished();

List<String> tagIds = getScenario().getModel().getLastScenarioModel().getTagIds();
assertThat( tagIds ).containsAll( Arrays.asList( "TestTag" ) );
assertThat( tagIds ).containsAll( Arrays.asList( TestTag.class.getName() ) );

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public SELF the_first_scenario_has_tag( @Quoted String name ) {

public SELF scenario_$_has_tag_$_with_value_$( int i, String name, String value ) {
latestTag = new Tag( name, value ).setPrependType( true );
latestTag.setType( name );
reportModel.getScenarios().get( i - 1 ).addTag( latestTag );
reportModel.addTag( latestTag );
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void tag_annotations_appear_in_the_report_model() {
given().a_test()
.and().the_test_has_a_tag_annotation_named( "TestTag" );
when().the_test_is_executed_with( testFramework );
then().the_report_model_contains_a_tag_named( "TestTag" );
then().the_report_model_contains_a_tag_named( "com.tngtech.jgiven.tests.TestTag" );
}

@Test
Expand Down

0 comments on commit cf096af

Please sign in to comment.