title: how to test a method of swapping 2 elements in array using Junit
body: <p>I have write 2 method in class which swaps 2 elements in array. But I am not sure how to test my methods in JUnit, I want to test if the 2 elements as correctly swapped, and to check if the index in array is valid. Finally a test to check if method will swap strings as well as double. </p>
  
  <pre><code>import java.util.Arrays;
  
  public class GenericExample {
  
  int index1;
  int index2; 
  
  public static &lt;T&gt; T [] swap(T[] array, int index1, int index2)
  {
      T temp = array[index1];
      array [index1] = array [index2] ;
      array [index2] = temp;
  
      return array;
  
  }
  
  public static void main(String[] args) {
      Integer [ ] array = {1, 2, 3, 4};
      System.out.println("Array is: " + Arrays.toString(array));
      swap(array,1,3);
      System.out.println("Array is: " + Arrays.toString(array));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the test class which I have created to test the code of this.
  <a href="https://i.stack.imgur.com/pva16.png" rel="nofollow">TestClass</a></p>