How to use DefaultTagDescriptionGenerator class of com.tngtech.jgiven.impl.tag package

Best JGiven code snippet using com.tngtech.jgiven.impl.tag.DefaultTagDescriptionGenerator

Source:AnnotationTagUtilsTest.java Github

copy

Full Screen

...7import org.junit.jupiter.api.Test;8import org.mockito.Mockito;9import com.tngtech.jgiven.config.TagConfiguration;10import com.tngtech.jgiven.exception.JGivenWrongUsageException;11import com.tngtech.jgiven.impl.tag.DefaultTagDescriptionGenerator;12import com.tngtech.jgiven.impl.tag.DefaultTagHrefGenerator;13import com.tngtech.jgiven.report.model.Tag;14class AnnotationTagUtilsTest {15 @DisplayName("An empty list should be returned when tag config is empty")16 @Test17 void shouldReturnEmptyResultWhenTagConfigIsNull() {18 List<Tag> tags = AnnotationTagUtils.toTags(null, null);19 Assertions.assertThat(tags)20 .isEmpty();21 }22 @DisplayName("Tags should be created despite that annotation does not have a value")23 @Test24 void shouldCreateTagsDespiteAnnotationHavingNoValue() {25 Annotation annotation = new AnnotationWithNoValue();26 TagConfiguration tagConfiguration = Mockito.mock(TagConfiguration.class);27 Mockito.when(tagConfiguration.getDescriptionGenerator())28 .thenAnswer(invocation -> DefaultTagDescriptionGenerator.class);29 Mockito.when(tagConfiguration.getDescription())30 .thenReturn("another value");31 Mockito.when(tagConfiguration.getHrefGenerator())32 .thenAnswer(invocation -> DefaultTagHrefGenerator.class);33 Mockito.when(tagConfiguration.getHref())34 .thenReturn("another value");35 Mockito.when(tagConfiguration.isIgnoreValue())36 .thenReturn(false);37 List<Tag> tags = AnnotationTagUtils.toTags(tagConfiguration, annotation);38 Assertions.assertThat(tags)39 .isNotEmpty();40 }41 @DisplayName("Tags should be created despite that annotation hypothetically has value, but in reality does not")42 @Test43 void shouldCreateTagsDespiteMethodMismatch() {44 Annotation annotation = Mockito.mock(AnnotationWithNoValue.class);45 Mockito.when(annotation.annotationType())46 .thenAnswer(invocation -> DummyAnnotation.class);47 TagConfiguration tagConfiguration = Mockito.mock(TagConfiguration.class);48 Mockito.when(tagConfiguration.getDescriptionGenerator())49 .thenAnswer(invocation -> DefaultTagDescriptionGenerator.class);50 Mockito.when(tagConfiguration.getDescription())51 .thenReturn("another value");52 Mockito.when(tagConfiguration.getHrefGenerator())53 .thenAnswer(invocation -> DefaultTagHrefGenerator.class);54 Mockito.when(tagConfiguration.getHref())55 .thenReturn("another value");56 Mockito.when(tagConfiguration.isIgnoreValue())57 .thenReturn(false);58 List<Tag> tags = AnnotationTagUtils.toTags(tagConfiguration, annotation);59 Assertions.assertThat(tags)60 .isNotEmpty();61 }62 @DisplayName("An description should be created using given generator")63 @Test64 void shouldCreateDescription() {65 TagConfiguration tagConfiguration = Mockito.mock(TagConfiguration.class);66 Mockito.when(tagConfiguration.getDescriptionGenerator())67 .thenAnswer(invocation -> DefaultTagDescriptionGenerator.class);68 Mockito.when(tagConfiguration.getDescription())69 .thenReturn("another value");70 Annotation annotation = Mockito.mock(Annotation.class);71 String value = "value";72 String description = AnnotationTagUtils.getDescriptionFromGenerator(tagConfiguration, annotation, value);73 Assertions.assertThat(description)74 .isEqualTo("another value");75 }76 @DisplayName("A JGiven exception should be thrown when a description generator cannot be instantiated")77 @Test78 void shouldThrowAJGivenExceptionOnDescriptionCreationError() {79 TagConfiguration tagConfiguration = Mockito.mock(TagConfiguration.class);80 Mockito.when(tagConfiguration.getDescriptionGenerator())81 .thenAnswer(invocation -> UnexpectedGenerator.class);82 Annotation annotation = Mockito.mock(Annotation.class);83 Mockito.when(annotation.toString())84 .thenReturn("Mock");85 String value = "value";86 Assertions.assertThatThrownBy(() ->87 AnnotationTagUtils.getDescriptionFromGenerator(tagConfiguration, annotation, value))88 .isInstanceOf(JGivenWrongUsageException.class)89 .hasMessage("Error while trying to generate the description for annotation Mock using DescriptionGenerator class class xyz.multicatch.mockgiven.core.annotations.tag.UnexpectedGenerator: xyz.multicatch.mockgiven.core.annotations.tag.UnexpectedGenerator. This exception indicates that you used JGiven in a wrong way. Please consult the JGiven documentation at http://jgiven.org/docs and the JGiven API documentation at http://jgiven.org/javadoc/ for further information.");90 }91 @DisplayName("An href should be created using given generator")92 @Test93 void shouldCreateHref() {94 TagConfiguration tagConfiguration = Mockito.mock(TagConfiguration.class);95 Mockito.when(tagConfiguration.getHrefGenerator())96 .thenAnswer(invocation -> DefaultTagHrefGenerator.class);97 Mockito.when(tagConfiguration.getHref())98 .thenReturn("another value");99 Annotation annotation = Mockito.mock(Annotation.class);100 String value = "value";101 String description = AnnotationTagUtils.getHref(tagConfiguration, annotation, value);102 Assertions.assertThat(description)103 .isEqualTo("another value");104 }105 @DisplayName("A JGiven exception should be thrown when an href generator cannot be instantiated")106 @Test107 void shouldThrowAJGivenExceptionOnHrefCreationError() {108 TagConfiguration tagConfiguration = Mockito.mock(TagConfiguration.class);109 Mockito.when(tagConfiguration.getHrefGenerator())110 .thenAnswer(invocation -> UnexpectedGenerator.class);111 Annotation annotation = Mockito.mock(Annotation.class);112 Mockito.when(annotation.toString())113 .thenReturn("Mock");114 String value = "value";115 Assertions.assertThatThrownBy(() ->116 AnnotationTagUtils.getHref(tagConfiguration, annotation, value))117 .isInstanceOf(JGivenWrongUsageException.class)118 .hasMessage("Error while trying to generate the href for annotation Mock using HrefGenerator class class xyz.multicatch.mockgiven.core.annotations.tag.UnexpectedGenerator: xyz.multicatch.mockgiven.core.annotations.tag.UnexpectedGenerator. This exception indicates that you used JGiven in a wrong way. Please consult the JGiven documentation at http://jgiven.org/docs and the JGiven API documentation at http://jgiven.org/javadoc/ for further information.");119 }120 @DisplayName("Exploded tags list should be created")121 @Test122 void shouldCreateExplodedTags() {123 Tag originalTag = new Tag(124 "xyz.multicatch.mockgiven.core.annotations.tag.SampleTag",125 "MockedTag",126 "value"127 );128 String[] values = new String[2];129 values[0] = "abc";130 values[1] = "def";131 Annotation annotation = Mockito.mock(Annotation.class);132 TagConfiguration tagConfiguration = Mockito.mock(TagConfiguration.class);133 Mockito.when(tagConfiguration.getDescriptionGenerator())134 .thenAnswer(invocation -> DefaultTagDescriptionGenerator.class);135 Mockito.when(tagConfiguration.getDescription())136 .thenReturn("another value");137 Mockito.when(tagConfiguration.getHrefGenerator())138 .thenAnswer(invocation -> DefaultTagHrefGenerator.class);139 Mockito.when(tagConfiguration.getHref())140 .thenReturn("another value");141 List<Tag> explodedTags = AnnotationTagUtils.getExplodedTags(originalTag, values, annotation, tagConfiguration);142 Assertions.assertThat(explodedTags)143 .hasSize(2);144 Assertions.assertThat(explodedTags.get(0))145 .extracting(146 "fullType",147 "type",148 "name",...

Full Screen

Full Screen

Source:TagConfiguration.java Github

copy

Full Screen

1package com.tngtech.jgiven.config;2import com.google.common.collect.Lists;3import com.tngtech.jgiven.annotation.TagDescriptionGenerator;4import com.tngtech.jgiven.annotation.TagHrefGenerator;5import com.tngtech.jgiven.impl.tag.DefaultTagDescriptionGenerator;6import com.tngtech.jgiven.impl.tag.DefaultTagHrefGenerator;7import java.lang.annotation.Annotation;8import java.util.List;9/**10 * Represents the configuration of a tag.11 *12 * @see com.tngtech.jgiven.annotation.IsTag for a documentation of the different values.13 */14public class TagConfiguration {15 private final String annotationType;16 private final String annotationFullType;17 private boolean ignoreValue;18 private boolean explodeArray = true;19 private boolean prependType;20 private String defaultValue = "";21 private String description = "";22 private String color = "";23 private String cssClass = "";24 private String style = "";25 private Class<? extends TagDescriptionGenerator> descriptionGenerator = DefaultTagDescriptionGenerator.class;26 private String name = "";27 private List<String> tags = Lists.newArrayList();28 private String href = "";29 private Class<? extends TagHrefGenerator> hrefGenerator = DefaultTagHrefGenerator.class;30 private boolean showInNavigation = true;31 public TagConfiguration( Class<? extends Annotation> tagAnnotation ) {32 this.annotationType = tagAnnotation.getSimpleName();33 this.annotationFullType = tagAnnotation.getName();34 }35 public static Builder builder( Class<? extends Annotation> tagAnnotation ) {36 return new Builder( new TagConfiguration( tagAnnotation ) );37 }38 public static class Builder {39 final TagConfiguration configuration;...

Full Screen

Full Screen

Source:SampleTag.java Github

copy

Full Screen

...3import java.lang.annotation.Retention;4import java.lang.annotation.RetentionPolicy;5import java.lang.annotation.Target;6import com.tngtech.jgiven.annotation.IsTag;7import com.tngtech.jgiven.impl.tag.DefaultTagDescriptionGenerator;8import com.tngtech.jgiven.impl.tag.DefaultTagHrefGenerator;9@Target(ElementType.TYPE)10@Retention(RetentionPolicy.RUNTIME)11@IsTag(12 explodeArray = false,13 ignoreValue = true,14 value = "Tag value",15 description = "Sophisticated description",16 descriptionGenerator = DefaultTagDescriptionGenerator.class,17 name = "Tag name",18 prependType = true,19 cssClass = "tag-class",20 color = "blue",21 style = "nice",22 href = "http://multicatch.xyz",23 hrefGenerator = DefaultTagHrefGenerator.class,24 showInNavigation = false25)26public @interface SampleTag {27}...

Full Screen

Full Screen

DefaultTagDescriptionGenerator

Using AI Code Generation

copy

Full Screen

1public class DefaultTagDescriptionGeneratorTest {2 public void testDefaultTagDescriptionGenerator() {3 DefaultTagDescriptionGenerator defaultTagDescriptionGenerator = new DefaultTagDescriptionGenerator();4 String tagDescription = defaultTagDescriptionGenerator.generateTagDescription( "testTagDescription" );5 assertThat(tagDescription).isEqualTo( "Test Tag Description" );6 }7}

Full Screen

Full Screen

DefaultTagDescriptionGenerator

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.impl.tag;2import java.util.List;3import com.tngtech.jgiven.annotation.Description;4import com.tngtech.jgiven.annotation.IsTag;5import com.tngtech.jgiven.impl.util.WordUtil;6@Description( "This is the default tag description generator." )7public class DefaultTagDescriptionGenerator implements TagDescriptionGenerator {8 public String getDescription( Class< ? > tagClass ) {9 Description description = tagClass.getAnnotation( Description.class );10 if( description != null ) {11 return description.value();12 } else {13 return WordUtil.splitCamelCase( tagClass.getSimpleName() );14 }15 }16 public List< String > getValues( Class< ? > tagClass ) {17 IsTag isTag = tagClass.getAnnotation( IsTag.class );18 if( isTag != null ) {19 return Arrays.asList( isTag.value() );20 } else {21 return Collections.emptyList();22 }23 }24}25package com.tngtech.jgiven.impl.tag;26import java.util.List;27import com.tngtech.jgiven.annotation.Description;28import com.tngtech.jgiven.annotation.IsTag;29import com.tngtech.jgiven.impl.util.WordUtil;30@Description( "This is the default tag description generator." )31public class DefaultTagDescriptionGenerator implements TagDescriptionGenerator {32 public String getDescription( Class< ? > tagClass ) {33 Description description = tagClass.getAnnotation( Description.class );34 if( description != null ) {35 return description.value();36 } else {37 return WordUtil.splitCamelCase( tagClass.getSimpleName() );38 }39 }40 public List< String > getValues( Class< ? > tagClass ) {41 IsTag isTag = tagClass.getAnnotation( IsTag.class );42 if( isTag != null ) {43 return Arrays.asList( isTag.value() );44 } else {45 return Collections.emptyList();46 }47 }48}49package com.tngtech.jgiven.impl.tag;50import java.util.List;51import com.tngtech.jgiven.annotation.Description;52import com.tngtech.jgiven.annotation.Is

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JGiven automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in DefaultTagDescriptionGenerator

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful