The purpose of these tests is to ensure that the Locales have been properly configured and that methods return values. The unit tests should ensure what the values returned are correct. These tests just ensure that the methods can be invoked.
| 27 | * are correct. These tests just ensure that the methods can be invoked. |
| 28 | */ |
| 29 | @RunWith(value = Parameterized.class) |
| 30 | public class FakerIT { |
| 31 | |
| 32 | private static final Logger logger = LoggerFactory.getLogger(FakerIT.class); |
| 33 | private final Locale locale; |
| 34 | private final Faker faker; |
| 35 | |
| 36 | /** |
| 37 | * a collection of Locales -> Exceptions. |
| 38 | * In the case of 'pt', city_prefix is '' by design. This test fails because it's testing that all string returning |
| 39 | * methods return a non blank string. But pt city_prefix is blank ,but the test shouldn't fail. So we add put |
| 40 | * exceptions like this into this collection. |
| 41 | */ |
| 42 | private static final Map<Locale, List<String>> exceptions = Maps.newHashMap(); |
| 43 | static { |
| 44 | // 'it' has an empty suffix list so it never returns a value |
| 45 | exceptions.put(new Locale("it"), Arrays.asList("Name.suffix")); |
| 46 | exceptions.put(new Locale("es-mx"), Arrays.asList("Address.cityPrefix", "Address.citySuffix")); |
| 47 | exceptions.put(new Locale("pt"), Arrays.asList("Address.cityPrefix", "Address.citySuffix")); |
| 48 | exceptions.put(new Locale("uk"), Arrays.asList("Address.stateAbbr", "Address.streetSuffix", |
| 49 | "Address.cityPrefix", "Address.citySuffix")); |
| 50 | } |
| 51 | |
| 52 | public FakerIT(Locale locale, Random random) { |
| 53 | this.locale = locale; |
| 54 | if (locale != null && random != null) { |
| 55 | faker = new Faker(locale, random); |
| 56 | } else if (locale != null) { |
| 57 | faker = new Faker(locale); |
| 58 | } else if (random != null) { |
| 59 | faker = new Faker(random); |
| 60 | } else { |
| 61 | faker = new Faker(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | @Parameterized.Parameters(name = "testing locale {0} and random {1}") |
| 66 | public static Collection<Object[]> data() { |
| 67 | Object[][] data = new Object[][]{ |
| 68 | {Locale.ENGLISH, new Random()}, |
| 69 | {new Locale("pt-BR"), null}, |
| 70 | {new Locale("pt-br"), null}, |
| 71 | {new Locale("Pt_br"), null}, |
| 72 | {new Locale("pT_Br"), null}, |
| 73 | {new Locale("pt","Br","x2"), null}, |
| 74 | {null, new Random()}, |
| 75 | {null, null}}; |
| 76 | |
| 77 | String[] ymlFiles = new File("./src/main/resources").list(); |
| 78 | int numberOfYmlFiles = ymlFiles.length; |
| 79 | Object[][] dataFromYmlFiles = new Object[numberOfYmlFiles][2]; |
| 80 | for (int i = 0; i < numberOfYmlFiles; i++) { |
| 81 | String ymlFileName = ymlFiles[i]; |
| 82 | dataFromYmlFiles[i][0] = new Locale(StringUtils.substringBefore(ymlFileName, ".")); |
| 83 | } |
| 84 | |
| 85 | List<Object[]> allData = new ArrayList<Object[]>(Arrays.asList(data)); |
| 86 | allData.addAll(Arrays.asList(dataFromYmlFiles)); |
nothing calls this directly
no outgoing calls
no test coverage detected