| 1 |
|
package guru.mikelue.foxglove.instancio; |
| 2 |
|
|
| 3 |
|
import java.util.function.Supplier; |
| 4 |
|
|
| 5 |
|
import org.instancio.Instancio; |
| 6 |
|
import org.instancio.generator.ValueSpec; |
| 7 |
|
import org.instancio.generator.specs.ByteSpec; |
| 8 |
|
|
| 9 |
|
|
| 10 |
|
@link |
| 11 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 13 |
Complexity Density: 0.65 |
|
| 12 |
|
public class ByteArraySpec implements ValueSpec<byte[]> { |
| 13 |
|
private boolean nullable = false; |
| 14 |
|
private ByteSpec byteSpec = Instancio.gen().bytes(); |
| 15 |
|
private int minLength = 16; |
| 16 |
|
private int maxLength = 128; |
| 17 |
|
private int length = -1; |
| 18 |
|
|
| 19 |
|
private Supplier<Byte> byteSupplier = byteSpec; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 24 |
31 |
public ByteArraySpec() {}... |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
@param |
| 30 |
|
|
| 31 |
|
@return |
| 32 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 33 |
17 |
public ByteArraySpec length(int length)... |
| 34 |
|
{ |
| 35 |
17 |
this.length = length; |
| 36 |
17 |
return this; |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
@param |
| 43 |
|
|
| 44 |
|
@return |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 46 |
13 |
public ByteArraySpec minLength(int min)... |
| 47 |
|
{ |
| 48 |
13 |
this.minLength = min; |
| 49 |
13 |
return this; |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
@param |
| 56 |
|
|
| 57 |
|
@return |
| 58 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 59 |
13 |
public ByteArraySpec maxLength(int max)... |
| 60 |
|
{ |
| 61 |
13 |
this.maxLength = max; |
| 62 |
13 |
return this; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@return |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 70 |
1 |
public ByteArraySpec zeroElements()... |
| 71 |
|
{ |
| 72 |
1 |
this.byteSpec = this.byteSpec.nullable(); |
| 73 |
1 |
this.byteSupplier = this::nullableByte; |
| 74 |
|
|
| 75 |
1 |
return this; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
private final static ValueSpec<Integer> diceSpec = Instancio.gen().ints().range(1, 6); |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@inheritDoc |
| 82 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 5 |
Complexity Density: 0.71 |
|
| 83 |
696 |
@Override... |
| 84 |
|
public byte[] get() |
| 85 |
|
{ |
| 86 |
696 |
if (nullable && diceSpec.get() == 1) { |
| 87 |
1 |
return null; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
695 |
int arrayLength = length > 0 ? length : Instancio.gen().ints().range(minLength, maxLength).get(); |
| 91 |
695 |
byte[] result = new byte[arrayLength]; |
| 92 |
230433 |
for (int i = 0; i < arrayLength; i++) { |
| 93 |
229738 |
result[i] = byteSupplier.get(); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
695 |
return result; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
@inheritDoc |
| 101 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 102 |
1 |
@Override... |
| 103 |
|
public ValueSpec<byte[]> nullable() |
| 104 |
|
{ |
| 105 |
1 |
nullable = true; |
| 106 |
1 |
return this; |
| 107 |
|
} |
| 108 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 109 |
512 |
private byte nullableByte()... |
| 110 |
|
{ |
| 111 |
512 |
Byte v = byteSpec.get(); |
| 112 |
512 |
return v != null ? v : 0x00; |
| 113 |
|
} |
| 114 |
|
} |
| 115 |
|
|