How to use StepFormatter class of com.tngtech.jgiven.report.model package

Best JGiven code snippet using com.tngtech.jgiven.report.model.StepFormatter

Source:ParameterFormattingUtil.java Github

copy

Full Screen

...18import com.tngtech.jgiven.format.table.TableFormatter;19import com.tngtech.jgiven.format.table.TableFormatterFactory;20import com.tngtech.jgiven.impl.util.AnnotationUtil;21import com.tngtech.jgiven.impl.util.ReflectionUtil;22import com.tngtech.jgiven.report.model.StepFormatter;23import com.tngtech.jgiven.report.model.StepFormatter.ChainedFormatting;24import com.tngtech.jgiven.report.model.StepFormatter.Formatting;25public class ParameterFormattingUtil {26 private static final StepFormatter.Formatting<?, ?> DEFAULT_FORMATTING = new StepFormatter.ArgumentFormatting<ArgumentFormatter<Object>, Object>(27 new DefaultFormatter<Object>() );28 private final FormatterConfiguration configuration;29 public ParameterFormattingUtil( FormatterConfiguration configuration ) {30 this.configuration = configuration;31 }32 @SuppressWarnings( { "rawtypes", "unchecked" } )33 public <T> ObjectFormatter<?> getFormatting( Class<T> parameterType, String parameterName, Annotation[] annotations ) {34 ObjectFormatter<?> formatting = getFormatting( annotations, Sets.<Class<?>>newHashSet(), null, parameterName );35 if( formatting != null ) {36 return formatting;37 }38 Formatter<T> formatter = (Formatter<T>) configuration.getFormatter( parameterType );39 if( formatter != null ) {40 return new StepFormatter.TypeBasedFormatting<T>( formatter, annotations );41 }42 return DEFAULT_FORMATTING;43 }44 /**45 * Recursively searches for formatting annotations.46 *47 * @param visitedTypes used to prevent an endless loop48 * @param parameterName49 */50 private StepFormatter.Formatting<?, ?> getFormatting( Annotation[] annotations, Set<Class<?>> visitedTypes,51 Annotation originalAnnotation, String parameterName ) {52 List<StepFormatter.Formatting<?, ?>> foundFormatting = Lists.newArrayList();53 Table tableAnnotation = null;54 for( Annotation annotation : annotations ) {55 try {56 if( annotation instanceof Format ) {57 Format arg = (Format) annotation;58 foundFormatting.add( new StepFormatter.ArgumentFormatting( ReflectionUtil.newInstance( arg.value() ), arg.args() ) );59 } else if( annotation instanceof Table ) {60 tableAnnotation = (Table) annotation;61 } else if( annotation instanceof AnnotationFormat ) {62 AnnotationFormat arg = (AnnotationFormat) annotation;63 foundFormatting.add( new StepFormatter.ArgumentFormatting(64 new StepFormatter.AnnotationBasedFormatter( arg.value().newInstance(), originalAnnotation ) ) );65 } else {66 Class<? extends Annotation> annotationType = annotation.annotationType();67 if( !visitedTypes.contains( annotationType ) ) {68 visitedTypes.add( annotationType );69 StepFormatter.Formatting<?, ?> formatting = getFormatting( annotationType.getAnnotations(), visitedTypes,70 annotation, parameterName );71 if( formatting != null ) {72 foundFormatting.add( formatting );73 }74 }75 }76 } catch( Exception e ) {77 throw Throwables.propagate( e );78 }79 }80 if( foundFormatting.size() > 1 ) {81 Formatting<?, ?> innerFormatting = Iterables.getLast( foundFormatting );82 foundFormatting.remove( innerFormatting );83 ChainedFormatting<?> chainedFormatting = new StepFormatter.ChainedFormatting<Object>( (ObjectFormatter<Object>) innerFormatting );84 for( StepFormatter.Formatting<?, ?> formatting : Lists.reverse( foundFormatting ) ) {85 chainedFormatting.addFormatting( (StepFormatter.Formatting<?, String>) formatting );86 }87 foundFormatting.clear();88 foundFormatting.add( chainedFormatting );89 }90 if( tableAnnotation != null ) {91 ObjectFormatter<?> objectFormatter = foundFormatting.isEmpty()92 ? DefaultFormatter.INSTANCE93 : foundFormatting.get( 0 );94 return getTableFormatting( annotations, parameterName, tableAnnotation, objectFormatter );95 }96 if( foundFormatting.isEmpty() ) {97 return null;98 }99 return foundFormatting.get( 0 );100 }101 private StepFormatter.Formatting<?, ?> getTableFormatting( Annotation[] annotations, String parameterName, Table annotation,102 ObjectFormatter<?> objectFormatter ) {103 Table tableAnnotation = annotation;104 TableFormatterFactory factory = createTableFormatterFactory( parameterName, tableAnnotation );105 TableFormatter tableFormatter = factory.create( configuration, objectFormatter );106 return new StepFormatter.TableFormatting( tableFormatter, tableAnnotation, parameterName, annotations );107 }108 private TableFormatterFactory createTableFormatterFactory( String parameterName, Table tableAnnotation ) {109 Class<? extends TableFormatterFactory> formatterFactoryClass = tableAnnotation.formatter();110 try {111 return ReflectionUtil.newInstance( formatterFactoryClass );112 } catch( Exception e ) {113 throw new JGivenWrongUsageException(114 "Could not create an instance of " + formatterFactoryClass.getName()115 + " which was specified at the @Table annotation for parameter '" + parameterName116 + "'. Most likely this was due to a missing default constructor",117 TableFormatterFactory.class, e );118 }119 }120 public List<String> toStringList( List<ObjectFormatter<?>> formatter, List<?> arguments ) {...

Full Screen

Full Screen

Source:StepModelFactory.java Github

copy

Full Screen

...9import com.tngtech.jgiven.format.ObjectFormatter;10import com.tngtech.jgiven.impl.util.AnnotationUtil;11import com.tngtech.jgiven.report.model.InvocationMode;12import com.tngtech.jgiven.report.model.NamedArgument;13import com.tngtech.jgiven.report.model.StepFormatter;14import com.tngtech.jgiven.report.model.Word;15import xyz.multicatch.mockgiven.core.scenario.methods.DescriptionFactory;16import xyz.multicatch.mockgiven.core.scenario.methods.arguments.ParameterFormatterFactory;17import xyz.multicatch.mockgiven.core.scenario.state.CurrentScenarioState;18public class StepModelFactory {19 private final CurrentScenarioState currentScenarioState;20 private final ParameterFormatterFactory parameterFormatterFactory;21 private final DescriptionFactory descriptionFactory;22 public StepModelFactory(23 CurrentScenarioState currentScenarioState,24 ParameterFormatterFactory parameterFormatterFactory,25 DescriptionFactory descriptionFactory26 ) {27 this.currentScenarioState = currentScenarioState;28 this.parameterFormatterFactory = parameterFormatterFactory;29 this.descriptionFactory = descriptionFactory;30 }31 public ExtendedStepModel create(32 Method paramMethod,33 List<NamedArgument> arguments,34 InvocationMode mode,35 Word introWord36 ) {37 ExtendedStepModel stepModel = new ExtendedStepModel();38 createModelDescription(stepModel, paramMethod);39 createModelName(stepModel, paramMethod);40 createModelWords(stepModel, introWord, paramMethod.getParameters(), arguments);41 stepModel.setStatus(mode.toStepStatus());42 return stepModel;43 }44 private void createModelDescription(45 ExtendedStepModel stepModel,46 Method paramMethod47 ) {48 ExtendedDescription extendedDescriptionAnnotation = paramMethod.getAnnotation(ExtendedDescription.class);49 if (extendedDescriptionAnnotation != null) {50 stepModel.setExtendedDescription(extendedDescriptionAnnotation.value());51 }52 }53 private void createModelName(54 ExtendedStepModel stepModel,55 Method paramMethod56 ) {57 Object currentStage = currentScenarioState.getCurrentStage();58 String name = descriptionFactory.create(currentStage, paramMethod);59 stepModel.setName(name);60 }61 private void createModelWords(62 ExtendedStepModel stepModel,63 Word introWord,64 Parameter[] parameters,65 List<NamedArgument> arguments66 ) {67 List<NamedArgument> nonHiddenArguments = filterHiddenArguments(arguments, parameters);68 List<ObjectFormatter<?>> formatter = parameterFormatterFactory.create(parameters, arguments);69 stepModel.setWords(new StepFormatter(stepModel.getName(), nonHiddenArguments, formatter).buildFormattedWords());70 if (introWord != null) {71 stepModel.addIntroWord(introWord);72 }73 }74 private List<NamedArgument> filterHiddenArguments(75 List<NamedArgument> arguments,76 Parameter[] parameters77 ) {78 Annotation[][] parameterAnnotations = Arrays.stream(parameters)79 .map(Parameter::getAnnotations)80 .toArray(Annotation[][]::new);81 List<NamedArgument> result = Lists.newArrayList();82 for (int i = 0; i < parameterAnnotations.length; i++) {83 if (!AnnotationUtil.isHidden(parameterAnnotations[i])) {...

Full Screen

Full Screen

Source:ParameterFormatterFactory.java Github

copy

Full Screen

...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 parameterAnnotations33 );34 }35 static StepFormatter.Formatting<?, ?> createDefault() {36 return DEFAULT_FORMATTING;37 }38}...

Full Screen

Full Screen

StepFormatter

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.report.model.StepFormatter;2import com.tngtech.jgiven.report.model.StepModel;3public class StepFormatterExample {4 public static void main(String[] args) {5 StepModel stepModel = new StepModel();6 stepModel.setDescription("This is step description");7 stepModel.setArg1("arg1");8 stepModel.setArg2("arg2");9 stepModel.setArg3("arg3");10 stepModel.setArg4("arg4");11 stepModel.setArg5("arg5");12 stepModel.setArg6("arg6");13 stepModel.setArg7("arg7");14 stepModel.setArg8("arg8");15 stepModel.setArg9("arg9");16 stepModel.setArg10("arg10");17 stepModel.setArg11("arg11");18 stepModel.setArg12("arg12");19 stepModel.setArg13("arg13");20 stepModel.setArg14("arg14");21 stepModel.setArg15("arg15");22 stepModel.setArg16("arg16");23 stepModel.setArg17("arg17");24 stepModel.setArg18("arg18");25 stepModel.setArg19("arg19");26 stepModel.setArg20("arg20");27 stepModel.setArg21("arg21");28 stepModel.setArg22("arg22");29 stepModel.setArg23("arg23");30 stepModel.setArg24("arg24");31 stepModel.setArg25("arg25");32 stepModel.setArg26("arg26");33 stepModel.setArg27("arg27");34 stepModel.setArg28("arg28");35 stepModel.setArg29("arg29");36 stepModel.setArg30("arg30");37 stepModel.setArg31("arg31");38 stepModel.setArg32("arg32");39 stepModel.setArg33("arg33");40 stepModel.setArg34("arg34");41 stepModel.setArg35("arg35");42 stepModel.setArg36("arg36");43 stepModel.setArg37("arg37");44 stepModel.setArg38("arg38");45 stepModel.setArg39("arg39");46 stepModel.setArg40("arg40");47 stepModel.setArg41("arg41");48 stepModel.setArg42("arg42");49 stepModel.setArg43("arg43");50 stepModel.setArg44("arg

Full Screen

Full Screen

StepFormatter

Using AI Code Generation

copy

Full Screen

1StepFormatter stepFormatter = new StepFormatter();2StepModel stepModel = new StepModel();3stepModel.setArgModelList(argModelList);4stepModel.setStepType(stepType);5stepModel.setStepWord(stepWord);6stepModel.setDescription(description);7stepFormatter.format(stepModel);8stepModel.getFormattedDescription();9stepModel.getArgModelList();10stepModel.getStepType();11stepModel.getStepWord();12stepModel.getDescription();13stepModel.getArgs();14stepModel.getArgModelList();15stepModel.getArgModelList();16stepModel.getArgModelList();17stepModel.getArgModelList();18stepModel.getArgModelList();19stepModel.getArgModelList();20stepModel.getArgModelList();

Full Screen

Full Screen

StepFormatter

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2import java.util.ArrayList;3import java.util.List;4public class StepFormatter {5 private final List<StepFormatter> subSteps = new ArrayList<StepFormatter>();6 public List<StepFormatter> getSubSteps() {7 return subSteps;8 }9}10package com.tngtech.jgiven.report.model;11import java.util.ArrayList;12import java.util.List;13public class StepFormatter {14 private final List<StepFormatter> subSteps = new ArrayList<StepFormatter>();15 public List<StepFormatter> getSubSteps() {16 return subSteps;17 }18}19package com.tngtech.jgiven.report.model;20import java.util.ArrayList;21import java.util.List;22public class StepFormatter {23 private final List<StepFormatter> subSteps = new ArrayList<StepFormatter>();24 public List<StepFormatter> getSubSteps() {25 return subSteps;26 }27}28package com.tngtech.jgiven.report.model;29import java.util.ArrayList;30import java.util.List;31public class StepFormatter {32 private final List<StepFormatter> subSteps = new ArrayList<StepFormatter>();33 public List<StepFormatter> getSubSteps() {34 return subSteps;35 }36}37package com.tngtech.jgiven.report.model;38import java.util.ArrayList;39import java.util.List;40public class StepFormatter {41 private final List<StepFormatter> subSteps = new ArrayList<StepFormatter>();42 public List<StepFormatter> getSubSteps() {43 return subSteps;44 }45}46package com.tngtech.jgiven.report.model;47import java.util.ArrayList;48import java.util.List;49public class StepFormatter {50 private final List<StepFormatter> subSteps = new ArrayList<StepFormatter>();51 public List<StepFormatter> getSubSteps() {52 return subSteps;53 }54}

Full Screen

Full Screen

StepFormatter

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.model;2public class StepFormatter {3private final Step step;4public StepFormatter(Step step) {5this.step = step;6}7public String format() {8String description = step.getDescription();9if (step.hasArguments()) {10description = formatArguments(description);11}12return description;13}14private String formatArguments(String description) {15List<Argument> arguments = step.getArguments();16for (int i = 0; i < arguments.size(); i++) {17Argument argument = arguments.get(i);18description = description.replace("{" + i + "}", argument.getName());19}20return description;21}22}23package com.tngtech.jgiven.report.model;24public class StepFormatter {25private final Step step;26public StepFormatter(Step step) {27this.step = step;28}29public String format() {30String description = step.getDescription();31if (step.hasArguments()) {32description = formatArguments(description);33}34return description;35}36private String formatArguments(String description) {37List<Argument> arguments = step.getArguments();38for (int i = 0; i < arguments.size(); i++) {39Argument argument = arguments.get(i);40description = description.replace("{" + i + "}", argument.getName());41}42return description;43}44}45package com.tngtech.jgiven.report.model;46public class StepFormatter {47private final Step step;48public StepFormatter(Step step) {49this.step = step;50}51public String format() {52String description = step.getDescription();53if (step.hasArguments()) {54description = formatArguments(description);55}56return description;57}58private String formatArguments(String description) {59List<Argument> arguments = step.getArguments();60for (int i = 0; i < arguments.size(); i++) {61Argument argument = arguments.get(i);62description = description.replace("{" + i + "}", argument.getName());63}64return description;65}66}67package com.tngtech.jgiven.report.model;68public class StepFormatter {69private final Step step;70public StepFormatter(Step step) {71this.step = step;72}73public String format() {74String description = step.getDescription();75if (step.hasArguments())

Full Screen

Full Screen

StepFormatter

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.impl.ScenarioModelBuilder;5import com.tngtech.jgiven.impl.ScenarioModelBuilder.ScenarioModel;6import com.tngtech.jgiven.impl.ScenarioModelBuilder.StepModel;7import com.tngtech.jgiven.report.model.ReportModel.ReportModelBuilder;8public class StepFormatter {9 private ScenarioModelBuilder scenarioModelBuilder;10 private ReportModelBuilder reportModelBuilder;11 private ScenarioModel scenarioModel;12 private StepModel currentStep;13 private List<StepModel> currentStepList;14 public StepFormatter(ScenarioModelBuilder scenarioModelBuilder, ReportModelBuilder reportModelBuilder) {15 this.scenarioModelBuilder = scenarioModelBuilder;16 this.reportModelBuilder = reportModelBuilder;17 scenarioModel = scenarioModelBuilder.build();18 currentStepList = scenarioModel.getSteps();19 }20 public StepFormatter addStep(String stepName) {21 StepModel step = new StepModel(stepName);22 currentStep = step;23 currentStepList.add(step);24 return this;25 }26 public StepFormatter addStep(String stepName, String stepDescription) {27 StepModel step = new StepModel(stepName, stepDescription);28 currentStep = step;29 currentStepList.add(step);30 return this;31 }32 public StepFormatter addStep(String stepName, String stepDescription, String stepStatus) {33 StepModel step = new StepModel(stepName, stepDescription, stepStatus);34 currentStep = step;35 currentStepList.add(step);36 return this;37 }38 public StepFormatter addStep(String stepName, String stepDescription, String stepStatus, String stepDuration) {39 StepModel step = new StepModel(stepName, stepDescription, stepStatus, stepDuration);40 currentStep = step;41 currentStepList.add(step);42 return this;43 }44 public StepFormatter addStep(String stepName, String stepDescription, String stepStatus, String stepDuration,45 String stepException) {46 StepModel step = new StepModel(stepName, stepDescription, stepStatus, stepDuration, stepException);47 currentStep = step;48 currentStepList.add(step);49 return this;50 }51 public StepFormatter addStep(String stepName, String stepDescription, String stepStatus, String stepDuration,

Full Screen

Full Screen

StepFormatter

Using AI Code Generation

copy

Full Screen

1StepFormatter formatter = new StepFormatter();2formatter.setIndent(0);3formatter.setStepNumber(1);4formatter.setStepText("This is a step");5formatter.setStepType(StepType.GIVEN);6formatter.setDuration(1000L);7formatter.setDurationUnit(TimeUnit.MILLISECONDS);8formatter.setStatus(Status.PASSED);9formatter.setErrorMessage("This is a error message");10formatter.setExceptionType("java.lang.RuntimeException");11formatter.setExceptionMessage("This is a exception message");12formatter.setExceptionStackTrace("This is a stack trace");13System.out.println(formatter.getFormattedStep());141. This is a step (1 ms)151. This is a step (1 ms)

Full Screen

Full Screen

StepFormatter

Using AI Code Generation

copy

Full Screen

1StepFormatter stepFormatter = new StepFormatter();2stepFormatter.addTable("table with one row");3stepFormatter.addRow("row1");4stepFormatter.addTable("table with two rows");5stepFormatter.addRow("row1");6stepFormatter.addRow("row2");7stepFormatter.addTable("table with three rows");8stepFormatter.addRow("row1");9stepFormatter.addRow("row2");10stepFormatter.addRow("row3");11stepFormatter.addTable("table with four rows");12stepFormatter.addRow("row1");13stepFormatter.addRow("row2");14stepFormatter.addRow("row3");15stepFormatter.addRow("row4");16stepFormatter.addTable("table with five rows");17stepFormatter.addRow("row1");18stepFormatter.addRow("row2");19stepFormatter.addRow("row3");20stepFormatter.addRow("row4");21stepFormatter.addRow("row5");22stepFormatter.addTable("table with six rows");23stepFormatter.addRow("row1");24stepFormatter.addRow("row2");25stepFormatter.addRow("row3");26stepFormatter.addRow("row4");27stepFormatter.addRow("row5");28stepFormatter.addRow("row6");29stepFormatter.addTable("table with seven rows");30stepFormatter.addRow("row1");31stepFormatter.addRow("row2");32stepFormatter.addRow("row3");33stepFormatter.addRow("row4");34stepFormatter.addRow("row5");35stepFormatter.addRow("row6");36stepFormatter.addRow("row7");37stepFormatter.addTable("table with eight rows");38stepFormatter.addRow("row1");39stepFormatter.addRow("row2");40stepFormatter.addRow("row3");41stepFormatter.addRow("row4");42stepFormatter.addRow("row5");43stepFormatter.addRow("row6");44stepFormatter.addRow("row7");45stepFormatter.addRow("row8");46stepFormatter.addTable("table with nine rows");47stepFormatter.addRow("row1");48stepFormatter.addRow("row2");49stepFormatter.addRow("row3");50stepFormatter.addRow("row4");51stepFormatter.addRow("row5");52stepFormatter.addRow("row6");53stepFormatter.addRow("row7");54stepFormatter.addRow("row8");55stepFormatter.addRow("row9");56stepFormatter.addTable("table with ten rows");57stepFormatter.addRow("row1");58stepFormatter.addRow("row2");59stepFormatter.addRow("row3");60stepFormatter.addRow("row4");61stepFormatter.addRow("row5");62stepFormatter.addRow("row6");63stepFormatter.addRow("row7

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