@@ -44,6 +44,7 @@ private List<ValueGenerator> getShuffledGenerators() {
4444 return generators ;
4545 }
4646
47+ // Mapping of classes to value generators
4748 private static final Map <Class <?>, ValueGenerator > TYPE_TO_GENERATOR =
4849 Map .of (
4950 Integer .class , new IntValueGenerator (),
@@ -54,25 +55,49 @@ Boolean.class, new BooleanValueGenerator(),
5455 String .class , new StringValueGenerator (),
5556 Double .class , new DoubleValueGenerator ());
5657
58+ /**
59+ * Creates a JSON provider file with generated sample data.
60+ *
61+ * @param path the file path where the provider file will be written
62+ * @param providerName the name of the provider
63+ * @param provider the {DataProvider} that defines columns
64+ * @throws IllegalArgumentException if no generator is found for a column type
65+ */
5766 public void createProviderFile (String path , String providerName , DataProvider provider ) {
5867 var generators = getGenerators (provider );
5968 ArrayList <Map <String , String >> rows = createSampleData (generators );
69+
70+ // Writes the generated rows to a JSON file.
6071 saveToJsonFile (path , providerName , rows );
6172 }
6273
74+ /**
75+ * Retrieves value generators for each column in the given {@link DataProvider}.
76+ *
77+ * <p>The column names are expected to follow the format "column1", "column2", ..., "columnN".
78+ * Each column type must have a corresponding {@link ValueGenerator} in {@code TYPE_TO_GENERATOR}.
79+ * Ensures that the generators are in the same order as the columns in the DataProvider.
80+ *
81+ * @param provider the provider defining column types
82+ * @return a list of value generators, in column order
83+ * @throws IllegalArgumentException if no generator is mapped for a column type
84+ */
6385 private List <ValueGenerator > getGenerators (DataProvider provider ) {
6486 Map <String , Class > columnTypes = provider .getColumnTypeByName ();
65-
6687 ArrayList <ValueGenerator > generators = new ArrayList <>();
88+
6789 for (int i = 1 ; i <= columnTypes .size (); i ++) {
6890 String column = "column" + i ;
6991 Class <?> type = columnTypes .get (column );
92+
93+ // Look up the appropriate generator for this column type.
7094 ValueGenerator generator = TYPE_TO_GENERATOR .get (type );
7195 if (generator == null ) {
7296 throw new IllegalArgumentException ("No generator found for type: " + type );
7397 }
7498 generators .add (generator );
7599 }
100+
76101 return generators ;
77102 }
78103
0 commit comments