net.jqwik.engine.execution.reporting.ArrayReportingFormat Maven / Gradle / Ivy
package net.jqwik.engine.execution.reporting;
import java.util.*;
import net.jqwik.api.*;
public class ArrayReportingFormat implements SampleReportingFormat {
@Override
public boolean appliesTo(Object value) {
return value.getClass().isArray();
}
@Override
public Object report(Object value) {
Class> arrayClass = value.getClass();
if (arrayClass.equals(byte[].class)) {
List list = new ArrayList<>();
for (byte v : ((byte[]) value)) {
list.add(v);
}
return list;
}
if (arrayClass.equals(short[].class)) {
List list = new ArrayList<>();
for (short v : ((short[]) value)) {
list.add(v);
}
return list;
}
if (arrayClass.equals(int[].class)) {
List list = new ArrayList<>();
for (int v : ((int[]) value)) {
list.add(v);
}
return list;
}
if (arrayClass.equals(long[].class)) {
List list = new ArrayList<>();
for (long v : ((long[]) value)) {
list.add(v);
}
return list;
}
if (arrayClass.equals(char[].class)) {
List list = new ArrayList<>();
for (char v : ((char[]) value)) {
list.add(v);
}
return list;
}
if (arrayClass.equals(float[].class)) {
List list = new ArrayList<>();
for (float v : ((float[]) value)) {
list.add(v);
}
return list;
}
if (arrayClass.equals(double[].class)) {
List list = new ArrayList<>();
for (double v : ((double[]) value)) {
list.add(v);
}
return list;
}
if (arrayClass.equals(boolean[].class)) {
List list = new ArrayList<>();
for (boolean v : ((boolean[]) value)) {
list.add(v);
}
return list;
}
return Arrays.asList((Object[]) value);
}
@Override
public Optional label(Object value) {
Class> arrayClass = value.getClass();
String baseClassName = arrayClass.getTypeName().startsWith("java.lang")
? arrayClass.getSimpleName()
: arrayClass.getTypeName();
return Optional.of(String.format("%s ", baseClassName));
}
}