How to use getDescription method of com.tngtech.jgiven.report.model.Tag class

Best JGiven code snippet using com.tngtech.jgiven.report.model.Tag.getDescription

Source:ScenarioModelBuilder.java Github

copy

Full Screen

...108 currentStep = stepModel;109 }110 StepModel createStepModel(Method paramMethod, List<NamedArgument> arguments, InvocationMode mode) {111 StepModel stepModel = new StepModel();112 stepModel.setName(getDescription(paramMethod));113 ExtendedDescription extendedDescriptionAnnotation = paramMethod.getAnnotation(ExtendedDescription.class);114 if (extendedDescriptionAnnotation != null) {115 stepModel.setExtendedDescription(extendedDescriptionAnnotation.value());116 }117 List<NamedArgument> nonHiddenArguments =118 filterHiddenArguments(arguments, paramMethod.getParameterAnnotations());119 ParameterFormattingUtil parameterFormattingUtil = new ParameterFormattingUtil(configuration);120 List<ObjectFormatter<?>> formatters =121 parameterFormattingUtil.getFormatter(paramMethod.getParameterTypes(), getNames(arguments),122 paramMethod.getParameterAnnotations());123 new StepFormatter(stepModel.getName(), nonHiddenArguments, formatters).buildFormattedWords()124 .forEach(sentenceBuilder::addWord);125 stepModel.setWords(sentenceBuilder.getWords());126 sentenceBuilder.clear();127 stepModel.setStatus(mode.toStepStatus());128 return stepModel;129 }130 private List<NamedArgument> filterHiddenArguments(List<NamedArgument> arguments,131 Annotation[][] parameterAnnotations) {132 List<NamedArgument> result = Lists.newArrayList();133 for (int i = 0; i < parameterAnnotations.length; i++) {134 if (!AnnotationUtil.isHidden(parameterAnnotations[i])) {135 result.add(arguments.get(i));136 }137 }138 return result;139 }140 @Override141 public void introWordAdded(String value) {142 sentenceBuilder.addIntroWord(value);143 }144 private void addToSentence(String value, boolean joinToPreviousWord, boolean joinToNextWord) {145 if (!sentenceBuilder.hasWords() && currentStep != null && joinToPreviousWord) {146 currentStep.getLastWord().addSuffix(value);147 } else {148 sentenceBuilder.addWord(value, joinToPreviousWord, joinToNextWord);149 }150 }151 private void addStepComment(List<NamedArgument> arguments) {152 if (arguments == null || arguments.size() != 1) {153 throw new JGivenWrongUsageException("A step comment method must have exactly one parameter.");154 }155 if (!(arguments.get(0).getValue() instanceof String)) {156 throw new JGivenWrongUsageException("The step comment method parameter must be a string.");157 }158 if (currentStep == null) {159 throw new JGivenWrongUsageException("A step comment must be added after the corresponding step, "160 + "but no step has been executed yet.");161 }162 stepCommentUpdated((String) arguments.get(0).getValue());163 }164 @Override165 public void stepCommentUpdated(String comment) {166 currentStep.setComment(comment);167 }168 private ScenarioCaseModel getCurrentScenarioCase() {169 if (scenarioCaseModel == null) {170 scenarioStarted("A Scenario");171 }172 return scenarioCaseModel;173 }174 private void incrementDiscrepancy() {175 int discrepancyOnCurrentLayer = discrepancyOnLayer.pop();176 discrepancyOnCurrentLayer++;177 discrepancyOnLayer.push(discrepancyOnCurrentLayer);178 }179 private void decrementDiscrepancy() {180 if (discrepancyOnLayer.peek() > 0) {181 int discrepancyOnCurrentLayer = discrepancyOnLayer.pop();182 discrepancyOnCurrentLayer--;183 discrepancyOnLayer.push(discrepancyOnCurrentLayer);184 }185 }186 @Override187 public void stepMethodInvoked(Method method, List<NamedArgument> arguments, InvocationMode mode,188 boolean hasNestedSteps) {189 if (method.isAnnotationPresent(IntroWord.class)) {190 introWordAdded(getDescription(method));191 incrementDiscrepancy();192 } else if (method.isAnnotationPresent(FillerWord.class)) {193 FillerWord fillerWord = method.getAnnotation(FillerWord.class);194 addToSentence(getDescription(method), fillerWord.joinToPreviousWord(), fillerWord.joinToNextWord());195 incrementDiscrepancy();196 } else if (method.isAnnotationPresent(StepComment.class)) {197 addStepComment(arguments);198 incrementDiscrepancy();199 } else {200 addTags(method.getAnnotations());201 addTags(method.getDeclaringClass().getAnnotations());202 addStepMethod(method, arguments, mode, hasNestedSteps);203 }204 }205 public void setMethodName(String methodName) {206 scenarioModel.setTestMethodName(methodName);207 }208 public void setArguments(List<String> arguments) {209 scenarioCaseModel.setExplicitArguments(arguments);210 }211 public void setParameterNames(List<String> parameterNames) {212 scenarioModel.setExplicitParameters(removeUnderlines(parameterNames));213 }214 private static List<String> removeUnderlines(List<String> parameterNames) {215 List<String> result = Lists.newArrayListWithCapacity(parameterNames.size());216 for (String paramName : parameterNames) {217 result.add(WordUtil.fromSnakeCase(paramName));218 }219 return result;220 }221 private String getDescription(Method paramMethod) {222 if (paramMethod.isAnnotationPresent(Hidden.class)) {223 return "";224 }225 Description description = paramMethod.getAnnotation(Description.class);226 if (description != null) {227 return description.value();228 }229 As as = paramMethod.getAnnotation(As.class);230 AsProvider provider = as != null231 ? ReflectionUtil.newInstance(as.provider())232 : new DefaultAsProvider();233 return provider.as(as, paramMethod);234 }235 public void setStatus(ExecutionStatus status) {...

Full Screen

Full Screen

Source:AnnotationTagUtilsTest.java Github

copy

Full Screen

...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",149 "value",...

Full Screen

Full Screen

Source:ReportModel.java Github

copy

Full Screen

...38 visitor.visitEnd(this);39 }40 private List<ScenarioModel> sortByDescription() {41 List<ScenarioModel> sorted = Lists.newArrayList(getScenarios());42 sorted.sort(Comparator.comparing(self -> self.getDescription().toLowerCase()));43 return sorted;44 }45 public ScenarioModel getLastScenarioModel() {46 return getScenarios().get(getScenarios().size() - 1);47 }48 public Optional<ScenarioModel> findScenarioModel(String scenarioDescription) {49 for (ScenarioModel model : getScenarios()) {50 if (model.getDescription().equals(scenarioDescription)) {51 return Optional.of(model);52 }53 }54 return Optional.empty();55 }56 public StepModel getFirstStepModelOfLastScenario() {57 return getLastScenarioModel().getCase(0).getStep(0);58 }59 public synchronized void addScenarioModel(ScenarioModel currentScenarioModel) {60 scenarios.add(copyModelToKeepOriginalIsolatedInItsThread(currentScenarioModel));61 }62 private ScenarioModel copyModelToKeepOriginalIsolatedInItsThread(ScenarioModel currentScenarioModel) {63 return new ScenarioModel(currentScenarioModel);64 }65 public String getSimpleClassName() {66 return Iterables.getLast(Splitter.on('.').split(getClassName()));67 }68 public String getDescription() {69 return description;70 }71 public void setDescription(String description) {72 this.description = description;73 }74 public String getClassName() {75 return className;76 }77 public void setClassName(String className) {78 this.className = className;79 }80 public List<ScenarioModel> getScenarios() {81 return scenarios;82 }83 public void setScenarios(List<ScenarioModel> scenarios) {84 this.scenarios = scenarios;85 }86 public String getPackageName() {87 int index = this.className.lastIndexOf('.');88 if (index == -1) {89 return "";90 }91 return this.className.substring(0, index);92 }93 public List<ScenarioModel> getFailedScenarios() {94 return getScenariosWithStatus(ExecutionStatus.FAILED);95 }96 public List<ScenarioModel> getPendingScenarios() {97 return getScenariosWithStatus(ExecutionStatus.SCENARIO_PENDING, ExecutionStatus.SOME_STEPS_PENDING);98 }99 public List<ScenarioModel> getScenariosWithStatus(ExecutionStatus first, ExecutionStatus... rest) {100 EnumSet<ExecutionStatus> stati = EnumSet.of(first, rest);101 List<ScenarioModel> result = Lists.newArrayList();102 for (ScenarioModel m : scenarios) {103 ExecutionStatus executionStatus = m.getExecutionStatus();104 if (stati.contains(executionStatus)) {105 result.add(m);106 }107 }108 return result;109 }110 public synchronized void addTag(Tag tag) {111 this.tagMap.put(tag.toIdString(), tag);112 }113 public synchronized void addTags(Iterable<Tag> tags) {114 tags.forEach(this::addTag);115 }116 public synchronized Tag getTagWithId(String tagId) {117 Tag tag = this.tagMap.get(tagId);118 AssertionUtil.assertNotNull(tag, "Could not find tag with id " + tagId);119 return tag;120 }121 public synchronized Map<String, Tag> getTagMap() {122 return tagMap;123 }124 public synchronized void setTagMap(Map<String, Tag> tagMap) {125 this.tagMap = tagMap;126 }127 public synchronized void addScenarioModelOrMergeWithExistingOne(ScenarioModel scenarioModel) {128 Optional<ScenarioModel> existingScenarioModel = findScenarioModel(scenarioModel.getDescription());129 if (existingScenarioModel.isPresent()) {130 AssertionUtil.assertTrue(scenarioModel.getScenarioCases().size() == 1,131 "ScenarioModel has more than one case");132 existingScenarioModel.get().addCase(scenarioModel.getCase(0));133 existingScenarioModel.get().addDurationInNanos(scenarioModel.getDurationInNanos());134 } else {135 addScenarioModel(scenarioModel);136 }137 }138 public synchronized void setTestClass(Class<?> testClass) {139 AssertionUtil.assertTrue(className == null || testClass.getName().equals(className),140 "Test class of the same report model was set to different values. 1st value: " + className141 + ", 2nd value: " + testClass.getName());142 setClassName(testClass.getName());...

Full Screen

Full Screen

getDescription

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import org.junit.Test;3import static org.assertj.core.api.Assertions.assertThat;4public class TagTest {5 public void testGetDescription() {6 Tag tag = new Tag();7 tag.setDescription("test description");8 assertThat(tag.getDescription()).isEqualTo("test description");9 }10}11package com.tngtech.jgiven.report.model;12import org.junit.Test;13import static org.assertj.core.api.Assertions.assertThat;14public class TagTest {15 public void testGetName() {16 Tag tag = new Tag();17 tag.setName("test name");18 assertThat(tag.getName()).isEqualTo("test name");19 }20}21package com.tngtech.jgiven.report.model;22import org.junit.Test;23import static org.assertj.core.api.Assertions.assertThat;24public class TagTest {25 public void testGetScenarioCount() {26 Tag tag = new Tag();27 tag.setScenarioCount(1);28 assertThat(tag.getScenarioCount()).isEqualTo(1);29 }30}31package com.tngtech.jgiven.report.model;32import org.junit.Test;33import static org.assertj.core.api.Assertions.assertThat;34public class TagTest {35 public void testGetFailedScenarioCount() {36 Tag tag = new Tag();37 tag.setFailedScenarioCount(1);38 assertThat(tag.getFailedScenarioCount()).isEqualTo(1);39 }40}41package com.tngtech.jgiven.report.model;42import org.junit.Test;43import static org.assertj.core.api.Assertions.assertThat;44public class TagTest {45 public void testGetScenarioCount() {46 Tag tag = new Tag();47 tag.setScenarioCount(1);48 assertThat(tag.getScenarioCount()).isEqualTo(1);49 }50}51package com.tngtech.jgiven.report.model;52import org

Full Screen

Full Screen

getDescription

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import java.util.ArrayList;3import java.util.List;4public class Tag {5 public static Tag create( String name ) {6 Tag tag = new Tag();7 tag.setName( name );8 return tag;9 }10 public static Tag create( String name, String description ) {11 Tag tag = new Tag();12 tag.setName( name );13 tag.setDescription( description );14 return tag;15 }16 public static Tag create( String name, String description, String color ) {17 Tag tag = new Tag();18 tag.setName( name );19 tag.setDescription( description );20 tag.setColor( color );21 return tag;22 }23 public static List<Tag> createList( String... names ) {24 List<Tag> tags = new ArrayList<Tag>();25 for( String name : names ) {26 tags.add( Tag.create( name ) );27 }28 return tags;29 }30 private String name;31 private String description;32 private String color;33 public String getName() {34 return name;35 }36 public void setName( String name ) {37 this.name = name;38 }39 public String getDescription() {40 return description;41 }42 public void setDescription( String description ) {43 this.description = description;44 }45 public String getColor() {46 return color;47 }48 public void setColor( String color ) {49 this.color = color;50 }51 public boolean equals( Object o ) {52 if( this == o ) {53 return true;54 }55 if( o == null || getClass() != o.getClass() ) {56 return false;57 }58 Tag tag = (Tag) o;59 if( name != null ? !name.equals( tag.name ) : tag.name != null ) {60 return false;61 }62 if( description != null ? !description.equals( tag.description ) : tag.description != null ) {63 return false;64 }65 return color != null ? color.equals( tag.color ) : tag.color == null;66 }67 public int hashCode() {68 int result = name != null ? name.hashCode() : 0;69 result = 31 * result + ( description != null ? description.hashCode() : 0 );70 result = 31 * result + ( color != null ? color.hashCode() : 0 );71 return result;72 }

Full Screen

Full Screen

getDescription

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.report.model.Tag;2import com.tngtech.jgiven.report.model.TagType;3public class TagExample {4 public static void main(String args[]) {5 Tag tag = new Tag();6 tag.setName("tag1");7 tag.setDescription("tag1 description");8 tag.setType(TagType.TAG);9 System.out.println("tag description is: " + tag.getDescription());10 }11}

Full Screen

Full Screen

getDescription

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import java.util.ArrayList;3import java.util.List;4import com.tngtech.jgiven.annotation.Description;5public class Tag {6 private String name;7 private String description;8 public Tag( String name, String description ) {9 this.name = name;10 this.description = description;11 }12 public String getName() {13 return name;14 }15 public String getDescription() {16 return description;17 }18 public static List<Tag> parseTags( String tagString ) {19 List<Tag> tags = new ArrayList<>();20 if( tagString != null ) {21 for( String tag : tagString.split( "," ) ) {22 String[] tagParts = tag.split( ":" );23 String tagName = tagParts[0];24 String tagDescription = "";25 if( tagParts.length > 1 ) {26 tagDescription = tagParts[1];27 }28 tags.add( new Tag( tagName, tagDescription ) );29 }30 }31 return tags;32 }33}34package com.tngtech.jgiven.report.model;35import java.util.ArrayList;36import java.util.Collection;37import java.util.Collections;38import java.util.List;39import com.tngtech.jgiven.annotation.Description;40public class ScenarioModel {41 private String description;42 private String name;43 private String className;44 private String methodName;45 private String status;46 private String errorMessage;47 private List<StepModel> steps = new ArrayList<>();48 private List<Tag> tags = new ArrayList<>();49 private List<AttachmentModel> attachments = new ArrayList<>();50 private List<ScenarioModel> scenarios = new ArrayList<>();51 private int durationInNanos;52 private String classNameSimple;53 private String packageName;54 public String getDescription() {55 return description;56 }57 public ScenarioModel setDescription( String description ) {58 this.description = description;59 return this;60 }61 public String getName() {62 return name;63 }64 public ScenarioModel setName( String name ) {65 this.name = name;66 return this;67 }68 public String getClassName() {69 return className;70 }71 public ScenarioModel setClassName( String className ) {72 this.className = className;73 return this;74 }75 public String getMethodName() {76 return methodName;77 }78 public ScenarioModel setMethodName( String methodName ) {

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful