|
| 1 | +package com.nylas; |
| 2 | + |
| 3 | +import okhttp3.HttpUrl; |
| 4 | +import org.junit.jupiter.api.BeforeEach; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | + |
| 9 | +import static com.nylas.AccessTokenTest.TEST_ACCESS_TOKEN; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 11 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 12 | +import static org.mockito.ArgumentMatchers.any; |
| 13 | +import static org.mockito.Mockito.*; |
| 14 | + |
| 15 | +public class NylasAccountTest { |
| 16 | + private NylasClient nylasClient; |
| 17 | + |
| 18 | + @BeforeEach |
| 19 | + private void init() { |
| 20 | + nylasClient = mock(NylasClient.class); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + public void testNylasAccountBootstraping() { |
| 25 | + final NylasAccount nylasAccount = new NylasAccount(nylasClient, TEST_ACCESS_TOKEN); |
| 26 | + |
| 27 | + assertEquals(nylasAccount.getAccessToken(), TEST_ACCESS_TOKEN); |
| 28 | + assertEquals(nylasAccount.getClient(), nylasClient); |
| 29 | + assertNotNull(nylasAccount.threads()); |
| 30 | + assertNotNull(nylasAccount.messages()); |
| 31 | + assertNotNull(nylasAccount.folders()); |
| 32 | + assertNotNull(nylasAccount.labels()); |
| 33 | + assertNotNull(nylasAccount.drafts()); |
| 34 | + assertNotNull(nylasAccount.outbox()); |
| 35 | + assertNotNull(nylasAccount.calendars()); |
| 36 | + assertNotNull(nylasAccount.files()); |
| 37 | + assertNotNull(nylasAccount.contacts()); |
| 38 | + assertNotNull(nylasAccount.contactGroups()); |
| 39 | + assertNotNull(nylasAccount.deltas()); |
| 40 | + assertNotNull(nylasAccount.events()); |
| 41 | + assertNotNull(nylasAccount.jobStatuses()); |
| 42 | + assertNotNull(nylasAccount.roomResources()); |
| 43 | + assertNotNull(nylasAccount.neural()); |
| 44 | + assertNotNull(nylasAccount.schedulers()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testFetchAccountByAccessToken() throws RequestFailedException, IOException { |
| 49 | + final NylasAccount nylasAccount = new NylasAccount(nylasClient, TEST_ACCESS_TOKEN); |
| 50 | + final AccountDetail expectedAccountDetail = new AccountDetail(); |
| 51 | + |
| 52 | + when(nylasClient.newUrlBuilder()).thenReturn(new HttpUrl.Builder()); |
| 53 | + when(nylasClient.executeGet(anyString(), any(), any())).thenReturn(expectedAccountDetail); |
| 54 | + |
| 55 | + AccountDetail actualAccountDetail = nylasAccount.fetchAccountByAccessToken(); |
| 56 | + |
| 57 | + verify(nylasClient).executeGet(anyString(), any(), any()); |
| 58 | + assertNotNull(actualAccountDetail); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testRevokeAccessToken() throws RequestFailedException, IOException { |
| 63 | + final NylasAccount nylasAccount = new NylasAccount(nylasClient, TEST_ACCESS_TOKEN); |
| 64 | + |
| 65 | + when(nylasClient.newUrlBuilder()).thenReturn(new HttpUrl.Builder()); |
| 66 | + |
| 67 | + nylasAccount.revokeAccessToken(); |
| 68 | + |
| 69 | + verify(nylasClient).executePost(anyString(), any(), any(), any()); |
| 70 | + } |
| 71 | +} |
0 commit comments