File tree Expand file tree Collapse file tree 3 files changed +26
-10
lines changed
Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 109109 <dependency >
110110 <groupId >junit</groupId >
111111 <artifactId >junit-dep</artifactId >
112- <version >4.10</version >
112+ <version >4.11</version >
113+ <scope >test</scope >
114+ </dependency >
115+ <dependency >
116+ <groupId >org.mockito</groupId >
117+ <artifactId >mockito-core</artifactId >
118+ <version >2.1.0</version >
113119 <scope >test</scope >
114120 </dependency >
115121 </dependencies >
Original file line number Diff line number Diff line change 11package com .sendgrid ;
22
3- import com .sendgrid .Client ;
4- import com .sendgrid .Method ;
5- import com .sendgrid .Request ;
6- import com .sendgrid .Response ;
7-
83import java .io .IOException ;
94import java .util .HashMap ;
105import java .util .Map ;
@@ -39,6 +34,15 @@ public SendGrid(String apiKey, Boolean test) {
3934 initializeSendGrid (apiKey );
4035 }
4136
37+ /**
38+ * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys
39+ * @param client the Client to use (allows to customize its configuration)
40+ */
41+ public SendGrid (String apiKey , Client client ) {
42+ this .client = client ;
43+ initializeSendGrid (apiKey );
44+ }
45+
4246 public void initializeSendGrid (String apiKey ) {
4347 this .apiKey = apiKey ;
4448 this .host = "api.sendgrid.com" ;
Original file line number Diff line number Diff line change 11package com .sendgrid ;
22
33import org .junit .Assert ;
4- import org .junit .Before ;
54import org .junit .Test ;
65
7- import java .io .BufferedReader ;
8- import java .io .FileNotFoundException ;
9- import java .io .FileReader ;
106import java .io .IOException ;
117import java .util .HashMap ;
128import java .util .Map ;
9+ import static org .mockito .Mockito .*;
1310
1411public class SendGridTest {
1512
@@ -34,6 +31,15 @@ public void testInitialization() {
3431 Assert .assertEquals (sg .getRequestHeaders (), requestHeaders );
3532 }
3633
34+ @ Test
35+ public void testConstructWithClient () throws IOException {
36+ Client client = mock (Client .class );
37+ SendGrid sg = new SendGrid (SENDGRID_API_KEY , client );
38+ Request request = new Request ();
39+ sg .makeCall (request );
40+ verify (client ).api (request );
41+ }
42+
3743 @ Test
3844 public void testLibraryVersion () {
3945 SendGrid sg = new SendGrid (SENDGRID_API_KEY );
You can’t perform that action at this time.
0 commit comments