#792 Include registration date into purging logic
- Take MAX(reg_date, login_date) as timestamp to compare against - Remove the second "all" parameter to include entries with 0 registration date -> we expect registration date to always be set to the current date, so the parameter becomes obsolete
This commit is contained in:
@@ -9,7 +9,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -74,7 +73,7 @@ public class PurgeCommandTest {
|
||||
|
||||
// then
|
||||
ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class);
|
||||
verify(purgeService).runPurge(eq(sender), captor.capture(), eq(false));
|
||||
verify(purgeService).runPurge(eq(sender), captor.capture());
|
||||
|
||||
// Check the timestamp with a certain tolerance
|
||||
int toleranceMillis = 100;
|
||||
@@ -83,41 +82,6 @@ public class PurgeCommandTest {
|
||||
assertIsCloseTo(captor.getValue(), calendar.getTimeInMillis(), toleranceMillis);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldProcessCommandWithAllParameter() {
|
||||
// given
|
||||
String interval = "32";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(interval, "all"));
|
||||
|
||||
// then
|
||||
ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class);
|
||||
verify(purgeService).runPurge(eq(sender), captor.capture(), eq(true));
|
||||
|
||||
// Check the timestamp with a certain tolerance
|
||||
int toleranceMillis = 100;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -Integer.valueOf(interval));
|
||||
assertIsCloseTo(captor.getValue(), calendar.getTimeInMillis(), toleranceMillis);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectCommandWithInvalidSecondParameter() {
|
||||
// given
|
||||
String interval = "80";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(interval, "bogus"));
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(
|
||||
argThat(containsString("Purge process aborted; use '/authme purge " + interval + " all'")));
|
||||
verifyZeroInteractions(purgeService);
|
||||
}
|
||||
|
||||
private static void assertIsCloseTo(long value1, long value2, long tolerance) {
|
||||
assertThat(Math.abs(value1 - value2), not(greaterThan(tolerance)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user