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

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

Source:DefaultTableFormatter.java Github

copy

Full Screen

...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;...

Full Screen

Full Screen

Source:MediaType.java Github

copy

Full Screen

1package com.tngtech.jgiven.attachment;2import static com.tngtech.jgiven.attachment.MediaType.Type.*;3import java.nio.charset.Charset;4import com.tngtech.jgiven.impl.util.ApiUtil;5/**6 * Represents a (simplified) <a href="http://www.iana.org/assignments/media-types/media-types.xhtml">Media Type</a>.7 * @since 0.7.08 */9public class MediaType {10 private static final Charset UTF_8 = Charset.forName( "utf8" );11 /**12 * Represents the type of a Media Type13 */14 public static enum Type {15 APPLICATION( "application" ),16 AUDIO( "audio" ),17 IMAGE( "image" ),18 TEXT( "text" ),19 VIDEO( "video" );20 private final String value;21 Type( String value ) {22 this.value = value;23 }24 @Override25 public String toString() {26 return value;27 }28 /**29 * Get the type from a given string30 */31 public static Type fromString( String string ) {32 for( Type type : values() ) {33 if( type.value.equalsIgnoreCase( string ) ) {34 return type;35 }36 }37 throw new IllegalArgumentException( "Unknown type " + string );38 }39 }40 /**41 * image/gif42 */43 public static final MediaType GIF = image( "gif" );44 /**45 * image/png46 */47 public static final MediaType PNG = image( "png" );48 /**49 * image/jpeg50 */51 public static final MediaType JPEG = image( "jpeg" );52 /**53 * image/svg+xml54 */55 public static final MediaType SVG_UTF_8 = imageUtf8( "svg+xml; charset=utf-8" );56 /**57 * text/plain58 */59 public static final MediaType PLAIN_TEXT_UTF_8 = textUtf8( "plain" );60 /**61 * application/json62 */63 public static final MediaType JSON_UTF_8 = applicationUtf8( "json" );64 /**65 * application/xml66 */67 public static final MediaType APPLICATION_XML_UTF_8 = applicationUtf8( "xml" );68 /**69 * text/xml70 */71 public static final MediaType XML_UTF_8 = textUtf8( "xml" );72 private final Type type;73 private final String subType;74 private final boolean binary;75 /**76 * An optional charset, can be {@code null}77 */78 private final Charset charset;79 /**80 * Creates a new MediaType81 * @param type the type82 * @param subType the subtype83 * @param binary whether or not content of this media type is binary. If {@code true}, the84 * content will be encoded as Base64 when stored in the JSON model.85 * @throws com.tngtech.jgiven.exception.JGivenWrongUsageException if any of the parameters is {@code null}86 */87 private MediaType( Type type, String subType, boolean binary ) {88 this.type = ApiUtil.notNull( type, "type must not be null" );89 this.subType = ApiUtil.notNull( subType, "subType must not be null" );90 this.binary = binary;91 this.charset = null;92 }93 private MediaType( Type type, String subType, Charset charset ) {94 this.type = ApiUtil.notNull( type, "type must not be null" );95 this.subType = ApiUtil.notNull( subType, "subType must not be null" );96 this.charset = ApiUtil.notNull( charset, "charset must not be null" );97 this.binary = false;98 }99 /**100 * The type of the Media Type.101 */102 public Type getType() {103 return type;104 }105 /**106 * The subtype of the Media Type.107 */108 public String getSubType() {109 return subType;110 }111 /**112 * Whether this media type is binary or not.113 */114 public boolean isBinary() {115 return binary;116 }117 public boolean isImage() {118 return type == IMAGE;119 }120 /**121 * @return the charset of this media type if one is specified122 * @throws java.lang.IllegalArgumentException if no charset is specified123 */124 public Charset getCharset() {125 if( charset == null ) {126 throw new IllegalArgumentException( "No charset is specified for media type " + this );127 }128 return charset;129 }130 public String asString() {131 return type.value + "/" + subType;132 }133 /**134 * Creates a binary media type with the given type and subtype135 * @throws com.tngtech.jgiven.exception.JGivenWrongUsageException if any of the given arguments is {@code null}136 */137 public static MediaType binary( MediaType.Type type, String subType ) {138 return new MediaType( type, subType, true );139 }140 /**141 * Creates a non-binary media type with the given type, subtype, and charSet142 * @throws com.tngtech.jgiven.exception.JGivenWrongUsageException if any of the given arguments is {@code null}143 */144 public static MediaType nonBinary( MediaType.Type type, String subType, Charset charSet ) {145 ApiUtil.notNull( charSet, "charset must not be null" );146 return new MediaType( type, subType, charSet );147 }148 /**149 * Creates a non-binary media type with the given type, subtype, and UTF-8 encoding150 * @throws com.tngtech.jgiven.exception.JGivenWrongUsageException if any of the given arguments is {@code null}151 */152 public static MediaType nonBinaryUtf8( MediaType.Type type, String subType ) {153 return new MediaType( type, subType, UTF_8 );154 }155 /**156 * Creates a binary image media type with the given subtype.157 */158 public static MediaType image( String subType ) {159 return binary( IMAGE, subType );...

Full Screen

Full Screen

Source:ApiUtil.java Github

copy

Full Screen

2import com.tngtech.jgiven.exception.JGivenWrongUsageException;3/**4 * This util is used for checking inputs of API methods5 */6public class ApiUtil {7 public static <T> T notNull(T o, String message) {8 if (o == null) {9 throw new JGivenWrongUsageException(message);10 }11 return o;12 }13 public static void isTrue(boolean b, String message) {14 if (!b) {15 throw new JGivenWrongUsageException(message);16 }17 }18}...

Full Screen

Full Screen

ApiUtil

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.impl.util.ApiUtil;2public class ApiUtilExample {3 public static void main(String[] args) {4 System.out.println(ApiUtil.getCallerClass(0));5 System.out.println(ApiUtil.getCallerClass(1));6 System.out.println(ApiUtil.getCallerClass(2));7 System.out.println(ApiUtil.getCallerClass(3));8 System.out.println(ApiUtil.getCallerClass(4));9 System.out.println(ApiUtil.getCallerClass(5));10 }11}

Full Screen

Full Screen

ApiUtil

Using AI Code Generation

copy

Full Screen

1package com.mycompany.myapp;2import com.tngtech.jgiven.impl.util.ApiUtil;3public class TestUtil {4 public static void main(String[] args) {5 ApiUtil.getCallerClass();6 }7}

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 ApiUtil

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