[28] | 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.RunningPartiesUpdater;
|
---|
| 16 | import geniusweb.partiesserver.repository.RunningPartiesRepo;
|
---|
| 17 | import geniusweb.partiesserver.repository.RunningParty;
|
---|
| 18 |
|
---|
| 19 | public class RunningPartiesUpdaterTest {
|
---|
| 20 | @Test
|
---|
| 21 | public void smokeTest() throws InterruptedException {
|
---|
| 22 | RunningPartiesRepo repo = mock(RunningPartiesRepo.class);
|
---|
| 23 | RunningPartiesUpdater updater = new RunningPartiesUpdater(repo, 100);
|
---|
| 24 | Thread.sleep(500);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | @Test
|
---|
| 28 | public void timeoutTest() throws InterruptedException {
|
---|
| 29 | RunningPartiesRepo repo = mock(RunningPartiesRepo.class);
|
---|
| 30 | RunningParty runningparty = mock(RunningParty.class);
|
---|
| 31 | PartyId id = new PartyId("partyid");
|
---|
| 32 | when(runningparty.getID()).thenReturn(id);
|
---|
| 33 | Date soon = new Date(System.currentTimeMillis() + 100);
|
---|
| 34 | when(runningparty.getEndDate()).thenReturn(soon);
|
---|
| 35 | Collection<RunningParty> list = new LinkedList<>();
|
---|
| 36 | list.add(runningparty);
|
---|
| 37 | when(repo.list()).thenReturn(list);
|
---|
| 38 | RunningPartiesUpdater updater = new RunningPartiesUpdater(repo, 100);
|
---|
| 39 | updater.update();
|
---|
| 40 | verify(repo, times(0)).remove(id);
|
---|
| 41 | Thread.sleep(400 + 2000); // there is 2000 extra kill wait time
|
---|
| 42 | updater.update();
|
---|
| 43 | verify(repo, times(1)).remove(id);
|
---|
| 44 |
|
---|
| 45 | }
|
---|
| 46 | }
|
---|