Why is assertEquals (Object [], Object []) from JUnit 4 deprecated?

Eclipse gives me a warning saying the method is deprecated assertEquals(Object[], Object[])by type Assert. I am using JUnit 4.

I wrote the following code in Eclipse:

import org.junit.Test;
import org.junit.Assert;

public class Generics { 
    public <T> T[] genericArraySwap(T[] list, int pos1, int pos2) throws IndexOutOfBoundsException {
        ...
    }

    @Test
    public void genericArraySwapTest() {
        Integer[] IntegerList = {0, 1, 2, 3, 4};        
        Assert.assertEquals(new Integer[] {0, 1, 2, 4, 3}, genericArraySwap(IntegerList, 3, 4));
    }
}

Can someone tell me why this method is deprecated or which method should I use instead?

+4
source share
1 answer

It is deprecated due to the lack of expressiveness of a system like Java.

assertEquals == ( ) equals ( ), : Object (.. ) equals, assertEquals .

assertArrayEquals, , , , .

, :

assertEquals(T, T)

T - " Object, ". Java; , , Object s.

, , :

  • , Object s
  • , , @Deprecated. , 9 ( 8 : 1 Object[], ).

assertEquals(T[], T[]), , ; squiggles Eclipse; .

, , Object; , , .

+5

Source: https://habr.com/ru/post/1668557/


All Articles