Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.10</version>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/com/sendgrid/SendGrid.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.sendgrid;

import com.sendgrid.Client;
import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -39,6 +34,15 @@ public SendGrid(String apiKey, Boolean test) {
initializeSendGrid(apiKey);
}

/**
* @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys
* @param client the Client to use (allows to customize its configuration)
*/
public SendGrid(String apiKey, Client client) {
this.client = client;
initializeSendGrid(apiKey);
}

public void initializeSendGrid(String apiKey) {
this.apiKey = apiKey;
this.host = "api.sendgrid.com";
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/com/sendgrid/SendGridTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.sendgrid;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static org.mockito.Mockito.*;

public class SendGridTest {

Expand All @@ -34,6 +31,15 @@ public void testInitialization() {
Assert.assertEquals(sg.getRequestHeaders(), requestHeaders);
}

@Test
public void testConstructWithClient() throws IOException {
Client client = mock(Client.class);
SendGrid sg = new SendGrid(SENDGRID_API_KEY, client);
Request request = new Request();
sg.makeCall(request);
verify(client).api(request);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of using a mock I could also add a getter for the client and make sure its the one we passed into the constructor. Opinions? 😊

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine as it is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sending Email with attachments. I want to set ConnectionTimeout values like shown above, But Not able to figure out where to set. I created Client object. I used abovbe 4 lines. But I do no see any API on Client or SendGrid to set timeout values. Can someone please help me with this.

}

@Test
public void testLibraryVersion() {
SendGrid sg = new SendGrid(SENDGRID_API_KEY);
Expand Down