5

I have a class List (EDIT: that I wrote myself), with method List.equals, so I want to run something like

List list1 = new List();
List list2 = new List();
assertTrue(list1.equals(list2));

So using matchers and assertThat, I thought maybe

assertThat(list1.equals(list2), is(true));

But this is getting pretty silly...EDIT: perhaps I can write my own matcher

Is there a better way to check if my equals method is working correctly?

This is with JUnit4.5

Henry
  • 6,502
  • 2
  • 24
  • 30

2 Answers2

11
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;    

...

assertThat(list1, equalTo(list2));
samlewis
  • 3,950
  • 27
  • 27
1

assertEquals(list1, list2) is the most straightforward way.

Tim Boudreau
  • 1,741
  • 11
  • 13