All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.accenture.testing.bdd.parameters.FakerTransform Maven / Gradle / Ivy

Go to download

A simple to use, easy to integrate, BDD library for API and microservices development.

The newest version!
package com.accenture.testing.bdd.parameters;

import com.github.javafaker.Faker;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FakerTransform extends ParamTransform {

  @Override
  String key() {
    return "faker";
  }

  @Override
  String transform(String params, ParamTransformer pt) {

    List args = new ArrayList<>(Arrays.asList(params.split(",")));

    String reflect = args.remove(0);
    String lang = args.isEmpty() ? Locale.getDefault().toLanguageTag() : args.remove(0);

    try {
      Faker faker = Faker.instance(new Locale(lang));
      return faker.expression("#{" + reflect + "}");
    } catch (Exception e) {
      log.error("Attempting to generate data on {}", params, e);
    }

    return params;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy