0

This is the code snippet I have to test. I am not able to figure out how to test the following method which takes an array as a parameter and returns nothing. Is there a function on JUnit which tests this.

default void print(int[] a) {
   System.out.print("{");
   if (a.length > 0) {
      System.out.print(a[0]);
      for (int i = 1; i < a.length; i++) {
         System.out.print(", " + a[i]);
      }
   }
   System.out.println("}");
}

If I put an Array in the expected field it tells me that an int[] output cannot be compared with a void function. This is what I have written.

@Test
void test() {
   var arr = new Array();
   assertArrayEquals(new int[]{1, 2, 3}, arr.print(new int[]{1, 2, 3}));

}
  • 1
    As an aside: I would advice to use [`Arrays.toString(...)` (`docs.oracle.com`)](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/Arrays.html#toString(int%5B%5D)). – Turing85 Nov 12 '22 at 15:00
  • I was able to solve the Problem. Thank you very much for your help:). – raj7vasani Nov 12 '22 at 16:45

0 Answers0