Ejemplo n.º 1
0
  @Override
  public Object generate(SourceOfRandomness random, GenerationStatus status) {
    Object array = Array.newInstance(componentType, status.size());
    for (int i = 0; i < Array.getLength(array); ++i)
      Array.set(array, i, component.generate(random, status));

    return array;
  }
 @Override
 public Enum<?> generate(SourceOfRandomness random, GenerationStatus status) {
   Object[] values = enumType.getEnumConstants();
   int index =
       turnOffRandomness == null
           ? random.nextInt(0, values.length - 1)
           : status.attempts() % values.length;
   return (Enum<?>) values[index];
 }
  @Override
  public BigInteger generate(SourceOfRandomness random, GenerationStatus status) {
    int numberOfBits = status.size() + 1;

    if (min == null && max == null) return random.nextBigInteger(numberOfBits);

    BigInteger minToUse = min;
    BigInteger maxToUse = max;
    if (minToUse == null) minToUse = maxToUse.subtract(TEN.pow(numberOfBits));
    else if (maxToUse == null) maxToUse = minToUse.add(TEN.pow(numberOfBits));

    return Ranges.randomBigIntegerInRange(random, minToUse, maxToUse);
  }
Ejemplo n.º 4
0
  @Override
  protected Object generateValue(
      final SourceOfRandomness random,
      final GenerationStatus status,
      final Class<BoxFile> type,
      final String key) {
    if (BoxFile.FIELD_CONTENT_CREATED_AT.equals(key)) {
      return ISO8601DateParser.toString(generateValue(random, status, Date.class));
    }

    if (BoxFile.FIELD_CONTENT_MODIFIED_AT.equals(key)) {
      return ISO8601DateParser.toString(generateValue(random, status, Date.class));
    }

    if (BoxFile.FIELD_CREATED_AT.equals(key)) {
      return ISO8601DateParser.toString(generateValue(random, status, Date.class));
    }

    if (BoxFile.FIELD_MODIFIED_AT.equals(key)) {
      return ISO8601DateParser.toString(generateValue(random, status, Date.class));
    }

    if (BoxFile.FIELD_PATH_COLLECTION.equals(key)) {

      final BoxCollection collection = generateValue(random, status, BoxCollection.class);

      for (int i = 0; i < status.size(); i++) {
        final BoxFolder folder =
            new BoxFolder(
                new HashMap<String, Object>() {
                  {
                    put(BoxFolder.FIELD_NAME, generateValue(random, status, String.class));
                  }
                });

        collection.getEntries().add(folder);
      }

      return collection;
    }

    return super.generateValue(random, status, type, key);
  }