How to correctly change unit test properties?

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 the date property of all Foos to the day before barDate.

I am trying to use Hamcrest to help me claim that the list is updated, but I cannot get it to work.

Should I just use foos.get (n) .getDate () and claim on them?

What is the preferred way to claim that the date property of elements in foos has been updated correctly?

Edit: Typo

+3
source share
1 answer

Don't you complicate yourself here? Why not just iterate over the collection and approve for each item?

for ( Foo foo : foos ) { assertThat( foo.getDate() , equalTo( barDate ) ); }

Greetings

+6
source

All Articles