|
5 | 5 | import com.messagebird.exceptions.UnauthorizedException;
|
6 | 6 | import com.messagebird.objects.*;
|
7 | 7 | import org.junit.*;
|
8 |
| - |
| 8 | +import org.mockito.Mockito; |
9 | 9 | import static org.junit.Assert.*;
|
| 10 | +import static org.mockito.Mockito.*; |
| 11 | +import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals; |
10 | 12 |
|
11 | 13 | public class ContactTest {
|
12 | 14 |
|
13 | 15 | private static MessageBirdServiceImpl messageBirdService;
|
14 | 16 | private static MessageBirdClient messageBirdClient;
|
| 17 | + private static final String CONTACTPATH = "/contacts"; |
15 | 18 |
|
16 | 19 | private static String msisdn;
|
17 | 20 |
|
@@ -62,12 +65,20 @@ public static void tearDown() throws UnauthorizedException, GeneralException, No
|
62 | 65 |
|
63 | 66 | @Test
|
64 | 67 | public void testList() throws UnauthorizedException, GeneralException {
|
65 |
| - ContactList actual = messageBirdClient.listContacts(); |
| 68 | + final ContactList contactResponseList = TestUtil.createContactList(); |
| 69 | + |
| 70 | + MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class); |
| 71 | + MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock); |
| 72 | + |
| 73 | + when(messageBirdServiceMock.requestList(Mockito.eq(CONTACTPATH), Mockito.eq(0), Mockito.eq(20), |
| 74 | + Mockito.eq(ContactList.class))) |
| 75 | + .thenReturn(contactResponseList); |
66 | 76 |
|
67 |
| - assertSame(20, actual.getLimit()); |
68 |
| - assertSame(0, actual.getOffset()); |
69 |
| - assertNotSame(0, actual.getTotalCount()); |
70 |
| - assertNotNull(actual.getItems().get(0).getId()); |
| 77 | + final ContactList response = messageBirdClientInjectMock.listContacts(); |
| 78 | + verify(messageBirdServiceMock, times(1)) |
| 79 | + .requestList(Mockito.eq(CONTACTPATH), Mockito.eq(0), Mockito.eq(20), |
| 80 | + Mockito.eq(ContactList.class)); |
| 81 | + assertReflectionEquals(response.getItems().get(0),contactResponseList.getItems().get(0)); |
71 | 82 | }
|
72 | 83 |
|
73 | 84 | @Test
|
|
0 commit comments