package geniusweb.partiesserver; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Collection; import java.util.Date; import java.util.LinkedList; import org.junit.Test; import geniusweb.actions.PartyId; import geniusweb.partiesserver.repository.RunningPartiesRepo; import geniusweb.partiesserver.repository.RunningParty; public class RunningPartiesUpdaterTest { @Test public void smokeTest() throws InterruptedException { RunningPartiesRepo repo = mock(RunningPartiesRepo.class); RunningPartiesUpdater updater = new RunningPartiesUpdater(repo, 100); Thread.sleep(500); } @Test public void timeoutTest() throws InterruptedException { RunningPartiesRepo repo = mock(RunningPartiesRepo.class); RunningParty runningparty = mock(RunningParty.class); PartyId id = new PartyId("partyid"); when(runningparty.getID()).thenReturn(id); Date soon = new Date(System.currentTimeMillis() + 100); when(runningparty.getEndDate()).thenReturn(soon); Collection list = new LinkedList<>(); list.add(runningparty); when(repo.list()).thenReturn(list); RunningPartiesUpdater updater = new RunningPartiesUpdater(repo, 100); updater.update(); verify(repo, times(0)).remove(id); // we also need to account for the kill delay Thread.sleep(400 + RunningPartiesUpdater.KILL_DELAY); updater.update(); verify(repo, times(1)).remove(id); } }