How to use getFormattedValues method of com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser class

Best JGiven code snippet using com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser.getFormattedValues

Source:CaseArgumentAnalyser.java Github

copy

Full Screen

...59 List<List<Word>> arguments = getFirstWords(joinedArgs);60 setParameterNames(joinedArgs, argumentNames);61 scenarioModel.setDerivedParameters(argumentNames);62 for (int caseCounter = 0; caseCounter < arguments.size(); caseCounter++) {63 scenarioModel.getCase(caseCounter).setDerivedArguments(getFormattedValues(arguments.get(caseCounter)));64 }65 }66 private List<List<String>> getExplicitParameterValues(List<ScenarioCaseModel> scenarioCases) {67 List<List<String>> explicitParameterValues = Lists.newArrayListWithExpectedSize(scenarioCases.size());68 for (ScenarioCaseModel caseModel : scenarioCases) {69 explicitParameterValues.add(caseModel.getExplicitArguments());70 }71 return explicitParameterValues;72 }73 /**74 * Finds for each JoinedArgs set the best fitting name.75 * <p>76 * First it is tried to find a name from the explicitParameterNames list, by comparing the argument values77 * with the explicit case argument values. If no matching value can be found, the name of the argument is taken.78 */79 private List<String> findArgumentNames(List<List<JoinedArgs>> joinedArgs,80 List<List<String>> explicitParameterValues,81 List<String> explicitParameterNames) {82 List<String> argumentNames = Lists.newArrayListWithExpectedSize(joinedArgs.get(0).size());83 Multiset<String> paramNames = TreeMultiset.create();84 arguments:85 for (int argumentCounter = 0; argumentCounter < joinedArgs.get(0).size(); argumentCounter++) {86 parameters:87 for (int paramCounter = 0; paramCounter < explicitParameterNames.size(); paramCounter++) {88 String paramName = explicitParameterNames.get(paramCounter);89 boolean formattedValueMatches = true;90 boolean valueMatches = true;91 for (int caseCounter = 0; caseCounter < joinedArgs.size(); caseCounter++) {92 JoinedArgs args = joinedArgs.get(caseCounter).get(argumentCounter);93 String parameterValue = explicitParameterValues.get(caseCounter).get(paramCounter);94 String formattedValue = args.words.get(0).getFormattedValue();95 if (!formattedValue.equals(parameterValue)) {96 formattedValueMatches = false;97 }98 String value = args.words.get(0).getValue();99 if (!value.equals(parameterValue)) {100 valueMatches = false;101 }102 if (!formattedValueMatches && !valueMatches) {103 continue parameters;104 }105 }106 // on this point either all formatted values match or all values match (or both)107 argumentNames.add(paramName);108 paramNames.add(paramName);109 continue arguments;110 }111 argumentNames.add(null);112 }113 Set<String> usedNames = Sets.newHashSet();114 for (int argumentCounter = 0; argumentCounter < joinedArgs.get(0).size(); argumentCounter++) {115 String name = argumentNames.get(argumentCounter);116 if (name == null || paramNames.count(name) > 1) {117 String origName = getArgumentName(joinedArgs, argumentCounter);118 name = findFreeName(usedNames, origName);119 argumentNames.set(argumentCounter, name);120 }121 usedNames.add(name);122 }123 return argumentNames;124 }125 private String getArgumentName(List<List<JoinedArgs>> joinedArgs, int argumentCounter) {126 return joinedArgs.get(0).get(argumentCounter).words.get(0).getArgumentInfo().getArgumentName();127 }128 private String findFreeName(Set<String> usedNames, String origName) {129 String name = origName;130 int counter = 2;131 while (usedNames.contains(name)) {132 name = origName + counter;133 counter++;134 }135 usedNames.add(name);136 return name;137 }138 private List<List<Word>> getFirstWords(List<List<JoinedArgs>> joinedArgs) {139 List<List<Word>> result = Lists.newArrayList();140 for (int i = 0; i < joinedArgs.size(); i++) {141 result.add(Lists.newArrayList());142 }143 for (int i = 0; i < joinedArgs.size(); i++) {144 for (int j = 0; j < joinedArgs.get(i).size(); j++) {145 result.get(i).add(joinedArgs.get(i).get(j).words.get(0));146 }147 }148 return result;149 }150 List<List<JoinedArgs>> joinEqualArguments(List<List<Word>> differentArguments) {151 List<List<JoinedArgs>> joined = Lists.newArrayList();152 for (int i = 0; i < differentArguments.size(); i++) {153 joined.add(Lists.newArrayList());154 }155 if (differentArguments.get(0).isEmpty()) {156 return joined;157 }158 for (int caseCounter = 0; caseCounter < differentArguments.size(); caseCounter++) {159 joined.get(caseCounter).add(new JoinedArgs(differentArguments.get(caseCounter).get(0)));160 }161 int numberOfArgs = differentArguments.get(0).size();162 outer:163 for (int i = 1; i < numberOfArgs; i++) {164 inner:165 for (int j = 0; j < joined.get(0).size(); j++) {166 for (int caseCounter = 0; caseCounter < differentArguments.size(); caseCounter++) {167 Word newWord = differentArguments.get(caseCounter).get(i);168 Word joinedWord = joined.get(caseCounter).get(j).words.get(0);169 if (!newWord.getFormattedValue().equals(joinedWord.getFormattedValue())) {170 continue inner;171 }172 }173 for (int caseCounter = 0; caseCounter < differentArguments.size(); caseCounter++) {174 joined.get(caseCounter).get(j).words.add(differentArguments.get(caseCounter).get(i));175 }176 continue outer;177 }178 for (int caseCounter = 0; caseCounter < differentArguments.size(); caseCounter++) {179 joined.get(caseCounter).add(new JoinedArgs(differentArguments.get(caseCounter).get(i)));180 }181 }182 return joined;183 }184 /**185 * A scenario model is structural identical if all cases have exactly the same186 * steps, except for values of step arguments.187 * <p>188 * This is implemented by comparing all cases with the first one189 */190 private boolean isStructuralIdentical(ScenarioModel scenarioModel) {191 ScenarioCaseModel firstCase = scenarioModel.getScenarioCases().get(0);192 for (int caseCounter = 1; caseCounter < scenarioModel.getScenarioCases().size(); caseCounter++) {193 ScenarioCaseModel caseModel = scenarioModel.getScenarioCases().get(caseCounter);194 if (stepsAreDifferent(firstCase, caseModel)) {195 return false;196 }197 }198 return true;199 }200 boolean stepsAreDifferent(ScenarioCaseModel firstCase, ScenarioCaseModel secondCase) {201 return stepsAreDifferent(firstCase.getSteps(), secondCase.getSteps());202 }203 boolean stepsAreDifferent(List<StepModel> firstSteps, List<StepModel> secondSteps) {204 if (firstSteps.size() != secondSteps.size()) {205 return true;206 }207 for (int stepCounter = 0; stepCounter < firstSteps.size(); stepCounter++) {208 StepModel firstStep = firstSteps.get(stepCounter);209 StepModel secondStep = secondSteps.get(stepCounter);210 if (firstStep.getWords().size() != secondStep.getWords().size()) {211 return true;212 }213 if (attachmentsAreStructurallyDifferent(firstStep.getAttachments(), secondStep.getAttachments())) {214 return true;215 }216 if (wordsAreDifferent(firstStep, secondStep)) {217 return true;218 }219 if (stepsAreDifferent(firstStep.getNestedSteps(), secondStep.getNestedSteps())) {220 return true;221 }222 }223 return false;224 }225 /**226 * Attachments are only structurally different if one step has an inline attachment227 * and the other step either has no inline attachment or the inline attachment is228 * different.229 */230 boolean attachmentsAreStructurallyDifferent(List<AttachmentModel> firstAttachments,231 List<AttachmentModel> otherAttachments) {232 if (firstAttachments.size() != otherAttachments.size()) {233 return true;234 }235 for (int i = 0; i < firstAttachments.size(); i++) {236 if (attachmentIsStructurallyDifferent(firstAttachments.get(i), otherAttachments.get(i))) {237 return true;238 }239 }240 return false;241 }242 boolean attachmentIsStructurallyDifferent(AttachmentModel firstAttachment, AttachmentModel otherAttachment) {243 if (isInlineAttachment(firstAttachment) != isInlineAttachment(otherAttachment)) {244 return true;245 }246 if (isInlineAttachment(firstAttachment)) {247 return !firstAttachment.getValue().equals(otherAttachment.getValue());248 }249 return false;250 }251 private boolean isInlineAttachment(AttachmentModel attachmentModel) {252 return attachmentModel != null && attachmentModel.isShowDirectly();253 }254 private boolean wordsAreDifferent(StepModel firstStep, StepModel stepModel) {255 for (int wordCounter = 0; wordCounter < firstStep.getWords().size(); wordCounter++) {256 Word firstWord = firstStep.getWord(wordCounter);257 Word word = stepModel.getWord(wordCounter);258 if (firstWord.isArg() != word.isArg()) {259 return true;260 }261 if (!firstWord.isArg() && !firstWord.getValue().equals(word.getValue())) {262 return true;263 }264 if (firstWord.isArg() && firstWord.isDataTable()265 && !firstWord.getArgumentInfo().getDataTable().equals(word.getArgumentInfo().getDataTable())) {266 return true;267 }268 }269 return false;270 }271 private void setParameterNames(List<List<JoinedArgs>> differentArguments, List<String> argumentNames) {272 AssertionUtil273 .assertTrue(argumentNames.size() == differentArguments.get(0).size(), "Number of argument names is wrong");274 for (int argumentCounter = 0; argumentCounter < argumentNames.size(); argumentCounter++) {275 for (List<JoinedArgs> differentArgument : differentArguments) {276 for (Word word : differentArgument.get(argumentCounter).words) {277 word.getArgumentInfo().setParameterName(argumentNames.get(argumentCounter));278 }279 }280 }281 }282 private List<String> getFormattedValues(List<Word> words) {283 List<String> formattedValues = Lists.newArrayListWithExpectedSize(words.size());284 for (Word word : words) {285 formattedValues.add(word.getFormattedValue());286 }287 return formattedValues;288 }289 /**290 * Returns a list with argument words that are not equal in all cases.291 */292 List<List<Word>> getDifferentArguments(List<List<Word>> argumentWords) {293 List<List<Word>> result = Lists.newArrayList();294 for (int i = 0; i < argumentWords.size(); i++) {295 result.add(Lists.newArrayList());296 }...

Full Screen

Full Screen

getFormattedValues

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser;2import com.tngtech.jgiven.report.model.CaseModel;3import com.tngtech.jgiven.report.model.ScenarioModel;4import com.tngtech.jgiven.report.model.StepModel;5import com.tngtech.jgiven.report.model.Tag;6import com.tngtech.jgiven.report.model.Word;7import com.tngtech.jgiven.report.model.WordType;8import com.tngtech.jgiven.report.model.WordUtil;9import java.util.List;10import java.util.Map;11public class JGivenMarkdownFormatter {12 public String format(CaseModel caseModel) {13 StringBuilder sb = new StringBuilder();14 sb.append("# ").append(caseModel.getDescription()).append("15");16 for (ScenarioModel scenarioModel : caseModel.getScenarioModels()) {17 sb.append("## ").append(scenarioModel.getDescription()).append("18");19 sb.append(scenarioModel.getTags().stream().map(Tag::getName).collect(Collectors.joining(" "))).append("20");21 for (StepModel stepModel : scenarioModel.getStepModels()) {22 sb.append("* ").append(stepModel.getDescription()).append("23");24 List<Word> words = WordUtil.split(stepModel.getDescription());25 if (!words.isEmpty()) {26 for (Word word : words) {27 if (word.getType() == WordType.ARGUMENT) {28 sb.append(" * ").append(word.getText()).append("29");30 }31 }32 }33 }34 }35 return sb.toString();36 }37}38import com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser;39import com.tngtech.jgiven.report.model.CaseModel;40import com.tngtech.jgiven.report.model.ScenarioModel;41import com.tngtech.jgiven.report.model.StepModel;42import com.tngtech.jgiven.report.model.Tag;43import java.util.List;44import java.util.Map;45public class JGivenMarkdownFormatter {46 public String format(CaseModel caseModel) {47 StringBuilder sb = new StringBuilder();48 sb.append("# ").append(caseModel.getDescription()).append("49");50 for (ScenarioModel scenarioModel : caseModel.getScenarioModels()) {51 sb.append("## ").append(scenarioModel.getDescription()).append("52");53 sb.append(scenarioModel.getTags().stream().map(Tag::getName).collect(Collectors

Full Screen

Full Screen

getFormattedValues

Using AI Code Generation

copy

Full Screen

1def caseArgumentAnalyser = new CaseArgumentAnalyser()2def caseArguments = caseArgumentAnalyser.getFormattedValues(analysisResult)3def caseArgumentTable = new CaseArgumentTable(caseArguments)4caseArgumentTable.render()5def caseArgumentAnalyser = new CaseArgumentAnalyser()6def caseArguments = caseArgumentAnalyser.getFormattedValues(analysisResult)7def caseArgumentTable = new CaseArgumentTable(caseArguments)8caseArgumentTable.render()9def caseArgumentAnalyser = new CaseArgumentAnalyser()10def caseArguments = caseArgumentAnalyser.getFormattedValues(analysisResult)11def caseArgumentTable = new CaseArgumentTable(caseArguments)12caseArgumentTable.render()13def caseArgumentAnalyser = new CaseArgumentAnalyser()14def caseArguments = caseArgumentAnalyser.getFormattedValues(analysisResult)15def caseArgumentTable = new CaseArgumentTable(caseArguments)16caseArgumentTable.render()17def caseArgumentAnalyser = new CaseArgumentAnalyser()18def caseArguments = caseArgumentAnalyser.getFormattedValues(analysisResult)19def caseArgumentTable = new CaseArgumentTable(caseArguments)20caseArgumentTable.render()21def caseArgumentAnalyser = new CaseArgumentAnalyser()22def caseArguments = caseArgumentAnalyser.getFormattedValues(analysisResult)23def caseArgumentTable = new CaseArgumentTable(caseArguments)24caseArgumentTable.render()25def caseArgumentAnalyser = new CaseArgumentAnalyser()26def caseArguments = caseArgumentAnalyser.getFormattedValues(analysisResult)27def caseArgumentTable = new CaseArgumentTable(caseArguments)28caseArgumentTable.render()29def caseArgumentAnalyser = new CaseArgumentAnalyser()

Full Screen

Full Screen

getFormattedValues

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.report.analysis.CaseArgumentAnalyser2import com.tngtech.jgiven.report.model.CaseModel3import com.tngtech.jgiven.report.model.ScenarioModel4import com.tngtech.jgiven.report.model.StepModel5import com.tngtech.jgiven.report.model.TagModel6def caseModel = new CaseModel()7caseModel.tags = [new TagModel("tag1"), new TagModel("tag2")]8caseModel.scenario = new ScenarioModel()9 new StepModel().withDescription("step1").withArguments("arg1"),10 new StepModel().withDescription("step2").withArguments("arg2"),11 new StepModel().withDescription("step3").withArguments("arg3"),12def caseArgumentAnalyser = new CaseArgumentAnalyser()13def formattedValues = caseArgumentAnalyser.getFormattedValues()14formattedValues.each { formattedValue ->15}

Full Screen

Full Screen

getFormattedValues

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.report.model.ScenarioCaseData2import com.tngtech.jgiven.report.model.ScenarioCaseModel3import com.tngtech.jgiven.report.model.ScenarioModel4import com.tngtech.jgiven.report.model.ReportModel5import com.tngtech.jgiven.report.model.ReportModel.ReportModelBuilder6import com.tngtech.jgiven.report.model.ReportModelBuilder7import com.tngtech.jgiven.report.model.ReportModel8import com.tngtech.jgiven.report.model.ScenarioCaseModel9import com.tngtech.jgiven.report.model.ScenarioCaseData10import com.tngtech.jgiven.report.model.ScenarioCaseData11import com.tngtech.jgiven.report.model.ScenarioModel12import com.tngtech.jgiven.report.model.ScenarioModel13import com.tngtech.jgiven.repor

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