Skip to content

Commit

Permalink
implement new attribute showInNavigation for the IsTag annotation (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Jul 2, 2016
1 parent 2aa1d00 commit be90df1
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 40 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# v0.12.0

## New Features

* Allow multiple formatter annotations on arguments, e.g., "@Quoted @YesNo", see [#204](https://github.com/TNG/JGiven/issues/204).
* Added a new comment() method to provide further information on specific step method invocations, see [#50](https://github.com/TNG/JGiven/issues/50).
* Steps can now have multiple attachments [#194](https://github.com/TNG/JGiven/issues/194).
* Tags can now be hidden from the navigation bar in the HTML report by setting the `showInNavigation` attribute to `false` [#211](https://github.com/TNG/JGiven/issues/211).

## Breaking Changes in the JSON model

* Due to the introduction of multiple attachments per step, the JSON model had to be changed in an backwards-incompatible way. Instead of a single field `attachment` that holds a single attachment object, a step has now an `attachments` field that holds an array of attachment objects.

# v0.11.4

Expand Down
23 changes: 15 additions & 8 deletions jgiven-core/src/main/java/com/tngtech/jgiven/annotation/IsTag.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.tngtech.jgiven.annotation;

import com.tngtech.jgiven.impl.tag.DefaultTagDescriptionGenerator;
import com.tngtech.jgiven.impl.tag.DefaultTagHrefGenerator;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.tngtech.jgiven.impl.tag.DefaultTagDescriptionGenerator;
import com.tngtech.jgiven.impl.tag.DefaultTagHrefGenerator;

/**
* Marks an annotation to be used as a tag in JGiven reports.
* The name and a possible value will be stored.
Expand Down Expand Up @@ -68,7 +68,7 @@
* <p>
* If this attribute is set, the {@link #description()} attribute is ignored.
* </p>
*
*
* @since 0.7.0
*/
Class<? extends TagDescriptionGenerator> descriptionGenerator() default DefaultTagDescriptionGenerator.class;
Expand Down Expand Up @@ -102,7 +102,7 @@
* <p>
* Non-HTML reports ignore this attribute
* </p>
*
*
* @since 0.7.2
*/
String cssClass() default "";
Expand All @@ -120,7 +120,7 @@
* This attribute is for simple use cases.
* For advanced styling options use the {@link #cssClass()} or {@link #style()} attributes instead.
* </p>
*
*
* @since 0.7.2
*/
String color() default "";
Expand All @@ -135,14 +135,14 @@
* <p>
* Non-HTML reports ignore this attribute
* </p>
*
*
* @since 0.8.0
*/
String style() default "";

/**
* An optional href of the tag that will appear in the generated report.
*
*
* @since 0.9.5
*/
String href() default "";
Expand All @@ -162,4 +162,11 @@
*/
Class<? extends TagHrefGenerator> hrefGenerator() default DefaultTagHrefGenerator.class;

/**
* Whether the tag should be shown in the navigation part of the report
*
* @since 0.12.0
*/
boolean showInNavigation() default true;

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.tngtech.jgiven.config;

import java.lang.annotation.Annotation;
import java.util.List;

import com.google.common.collect.Lists;
import com.tngtech.jgiven.annotation.TagDescriptionGenerator;
import com.tngtech.jgiven.annotation.TagHrefGenerator;
import com.tngtech.jgiven.impl.tag.DefaultTagDescriptionGenerator;
import com.tngtech.jgiven.annotation.TagDescriptionGenerator;
import com.tngtech.jgiven.impl.tag.DefaultTagHrefGenerator;

import java.lang.annotation.Annotation;
import java.util.List;

/**
* Represents the configuration of a tag.
*
*
* @see com.tngtech.jgiven.annotation.IsTag for a documentation of the different values.
*/
public class TagConfiguration {
Expand All @@ -29,6 +29,7 @@ public class TagConfiguration {
private List<String> tags = Lists.newArrayList();
private String href = "";
private Class<? extends TagHrefGenerator> hrefGenerator = DefaultTagHrefGenerator.class;
private boolean showInNavigation = true;

public TagConfiguration( Class<? extends Annotation> tagAnnotation ) {
this.annotationType = tagAnnotation.getSimpleName();
Expand Down Expand Up @@ -119,6 +120,11 @@ public Builder hrefGenerator( Class<? extends TagHrefGenerator> hrefGenerator )
return this;
}

public Builder showInNavigation( boolean value ) {
configuration.showInNavigation = value;
return this;
}

public TagConfiguration build() {
return configuration;
}
Expand Down Expand Up @@ -226,4 +232,11 @@ public Class<? extends TagHrefGenerator> getHrefGenerator() {
return hrefGenerator;
}

/**
* @see com.tngtech.jgiven.annotation.IsTag#showInNavigation
*/
public boolean showInNavigation() {
return showInNavigation;
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.tngtech.jgiven.impl;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.CaseFormat;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
Expand All @@ -26,6 +19,12 @@
import com.tngtech.jgiven.impl.util.ReflectionUtil;
import com.tngtech.jgiven.impl.util.WordUtil;
import com.tngtech.jgiven.report.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*;

public class ScenarioModelBuilder implements ScenarioListener {
private static final Logger log = LoggerFactory.getLogger( ScenarioModelBuilder.class );
Expand Down Expand Up @@ -412,6 +411,8 @@ public List<Tag> toTags( Annotation annotation ) {
tag.setPrependType( true );
}

tag.setShowInNavigation( tagConfig.showInNavigation() );

if( !Strings.isNullOrEmpty( tagConfig.getCssClass() ) ) {
tag.setCssClass( tagConfig.getCssClass() );
}
Expand Down Expand Up @@ -471,7 +472,8 @@ public TagConfiguration fromIsTag( IsTag isTag, Annotation annotation ) {
.explodeArray( isTag.explodeArray() ).ignoreValue( isTag.ignoreValue() ).prependType( isTag.prependType() ).name( name )
.descriptionGenerator( isTag.descriptionGenerator() ).cssClass( isTag.cssClass() ).color( isTag.color() )
.style( isTag.style() ).tags( getTagNames( isTag, annotation ) )
.href( isTag.href() ).hrefGenerator( isTag.hrefGenerator() ).build();
.href( isTag.href() ).hrefGenerator( isTag.hrefGenerator() )
.showInNavigation( isTag.showInNavigation() ).build();

}

Expand Down
29 changes: 23 additions & 6 deletions jgiven-core/src/main/java/com/tngtech/jgiven/report/model/Tag.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.tngtech.jgiven.report.model;

import java.util.Collections;
import java.util.List;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;

import java.util.Collections;
import java.util.List;

/**
* A tag represents a Java annotation of a scenario-test.
*/
Expand Down Expand Up @@ -35,7 +35,7 @@ public class Tag {
/**
* Whether the type should be prepended in the report.
* <p>
* Is either {@code true} or {@code null}
* Is either {@code true} or {@code null}
*/
private Boolean prependType;

Expand Down Expand Up @@ -68,6 +68,14 @@ public class Tag {
*/
private String href;

/**
* Whether the tag should appear in the navigation part of the report
* <p>
* Is either {@code true} or {@code null}
*/
private Boolean hideInNav;
private boolean shownInNavigation;

public Tag( String type ) {
this.type = type;
}
Expand Down Expand Up @@ -134,7 +142,7 @@ public String getHref() {
return href;
}

public void setHref(String href) {
public void setHref( String href ) {
this.href = href;
}

Expand Down Expand Up @@ -162,6 +170,10 @@ public Tag setPrependType( boolean prependType ) {
return this;
}

public void setShowInNavigation( boolean show ) {
this.hideInNav = show ? null : true;
}

@Override
public String toString() {
if( value != null ) {
Expand Down Expand Up @@ -213,7 +225,7 @@ public boolean equals( Object obj ) {
/**
* Returns a string representation where all non-alphanumeric characters are replaced with an underline (_).
* In addition, the result is cut-off at a length of 255 characters.
*
*
* @return a string representation without special characters
*/
public String toEscapedString() {
Expand All @@ -235,6 +247,10 @@ public String getType() {
return type;
}

public boolean getShownInNavigation() {
return shownInNavigation;
}

public List<String> getTags() {
if( tags == null ) {
return Collections.emptyList();
Expand All @@ -257,6 +273,7 @@ public Tag copy() {
tag.prependType = this.prependType;
tag.tags = this.tags;
tag.href = this.href;
tag.hideInNav = this.hideInNav;
return tag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void tags_can_form_a_hierarchy() {
then().the_tags_appear_in_a_hierarchy();
}

@TagThatIsNotVisibleInNavigation
@AnotherExampleSubCategory
@Test
public void parent_tags_can_have_values() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tngtech.jgiven.examples.tags;

import com.tngtech.jgiven.annotation.IsTag;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Used to be able to sort scenarios in the HMTL5 report
*/
@IsTag( showInNavigation = false )
@Retention( RetentionPolicy.RUNTIME )
public @interface TagThatIsNotVisibleInNavigation {
}
Loading

0 comments on commit be90df1

Please sign in to comment.