I have this test:
@Test
public void UpdateAllFooDatesToOneDayBeforeProvidedDate_TodaysDateAndFooDate_UpdatedDates() {
// arrange
List<Foo> foos = new ArrayList<Foo>();
Date barDate = today;
Foo foo1 = setupFoo();
Foo foo2 = setupFoo();
foos.add(foo1);
foos.add(foo2);
foo1.setValidTo(dateUtil.adjustDaysOfDate(today, 5));
foo2.setValidTo(dateUtil.adjustDaysOfDate(today, 8));
// act
modifyDates.updateAllFooDatesToOneDayBeforeProvidedDate(barDate, foos);
// assert
assertThat(foos, hasItems(...?)); //I don't know how to assert this
}
updateAllFooDatesToOneDayBeforeProvidedDate(Date, List) simply changes a date property of all Foos to the day before barDate.
I am trying to use Hamcrest to help me assert that the list has been updated, but I can't really get it to work.
Should I simply use foos.get(n).getDate() and assert on those?
What is the preferred way of asserting that the date property of the elements in foos has been updated properly?
Edit: Typo
Aren't you making it hard on yourself here? Why not just iterate over the collection and assert for each element?
for ( Foo foo : foos ) { assertThat( foo.getDate() , equalTo( barDate ) ); }
Cheers,