How to use ParameterFormattingUtil method of com.tngtech.jgiven.impl.format.ParameterFormattingUtil class

Best JGiven code snippet using com.tngtech.jgiven.impl.format.ParameterFormattingUtil.ParameterFormattingUtil

Source:ScenarioModelBuilder.java Github

copy

Full Screen

...17import com.tngtech.jgiven.config.ConfigurationUtil;18import com.tngtech.jgiven.config.DefaultConfiguration;19import com.tngtech.jgiven.exception.JGivenWrongUsageException;20import com.tngtech.jgiven.format.ObjectFormatter;21import com.tngtech.jgiven.impl.format.ParameterFormattingUtil;22import com.tngtech.jgiven.impl.intercept.ScenarioListener;23import com.tngtech.jgiven.impl.params.DefaultAsProvider;24import com.tngtech.jgiven.impl.tag.ResolvedTags;25import com.tngtech.jgiven.impl.tag.TagCreator;26import com.tngtech.jgiven.impl.util.AnnotationUtil;27import com.tngtech.jgiven.impl.util.AssertionUtil;28import com.tngtech.jgiven.impl.util.ReflectionUtil;29import com.tngtech.jgiven.impl.util.WordUtil;30import com.tngtech.jgiven.report.model.ExecutionStatus;31import com.tngtech.jgiven.report.model.InvocationMode;32import com.tngtech.jgiven.report.model.NamedArgument;33import com.tngtech.jgiven.report.model.ReportModel;34import com.tngtech.jgiven.report.model.ScenarioCaseModel;35import com.tngtech.jgiven.report.model.ScenarioModel;36import com.tngtech.jgiven.report.model.StepFormatter;37import com.tngtech.jgiven.report.model.StepModel;38import com.tngtech.jgiven.report.model.StepStatus;39import com.tngtech.jgiven.report.model.Word;40import java.lang.annotation.Annotation;41import java.lang.reflect.Method;42import java.util.ArrayList;43import java.util.List;44import java.util.Set;45import java.util.Stack;46public class ScenarioModelBuilder implements ScenarioListener {47 private static final Set<String> STACK_TRACE_FILTER = ImmutableSet48 .of("sun.reflect", "com.tngtech.jgiven.impl.intercept", "com.tngtech.jgiven.impl.intercept",49 "$$EnhancerByCGLIB$$",50 "java.lang.reflect", "net.sf.cglib.proxy", "com.sun.proxy");51 private static final boolean FILTER_STACK_TRACE = Config.config().filterStackTrace();52 private ScenarioModel scenarioModel;53 private ScenarioCaseModel scenarioCaseModel;54 private StepModel currentStep;55 private final Stack<StepModel> parentSteps = new Stack<>();56 private final SentenceBuilder sentenceBuilder = new SentenceBuilder();57 private long scenarioStartedNanos;58 private AbstractJGivenConfiguration configuration = new DefaultConfiguration();59 private ReportModel reportModel;60 private TagCreator tagCreator;61 public void setReportModel(ReportModel reportModel) {62 this.reportModel = reportModel;63 }64 private Stack<Integer> discrepancyOnLayer = new Stack<>();65 @Override66 public void scenarioStarted(String description) {67 scenarioStartedNanos = System.nanoTime();68 String readableDescription = description;69 if (description.contains("_")) {70 readableDescription = description.replace('_', ' ');71 } else if (!description.contains(" ")) {72 readableDescription = WordUtil.camelCaseToCapitalizedReadableText(description);73 }74 scenarioCaseModel = new ScenarioCaseModel();75 scenarioModel = new ScenarioModel();76 scenarioModel.addCase(scenarioCaseModel);77 scenarioModel.setDescription(readableDescription);78 this.tagCreator = new TagCreator(configuration);79 discrepancyOnLayer.push(0);80 }81 @Override82 public void scenarioStarted(Class<?> testClass, Method method, List<NamedArgument> namedArguments) {83 readConfiguration(testClass);84 readAnnotations(testClass, method);85 scenarioModel.setClassName(testClass.getName());86 setParameterNames(getNames(namedArguments));87 // must come at last88 setMethodName(method.getName());89 ParameterFormattingUtil parameterFormattingUtil = new ParameterFormattingUtil(configuration);90 List<ObjectFormatter<?>> formatter =91 parameterFormattingUtil.getFormatter(method.getParameterTypes(), getNames(namedArguments),92 method.getParameterAnnotations());93 setArguments(parameterFormattingUtil.toStringList(formatter, getValues(namedArguments)));94 setCaseDescription(testClass, method, namedArguments);95 }96 private void addStepMethod(Method paramMethod, List<NamedArgument> arguments, InvocationMode mode,97 boolean hasNestedSteps) {98 StepModel stepModel = createStepModel(paramMethod, arguments, mode);99 if (parentSteps.empty()) {100 getCurrentScenarioCase().addStep(stepModel);101 } else {102 parentSteps.peek().addNestedStep(stepModel);103 }104 if (hasNestedSteps) {105 parentSteps.push(stepModel);106 discrepancyOnLayer.push(0);107 }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++) {...

Full Screen

Full Screen

Source:PlainRowFormatter.java Github

copy

Full Screen

...4import com.google.common.collect.ImmutableList;5import com.tngtech.jgiven.annotation.Table;6import com.tngtech.jgiven.config.FormatterConfiguration;7import com.tngtech.jgiven.format.ObjectFormatter;8import com.tngtech.jgiven.impl.format.ParameterFormattingUtil;9/**10 * Formats each row by just using the default formatting of an object.11 * This results in a table with just one column, where the header is the name of the parameter.12 *13 * @see com.tngtech.jgiven.annotation.Table14 * @since 0.10.015 */16public class PlainRowFormatter extends RowFormatter {17 private final String columnHeader;18 private final ObjectFormatter objectFormatter;19 public PlainRowFormatter( Class<?> type, Table tableAnnotation, String columnHeader, Annotation[] annotations,20 FormatterConfiguration configuration, ObjectFormatter objectFormatter ) {21 this.columnHeader = columnHeader;22 ParameterFormattingUtil formattingUtil = new ParameterFormattingUtil( configuration );23 this.objectFormatter = objectFormatter;24 }25 @Override26 public List<String> header() {27 return ImmutableList.of( columnHeader );28 }29 @Override30 public List<String> formatRow( Object object ) {31 return ImmutableList.of( objectFormatter.format( object ) );32 }33 /**34 * Factory for creating instances of {@link PlainRowFormatter}35 *36 * @see com.tngtech.jgiven.annotation.Table...

Full Screen

Full Screen

Source:ParameterFormatterFactory.java Github

copy

Full Screen

...6import com.tngtech.jgiven.config.AbstractJGivenConfiguration;7import com.tngtech.jgiven.format.ArgumentFormatter;8import com.tngtech.jgiven.format.DefaultFormatter;9import com.tngtech.jgiven.format.ObjectFormatter;10import com.tngtech.jgiven.impl.format.ParameterFormattingUtil;11import com.tngtech.jgiven.report.model.NamedArgument;12import com.tngtech.jgiven.report.model.StepFormatter;13public class ParameterFormatterFactory {14 private static final StepFormatter.Formatting<?, ?> DEFAULT_FORMATTING = new StepFormatter.ArgumentFormatting<ArgumentFormatter<Object>, Object>(15 new DefaultFormatter<>());16 private final ParameterFormattingUtil parameterFormattingUtil;17 public ParameterFormatterFactory(AbstractJGivenConfiguration configuration) {18 this.parameterFormattingUtil = new ParameterFormattingUtil(configuration);19 }20 public List<ObjectFormatter<?>> create(21 Parameter[] parameters,22 List<NamedArgument> namedArguments23 ) {24 Class<?>[] parameterTypes = Arrays.stream(parameters)25 .map(Parameter::getType)26 .toArray(Class<?>[]::new);27 Annotation[][] parameterAnnotations = Arrays.stream(parameters)28 .map(Parameter::getAnnotations)29 .toArray(Annotation[][]::new);30 return parameterFormattingUtil.getFormatter(parameterTypes,31 ArgumentUtils.getNames(namedArguments),32 parameterAnnotations...

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful