title: JUnit test - Wrong number of parameters and @Parameter fields
body: <p>I have no experience with JUnit tests, but I am trying to learn them. For start, I wrote a very simple class <code>UrlParams</code>, which contains two public methods - <code>void addParameter(String name, String value)</code> and <code>String buildUrl()</code>. The usage of my class is also very simple.</p>
  
  <pre><code>UrlParams urlParams = new UrlParams("http://baseurl.com");
  urlParams.addParameter("name1", "value1");
  urlParams.addParameter("name2", "value2");
  String url = urlParams.buildUrl();
  System.out.println(url);
  </code></pre>
  
  <p>The output from this code is <code>http://baseurl.com?name1=value1&amp;name2=value2</code>.</p>
  
  <p>Now, I am trying to write test class. I would like to test my class with different count of parameters, so I decided to use parameterized test. I wrote following code:</p>
  
  <pre><code>@RunWith(Parameterized.class)
  public class UrlParamsTest {
  
      @Parameterized.Parameter(value = 0)
      public UrlParameter[] paramsList;
  
  
      @Parameterized.Parameters
      public static Collection&lt;Object[]&gt; data() {
          List&lt;Object[]&gt; data = new LinkedList&lt;Object[]&gt;();
  
          // Test 1
          UrlParameter[] parameterList1 = new UrlParameter[3];
          parameterList1[0] = new UrlParameter("name1", "value1");
          parameterList1[1] = new UrlParameter("name2", "value2");
          parameterList1[2] = new UrlParameter("name3", "value3");
  
          // Test 2
          UrlParameter[] parameterList2 = new UrlParameter[2];
          parameterList2[0] = new UrlParameter("name1", "value1");
          parameterList2[1] = new UrlParameter("name2", "value2");
  
          // Test 3
          UrlParameter[] parameterList3 = new UrlParameter[0];
  
          data.add(parameterList1);
          data.add(parameterList2);
          data.add(parameterList3);
          return data;
      }
  
      @Test
      public void buildUrlTest() {
          final String baseUrl = "http://baseurl.com";
          UrlParams urlParams = new UrlParams(baseUrl);
  
          String expected = baseUrl;
          if (paramsList.length &gt; 0) {
              expected += "?";
          }
  
          int index = 0;
          for (UrlParameter p : paramsList) {
              urlParams.addParameter(p.name, p.value);
              expected += p.name + "=" + p.value;
              if (index != paramsList.length - 1) {
                  expected += "&amp;";
              }
          }
          String buildUrl = urlParams.buildUrl();
  
          assertEquals(expected, buildUrl);
          System.out.println("Expected = " + expected + " Created = " + buildUrl);
      }
  
  
      static class UrlParameter {
          String name, value;
  
          public UrlParameter(String name, String value) {
              this.name = name;
              this.value = value;
          }
      }
  }
  </code></pre>
  
  <p>If I am trying to run this test, I see the exceptions below.</p>
  
  <pre><code>java.lang.Exception: Wrong number of parameters and @Parameter fields. @Parameter fields counted: 1, available parameters: 3.
  java.lang.Exception: Wrong number of parameters and @Parameter fields. @Parameter fields counted: 1, available parameters: 2.
  java.lang.Exception: Wrong number of parameters and @Parameter fields. @Parameter fields counted: 1, available parameters: 0.
  </code></pre>
  
  <p>I am new in JUnit tests and I have no idea what is wrong. Could you tell me please, what I am doing wrong? Thank you.</p>