[40] | 1 | package geniusweb.partiesserver;
|
---|
| 2 |
|
---|
| 3 | import static org.mockito.Mockito.mock;
|
---|
| 4 | import static org.mockito.Mockito.times;
|
---|
| 5 | import static org.mockito.Mockito.verify;
|
---|
| 6 | import static org.mockito.Mockito.when;
|
---|
| 7 |
|
---|
| 8 | import java.util.Collection;
|
---|
| 9 | import java.util.Date;
|
---|
| 10 | import java.util.LinkedList;
|
---|
| 11 |
|
---|
| 12 | import org.junit.Test;
|
---|
| 13 |
|
---|
| 14 | import geniusweb.actions.PartyId;
|
---|
| 15 | import geniusweb.partiesserver.repository.RunningPartiesRepo;
|
---|
| 16 | import geniusweb.partiesserver.repository.RunningParty;
|
---|
| 17 |
|
---|
| 18 | public class RunningPartiesUpdaterTest {
|
---|
| 19 | @Test
|
---|
| 20 | public void smokeTest() throws InterruptedException {
|
---|
| 21 | RunningPartiesRepo repo = mock(RunningPartiesRepo.class);
|
---|
| 22 | RunningPartiesUpdater updater = new RunningPartiesUpdater(repo, 100);
|
---|
| 23 | Thread.sleep(500);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | @Test
|
---|
| 27 | public void timeoutTest() throws InterruptedException {
|
---|
| 28 | RunningPartiesRepo repo = mock(RunningPartiesRepo.class);
|
---|
| 29 | RunningParty runningparty = mock(RunningParty.class);
|
---|
| 30 | PartyId id = new PartyId("partyid");
|
---|
| 31 | when(runningparty.getID()).thenReturn(id);
|
---|
| 32 | Date soon = new Date(System.currentTimeMillis() + 100);
|
---|
| 33 | when(runningparty.getEndDate()).thenReturn(soon);
|
---|
| 34 | Collection<RunningParty> list = new LinkedList<>();
|
---|
| 35 | list.add(runningparty);
|
---|
| 36 | when(repo.list()).thenReturn(list);
|
---|
| 37 | RunningPartiesUpdater updater = new RunningPartiesUpdater(repo, 100);
|
---|
| 38 | updater.update();
|
---|
| 39 | verify(repo, times(0)).remove(id);
|
---|
| 40 | // we also need to account for the kill delay
|
---|
| 41 | Thread.sleep(400 + RunningPartiesUpdater.KILL_DELAY);
|
---|
| 42 | updater.update();
|
---|
| 43 | verify(repo, times(1)).remove(id);
|
---|
| 44 |
|
---|
| 45 | }
|
---|
| 46 | }
|
---|