How to use getDescription method of com.tngtech.jgiven.impl.ScenarioModelBuilder class

Best JGiven code snippet using com.tngtech.jgiven.impl.ScenarioModelBuilder.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:ScenarioModelBuilderTest.java Github

copy

Full Screen

...69 when().both_values_are_multiplied_with_each_other();70 then().the_result_is(expectedResult);71 getScenario().finished();72 ScenarioModel model = getScenario().getScenarioModel();73 assertThat(model.getDescription()).isEqualTo(description);74 ScenarioCaseModel case0 = model.getCase(0);75 assertThat(case0.getExecutionStatus()).isEqualTo(ExecutionStatus.SUCCESS);76 assertThat(case0.getCaseNr()).isEqualTo(1);77 assertThat(case0.getExplicitArguments()).isEmpty();78 assertThat(case0.getSteps()).hasSize(3);79 assertThat(case0.getSteps()).extracting("failed").isEqualTo(asList(false, false, false));80 assertThat(case0.getSteps()).extracting("pending").isEqualTo(asList(false, false, false));81 assertThat(case0.getSteps()).extracting("skipped").isEqualTo(asList(false, false, false));82 StepModel step0 = case0.getSteps().get(0);83 assertThat(step0.getWords()).hasSize(4);84 assertThat(step0.getCompleteSentence()).isEqualTo("Given " + a + " and " + b);85 assertThat(extractIsArg(step0.getWords())).isEqualTo(Arrays.asList(false, true, false, true));86 StepModel step2 = case0.getSteps().get(2);87 assertThat(step2.getWords()).hasSize(3);...

Full Screen

Full Screen

getDescription

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.impl.ScenarioModelBuilder;2import com.tngtech.jgiven.report.model.ScenarioModel;3import com.tngtech.jgiven.report.model.ScenarioCaseModel;4import com.tngtech.jgiven.report.model.GivenCaseModel;5import com.tngtech.jgiven.report.model.WhenCaseModel;6import com.tngtech.jgiven.report.model.ThenCaseModel;7import com.tngtech.jgiven.report.model.TagModel;8import com.tngtech.jgiven.report.model.StepCaseModel;9import com.tngtech.jgiven.report.model.StepModel;10import com.tngtech.jgiven.report.model.AttachementModel;11import com.tngtech.jgiven.report.model.CommentModel;12import com.tngtech.jgiven.report.model.TableModel;13import com.tngtech.jgiven.report.model.TableRowModel;14import com.tngtech.jgiven.report.model.TableCellModel;15import com.tngtech.jgiven.report.model.TableHeaderModel;16import com.tngtech.jgiven.report.model.TableFooterModel;17import com.tngtech.jgiven.report.model.TableCellModel;18import com.tngtech.jgiven.report.model.TableRowModel

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