|
5 | 5 | import org.junit.jupiter.api.Test; |
6 | 6 |
|
7 | 7 | import java.io.IOException; |
| 8 | +import java.util.Collections; |
| 9 | +import java.util.Map; |
8 | 10 |
|
9 | 11 | 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.junit.jupiter.api.Assertions.*; |
12 | 13 | import static org.mockito.ArgumentMatchers.any; |
13 | 14 | import static org.mockito.Mockito.*; |
14 | 15 |
|
@@ -61,11 +62,42 @@ public void testFetchAccountByAccessToken() throws RequestFailedException, IOExc |
61 | 62 | @Test |
62 | 63 | public void testRevokeAccessToken() throws RequestFailedException, IOException { |
63 | 64 | final NylasAccount nylasAccount = new NylasAccount(nylasClient, TEST_ACCESS_TOKEN); |
| 65 | + final Map<String, Boolean> revokeResponse = Collections.singletonMap("success", true); |
64 | 66 |
|
65 | 67 | when(nylasClient.newUrlBuilder()).thenReturn(new HttpUrl.Builder()); |
| 68 | + when(nylasClient.executePost(anyString(), any(), any(), any())).thenReturn(revokeResponse); |
66 | 69 |
|
67 | | - nylasAccount.revokeAccessToken(); |
| 70 | + boolean revokeAccessToken = nylasAccount.revokeAccessToken(); |
68 | 71 |
|
69 | 72 | verify(nylasClient).executePost(anyString(), any(), any(), any()); |
| 73 | + assertTrue(revokeAccessToken); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void testRevokeAccessTokenSuccessFalse() throws RequestFailedException, IOException { |
| 78 | + final NylasAccount nylasAccount = new NylasAccount(nylasClient, TEST_ACCESS_TOKEN); |
| 79 | + final Map<String, Boolean> revokeResponse = Collections.singletonMap("success", false); |
| 80 | + |
| 81 | + when(nylasClient.newUrlBuilder()).thenReturn(new HttpUrl.Builder()); |
| 82 | + when(nylasClient.executePost(anyString(), any(), any(), any())).thenReturn(revokeResponse); |
| 83 | + |
| 84 | + boolean revokeAccessToken = nylasAccount.revokeAccessToken(); |
| 85 | + |
| 86 | + verify(nylasClient).executePost(anyString(), any(), any(), any()); |
| 87 | + assertFalse(revokeAccessToken); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testRevokeAccessTokenInvalidObjectReturnsFalse() throws RequestFailedException, IOException { |
| 92 | + final NylasAccount nylasAccount = new NylasAccount(nylasClient, TEST_ACCESS_TOKEN); |
| 93 | + final Map<String, Object> revokeResponse = Collections.singletonMap("invalidKey", "invalidValue"); |
| 94 | + |
| 95 | + when(nylasClient.newUrlBuilder()).thenReturn(new HttpUrl.Builder()); |
| 96 | + when(nylasClient.executePost(anyString(), any(), any(), any())).thenReturn(revokeResponse); |
| 97 | + |
| 98 | + boolean revokeAccessToken = nylasAccount.revokeAccessToken(); |
| 99 | + |
| 100 | + verify(nylasClient).executePost(anyString(), any(), any(), any()); |
| 101 | + assertFalse(revokeAccessToken); |
70 | 102 | } |
71 | 103 | } |
0 commit comments