title: Unit testing Linear Search method
body: <p>Im trying to learn some unit testing for more complicated methods. I have a linear search method that searches an array and returns another array that contains the indexes of the "target" if found. How would I go about writing a test for this method?  here is the method below. </p>
  
  <pre><code>public static &lt;T extends Comparable&gt; int[] linearSearch3 (T[] data, T 
         target)
  
     int count = 0;
     int index = 0;
     int[] indices = new int[data.length];
  
  
     for (int i = 0; i &lt; data.length;i++){
         if (data[i] == null) break;
         if (data[i].compareTo(target) == 0){ 
             indices[count] = i;
             count++;
         }
      }
      Arrays.copyOf(indices, count);
      int[] copy = Arrays.copyOf(indices,count);
  
      if(count != 0){
       return copy;
      }
      else 
          return null;
  </code></pre>
  
  <p>Here is what i have so far in my test method. The two arrays are fields of my test class. intArray being the array i'm searching. and newArray being the array i want to return? however, i am not sure if i'm even going about doing this correctly.  Im getting an incompatible types error on the second line. "no instances of type variables T exist so that int[] conforms to Integer where T is a type-variable".</p>
  
  <pre><code>private final Integer[] intArray = {2, 5, 6, 8, 12, 17, 3, 45, 29, 88, 76, 54, 
  1, 12, 5, 41, 12, 99};
  
  private final Integer[] newArray = {2};
  
       @Test
       public &lt;T extends Comparable&gt; void testLinearSearch3() {
  
      System.out.println("Testing LinearSearch3");
      Integer result = Searching.linearSearch3(intArray,(Integer)2);
  </code></pre>
  
  <p>any help would be appreciated. thank you.</p>