How to use AnnotationUtil class of com.tngtech.jgiven.impl.util package

Best JGiven code snippet using com.tngtech.jgiven.impl.util.AnnotationUtil

Source:DefaultTableFormatter.java Github

copy

Full Screen

...10import com.tngtech.jgiven.config.FormatterConfiguration;11import com.tngtech.jgiven.exception.JGivenWrongUsageException;12import com.tngtech.jgiven.format.DefaultFormatter;13import com.tngtech.jgiven.format.ObjectFormatter;14import com.tngtech.jgiven.impl.util.AnnotationUtil;15import com.tngtech.jgiven.impl.util.ApiUtil;16import com.tngtech.jgiven.impl.util.ReflectionUtil;17import com.tngtech.jgiven.report.model.DataTable;18/**19 * The default implementation to format a table argument20 */21public class DefaultTableFormatter implements TableFormatter {22 public static final String DEFAULT_NUMBERED_HEADER = "#";23 private final FormatterConfiguration formatterConfiguration;24 private final ObjectFormatter<?> objectFormatter;25 public DefaultTableFormatter( FormatterConfiguration formatterConfiguration, ObjectFormatter<?> objectFormatter ) {26 this.formatterConfiguration = formatterConfiguration;27 this.objectFormatter = objectFormatter;28 }29 @Override30 public DataTable format( Object tableArgument, Table tableAnnotation, String parameterName, Annotation... allAnnotations ) {31 DataTable dataTable = toDataTable( tableArgument, tableAnnotation, parameterName, allAnnotations );32 addNumberedRows( tableAnnotation, dataTable );33 addNumberedColumns( tableAnnotation, dataTable );34 return dataTable;35 }36 private static void addNumberedRows( Table tableAnnotation, DataTable dataTable ) {37 String customHeader = tableAnnotation.numberedRowsHeader();38 boolean hasCustomerHeader = !customHeader.equals( AnnotationUtil.ABSENT );39 if( tableAnnotation.numberedRows() || hasCustomerHeader ) {40 ApiUtil.isTrue( !hasCustomerHeader || dataTable.hasHorizontalHeader(),41 "Using numberedRowsHeader in @Table without having a horizontal header." );42 int rowCount = dataTable.getRowCount();43 List<String> column = Lists.newArrayListWithExpectedSize( rowCount );44 addHeader( customHeader, column, dataTable.hasHorizontalHeader() );45 addNumbers( rowCount, column );46 dataTable.addColumn( 0, column );47 }48 }49 private static void addNumberedColumns( Table tableAnnotation, DataTable dataTable ) {50 String customHeader = tableAnnotation.numberedColumnsHeader();51 boolean hasCustomerHeader = !customHeader.equals( AnnotationUtil.ABSENT );52 if( tableAnnotation.numberedColumns() || hasCustomerHeader ) {53 ApiUtil.isTrue( !hasCustomerHeader || dataTable.hasVerticalHeader(),54 "Using numberedColumnsHeader in @Table without having a vertical header." );55 int columnCount = dataTable.getColumnCount();56 List<String> row = Lists.newArrayListWithExpectedSize( columnCount );57 addHeader( customHeader, row, dataTable.hasVerticalHeader() );58 addNumbers( columnCount, row );59 dataTable.addRow( 0, row );60 }61 }62 private static void addHeader( String customHeader, List<String> column, boolean hasHeader ) {63 boolean hasCustomerHeader = !customHeader.equals( AnnotationUtil.ABSENT );64 if( hasHeader ) {65 String header = DEFAULT_NUMBERED_HEADER;66 if( hasCustomerHeader ) {67 header = customHeader;68 }69 column.add( header );70 }71 }72 private static void addNumbers( int count, List<String> column ) {73 int counter = 1;74 while( column.size() < count ) {75 column.add( Integer.toString( counter ) );76 counter++;77 }...

Full Screen

Full Screen

Source:StepModelFactory.java Github

copy

Full Screen

...6import java.util.List;7import com.google.common.collect.Lists;8import com.tngtech.jgiven.annotation.ExtendedDescription;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])) {84 result.add(arguments.get(i));85 }86 }87 return result;88 }89}...

Full Screen

Full Screen

Source:TableAnnotation.java Github

copy

Full Screen

...5import com.tngtech.jgiven.format.table.DefaultRowFormatterFactory;6import com.tngtech.jgiven.format.table.DefaultTableFormatter;7import com.tngtech.jgiven.format.table.RowFormatterFactory;8import com.tngtech.jgiven.format.table.TableFormatterFactory;9import com.tngtech.jgiven.impl.util.AnnotationUtil;10public class TableAnnotation implements Table {11 HeaderType header = HeaderType.HORIZONTAL;12 boolean transpose = false;13 boolean includeNullColumns = false;14 String[] excludeFields = {};15 String[] includeFields = {};16 String[] columnTitles = {};17 boolean numberedRows = false;18 boolean numberedColumns = false;19 String numberedRowsHeader = AnnotationUtil.ABSENT;20 String numberedColumnsHeader = AnnotationUtil.ABSENT;21 Class<DefaultTableFormatter.Factory> formatter = DefaultTableFormatter.Factory.class;22 Class<? extends RowFormatterFactory> rowFormatter = DefaultRowFormatterFactory.class;23 ObjectFormatting objectFormatting = ObjectFormatting.FIELDS;24 NamedFormat[] fieldsFormats = new NamedFormat[] {};25 private Class<? extends Annotation> fieldsFormatSetAnnotation = Annotation.class;26 @Override27 public HeaderType header() {28 return header;29 }30 @Override31 public boolean transpose() {32 return transpose;33 }34 @Override...

Full Screen

Full Screen

AnnotationUtil

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.annotation.As;2import com.tngtech.jgiven.annotation.Hidden;3import com.tngtech.jgiven.annotation.ScenarioState;4import com.tngtech.jgiven.impl.util.AnnotationUtil;5import com.tngtech.jgiven.junit.ScenarioTest;6import org.junit.Test;7public class JGivenAnnotationTest extends ScenarioTest<JGivenAnnotationTest.TestStage> {8public void testAnnotation() throws NoSuchMethodException {9 String annotationValue = AnnotationUtil.getAnnotationValue(10 JGivenAnnotationTest.class.getMethod("testAnnotation"),11 ScenarioState.class, "value", String.class);12 System.out.println(annotationValue);13}14@ScenarioState(value = "test")15public void testHidden() throws NoSuchMethodException {16 String annotationValue = AnnotationUtil.getAnnotationValue(17 JGivenAnnotationTest.class.getMethod("testHidden"),18 Hidden.class, "value", String.class);19 System.out.println(annotationValue);20}21@As("test")22public void testAs() throws NoSuchMethodException {23 String annotationValue = AnnotationUtil.getAnnotationValue(24 JGivenAnnotationTest.class.getMethod("testAs"),25 As.class, "value", String.class);26 System.out.println(annotationValue);27}28public static class TestStage {29}30}

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.

Most used methods in AnnotationUtil

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful