title: TestNG @Factory annotation + not enough knowledge on Dependency Injection
body: <p>I am just learning dependency injection and I dont get its logic at all. Not to mention, TestNG's requirements are always too bizarre for me.</p>
  
  <p>I have this class that provides the data, and a test class that needs it:</p>
  
  <pre><code>public abstract class AppData { // extends Mailer
  
      @DataProvider(name = "dataProvider")
      public static Object[][] setUp() throws Exception {
  
  
          //prepare the data here - code.
  
          //pass the data to the test case
          Object[][] setUp = new Object[1][4];
          setUp[0][0] = driver;
          setUp[0][1] = wait;
          setUp[0][2] = array;
          setUp[0][3] = array2;   
          return setUp;
      }
  }
  </code></pre>
  
  <p>and this is the test class</p>
  
  <pre><code>public class AppTest { 
  
  //this is my attempt to make a dependency injection, completely blindly shooting in the dark
      private AppData appdata;
  
      public AppTest (
              AppData appdata
          ) {
             this.appdata = appdata;
          }
  
  
  
  @Factory(dataProviderClass=com.fmydomain.tests.AppData.class,dataProvider="dataProvider")
      public void oneUserTwoUser(WebDriver driver, WebDriverWait wait, ArrayList&lt;ArrayList&lt;String&gt;&gt; array, ArrayList&lt;ArrayList&lt;String&gt;&gt; array2) throws Exception {
  
      }
  }
  </code></pre>
  
  <p>and Im getting this error when I run it:</p>
  
  <pre><code>org.testng.TestNGException: 
  The factory method class com.f1rstt.tests.AppTest3.oneUserTwoUser() threw an exception
      at org.testng.internal.FactoryMethod.invoke(FactoryMethod.java:93)
      at org.testng.internal.TestNGClassFinder.&lt;init&gt;(TestNGClassFinder.java:140)
  </code></pre>
  
  <p>EDIT: I have also tried the following way:</p>
  
  <pre><code>public class AppTest3 { 
  
      private AppData appdata = new AppData();
  
      public AppTest3(AppData appdata) {
          this.appdata = appdata;
      }
  
      WebDriver driver = AppData.driver;
      WebDriverWait wait = AppData.wait;
      ArrayList&lt;ArrayList&lt;String&gt;&gt; array = AppData.array;
      //ArrayList&lt;ArrayList&lt;String&gt;&gt; array2 = AppData.array2;
  
      @Parameters({ "driver", "wait", "array" })
      @Test
      public void oneUserTwoUser(WebDriver driver, WebDriverWait wait, ArrayList&lt;ArrayList&lt;String&gt;&gt; array) throws Exception {
  </code></pre>
  
  <p>but I get this error:</p>
  
  <pre><code>org.testng.TestNGException: 
  Parameter 'driver' is required by @Test on method oneUserTwoUser but has not been marked @Optional or defined
  </code></pre>