How to use getColumnSpecs method of com.tngtech.jgiven.report.text.PlainTextTableWriter class

Best JGiven code snippet using com.tngtech.jgiven.report.text.PlainTextTableWriter.getColumnSpecs

Source:PlainTextTableWriter.java Github

copy

Full Screen

...23 }24 StringBuilder formatBuilder = new StringBuilder();25 StringBuilder lineBuilder = new StringBuilder();26 List<List<String>> tableModel = handleNewLines( dataTable.getData() );27 List<ColumnSpec> columnWidths = getColumnSpecs( tableModel );28 for( ColumnSpec spec : columnWidths ) {29 formatBuilder.append( "| %" );30 if( spec.leftAligned ) {31 formatBuilder.append( "-" );32 }33 formatBuilder.append( spec.width + "s " );34 lineBuilder.append( "+" );35 lineBuilder.append( Strings.repeat( "-", spec.width + 2 ) );36 }37 formatBuilder.append( "|" );38 lineBuilder.append( "+" );39 String formatString = formatBuilder.toString();40 writer.println( indent + String.format( formatString, tableModel.get( 0 ).toArray() ) );41 if( dataTable.getHeaderType().isHorizontal() ) {42 writer.println( indent + lineBuilder );43 }44 for( int nrow = 1; nrow < tableModel.size(); nrow++ ) {45 writer.println( indent + String.format( formatString, tableModel.get( nrow ).toArray() ) );46 }47 }48 /**49 * Handles newlines by removing them and add new rows instead 50 */51 static List<List<String>> handleNewLines( List<List<String>> tableModel ) {52 List<List<String>> result = Lists.newArrayListWithExpectedSize( tableModel.size() );53 for( List<String> row : tableModel ) {54 if( hasNewline( row ) ) {55 result.addAll( splitRow( row ) );56 } else {57 result.add( row );58 }59 }60 return result;61 }62 static private Collection<List<String>> splitRow( List<String> row ) {63 List<List<String>> columns = Lists.newArrayListWithExpectedSize( row.size() );64 int nRows = 0;65 for( String cell : row ) {66 List<String> lines = FluentIterable.from( Splitter.onPattern( "\\r?\\n" ).split( cell ) ).toList();67 if( lines.size() > nRows ) {68 nRows = lines.size();69 }70 columns.add( lines );71 }72 List<List<String>> rows = Lists.newArrayListWithCapacity( nRows );73 for( int iRow = 0; iRow < nRows; iRow++ ) {74 List<String> newRow = Lists.newArrayListWithExpectedSize( row.size() );75 for( int iCol = 0; iCol < columns.size(); iCol++ ) {76 List<String> column = columns.get( iCol );77 String cell = "";78 if( iRow < column.size() ) {79 cell = column.get( iRow );80 }81 newRow.add( cell );82 }83 rows.add( newRow );84 }85 return rows;86 }87 static private boolean hasNewline( List<String> row ) {88 for( String cell : row ) {89 if( cell != null && cell.contains( "\n" ) ) {90 return true;91 }92 }93 return false;94 }95 private List<ColumnSpec> getColumnSpecs( List<List<String>> dataTableModel ) {96 if( dataTableModel.isEmpty() ) {97 return Collections.emptyList();98 }99 ColumnSpec[] result = new ColumnSpec[dataTableModel.get( 0 ).size()];100 for( int nrow = 0; nrow < dataTableModel.size(); nrow++ ) {101 List<String> row = dataTableModel.get( nrow );102 for( int ncol = 0; ncol < row.size(); ncol++ ) {103 String value = row.get( ncol );104 int width = Math.max( value.length(), 1 );105 ColumnSpec spec = result[ncol];106 if( spec == null ) {107 spec = new ColumnSpec();108 result[ncol] = spec;109 }...

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 method in PlainTextTableWriter

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful