How to compare two ListFloat in Junit?

0

I need to compare two List, and in my test I used

assertEquals(lista1, lista2);
Assert.assertTrue(lista1.containsAll(lista2));

And the error that the test shows is

  

(index: 22 size: 22) java.lang.IndexOutOfBoundsException

Until today I had never tested a return from List so I do not know if I'm doing it right.

    
asked by anonymous 05.03.2017 / 23:05

1 answer

0

Use the methods assertThat of class MatcherAssert and method is of class CoreMatchers . Example:

@Test
public void verificaSeAListaASerTestadaEIgualAEsperada() {
    List<Float> listaASerTestada = Arrays.asList(1.0f, 2.0f, 3.0f);
    List<Float> listaEsperada = Arrays.asList(1.0f, 2.0f, 3.0f);
    MatcherAssert.assertThat(listaASerTestada, CoreMatchers.is(listaEsperada));
}
    
05.03.2017 / 23:21