I have a method:
public int checkQuality() { Calendar currentDate = Calendar.getInstance(); long differenceOne = this.expireDate.getTimeInMillis() - this.createDate.getTimeInMillis(); long differenceTwo = currentDate.getTimeInMillis() - this.createDate.getTimeInMillis(); return (int) (((float) differenceTwo / differenceOne) * 100); } It checks in percents on how much the expiration date of the goods is in percents, and returns int these percentages.
I need to test it and the first test looks like this:
@Test public void whenThen() { Calendar createDate = new GregorianCalendar(2016, 11, 16); Calendar expireDate = new GregorianCalendar(2017, 11, 31); Product food = new Food(createDate, expireDate); ControlQuality control = new ControlQuality(); control.uploadInRepo(food); assertThat(food, is(control.getRepo().get(0).getProducts().get(0))); } It is obvious that in a couple of days he will not work. Of course, when creating Calendar objects, you can push off from the current date, but it seems to me to be some kind of crutch ... How can I make it always work without sticks, scrap, and other hand-made utensils?