Skip to content

Commit

Permalink
Removed wrongly used mock in tested DateUtils class
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Nov 3, 2023
1 parent 05b5a55 commit e2963c4
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import java.util.Locale;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;


public class DateUtilsTest {
Expand All @@ -55,15 +53,23 @@ public void prettyTime() {
Assert.assertEquals(0, prettyTime.toLowerCase().length());
}

@Test
public void getNextMinute() {
var nextMinute = DateUtils.getNextMinute();

assertTrue(Calendar.getInstance().getTimeInMillis() < nextMinute);
assertTrue(nextMinute < Calendar.getInstance().getTimeInMillis() + 61 * 1000);
}

@Test
public void getPresetReminder() {
long mockedNextMinute = 1497315847L;
Long testReminder = null;
try (MockedStatic<DateUtils> dateUtils = Mockito.mockStatic(DateUtils.class)) {
dateUtils.when(DateUtils::getNextMinute).thenReturn(mockedNextMinute);
var nextHour = Calendar.getInstance().getTimeInMillis() + 60 * 60 * 1000;
assertEquals(nextHour, DateUtils.getPresetReminder(nextHour));

assertEquals(mockedNextMinute, DateUtils.getPresetReminder(testReminder));
}
var previousMinute = Calendar.getInstance().getTimeInMillis() - 60 * 1000;
var nextMinute = Calendar.getInstance().getTimeInMillis() + 61 * 1000;
var presetReminder = DateUtils.getPresetReminder(previousMinute);
assertTrue(Calendar.getInstance().getTimeInMillis() < presetReminder && presetReminder < nextMinute);
}

@Test
Expand Down

0 comments on commit e2963c4

Please sign in to comment.