11package com .codedifferently .lesson9 ;
22
3- import com .codedifferently .lesson9 .generator .SampleFileGenerator ;
43import java .io .File ;
54import java .nio .file .Paths ;
5+ import java .util .List ;
6+
67import org .springframework .boot .CommandLineRunner ;
78import org .springframework .boot .SpringApplication ;
89import org .springframework .boot .autoconfigure .SpringBootApplication ;
910import org .springframework .context .annotation .Configuration ;
1011
12+ import com .codedifferently .lesson9 .dataprovider .DataProvider ;
13+ import com .codedifferently .lesson9 .generator .SampleFileGenerator ;
14+
1115@ Configuration
1216@ SpringBootApplication (scanBasePackages = "com.codedifferently" )
1317public class Lesson9 implements CommandLineRunner {
14-
18+ private final List <DataProvider > providers ;
19+ public Lesson9 (List <DataProvider > providers ) {
20+ this .providers = providers ;
21+ }
1522 public static void main (String [] args ) {
1623 var application = new SpringApplication (Lesson9 .class );
1724 application .run (args );
@@ -22,23 +29,23 @@ public void run(String... args) throws Exception {
2229 return ;
2330 }
2431
25- var providerName = args [0 ];
26- if (providerName == null ) {
32+ var option = args [0 ];
33+ if (option == null ) {
2734 throw new IllegalArgumentException ("Provider name is required" );
2835 }
29- if (providerName .equals ("--all" )){
36+ if (option .equals ("--all" )){
3037 //TODO: change providers to search dynamically for all available providers
31- String [] providers = { "danielsonadjocy" , "johnsonjames" , "smithjane" , "williamsrobert" };
32- for ( String provider : providers ) {
38+ for ( DataProvider provider : providers ) {
39+ String providerName = provider . getClass (). getSimpleName (). replace ( "Provider" , "" );
3340 String path = getDataPath ();
3441 var fileGenerator = new SampleFileGenerator ();
35- // fileGenerator.createProviderFile(path, providerName, provider);
42+ fileGenerator .createProviderFile (path , providerName , provider );
3643 }
3744 return ;
3845 }
3946 String path = getDataPath ();
4047 var fileGenerator = new SampleFileGenerator ();
41- fileGenerator .createTestFile (path , providerName );
48+ fileGenerator .createTestFile (path , option );
4249 }
4350
4451 private static String getDataPath () {
0 commit comments