Skip to content

Commit 1b6b8f0

Browse files
committed
2 spacing tabs please vs the sometimes chosen 4
1 parent 135a68b commit 1b6b8f0

File tree

2 files changed

+152
-151
lines changed

2 files changed

+152
-151
lines changed

src/main/java/com/github/scottmotte/sendgrid/Sendgrid.java

Lines changed: 90 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,105 +5,106 @@
55
import java.io.File;
66

77
public class Sendgrid {
8-
private static final String PARAM_API_KEY = "api_key";
9-
private static final String PARAM_API_USER = "api_user";
10-
private static final String PARAM_BCC = "bcc";
11-
private static final String PARAM_FILES = "files[%s]";
12-
private static final String PARAM_FROM = "from";
13-
private static final String PARAM_HTML = "html";
14-
private static final String PARAM_SUBJECT = "subject";
15-
private static final String PARAM_TEXT = "text";
16-
private static final String PARAM_TO = "to";
8+
private static final String PARAM_API_KEY = "api_key";
9+
private static final String PARAM_API_USER = "api_user";
10+
private static final String PARAM_BCC = "bcc";
11+
private static final String PARAM_FILES = "files[%s]";
12+
private static final String PARAM_FROM = "from";
13+
private static final String PARAM_HTML = "html";
14+
private static final String PARAM_SUBJECT = "subject";
15+
private static final String PARAM_TEXT = "text";
16+
private static final String PARAM_TO = "to";
1717

18-
private String[] bcc;
19-
private File[] file;
20-
private String from;
21-
private String html;
22-
private String password;
23-
private String subject;
24-
private String text;
25-
private String[] to;
26-
private String username;
18+
private String[] bcc;
19+
private File[] file;
20+
private String from;
21+
private String html;
22+
private String password;
23+
private String subject;
24+
private String text;
25+
private String[] to;
26+
private String username;
2727

28-
public static Sendgrid withCredentials(String username, String password) {
29-
return new Sendgrid(username, password);
30-
}
28+
public static Sendgrid withCredentials(String username, String password) {
29+
return new Sendgrid(username, password);
30+
}
3131

32-
public Sendgrid(final String username, final String password) {
33-
this.username = username;
34-
this.password = password;
35-
}
32+
public Sendgrid(final String username, final String password) {
33+
this.username = username;
34+
this.password = password;
35+
}
3636

37-
public Sendgrid bcc(final String... bcc) {
38-
this.bcc = bcc;
39-
return this;
40-
}
37+
public Sendgrid bcc(final String... bcc) {
38+
this.bcc = bcc;
39+
return this;
40+
}
4141

42-
public Sendgrid from(final String email) {
43-
this.from = email;
44-
return this;
45-
}
42+
public Sendgrid from(final String email) {
43+
this.from = email;
44+
return this;
45+
}
4646

47-
public String send() {
48-
HttpRequest request = HttpRequest.post("https://sendgrid.com/api/mail.send.json");
49-
if (username != null) {
50-
request.part(PARAM_API_USER, username);
51-
}
52-
if (password != null) {
53-
request.part(PARAM_API_KEY, password);
54-
}
55-
if (from != null) {
56-
request.part(PARAM_FROM, from);
57-
}
58-
if (to != null) {
59-
for (String s : to) {
60-
request.part(PARAM_TO, s);
61-
}
62-
}
63-
if (bcc != null) {
64-
for (String s : bcc) {
65-
request.part(PARAM_BCC, s);
66-
}
67-
}
68-
if (subject != null) {
69-
request.part(PARAM_SUBJECT, subject);
70-
}
71-
if (text != null) {
72-
request.part(PARAM_TEXT, text);
73-
}
74-
if (html != null) {
75-
request.part(PARAM_HTML, html);
76-
}
77-
if (file != null) {
78-
for (File f : file) {
79-
request.part(String.format(PARAM_FILES, f.getName()), f);
80-
}
81-
}
82-
return request.body();
47+
public String send() {
48+
HttpRequest request = HttpRequest.post("https://sendgrid.com/api/mail.send.json");
49+
if (username != null) {
50+
request.part(PARAM_API_USER, username);
8351
}
84-
85-
public Sendgrid to(final String... to) {
86-
this.to = to;
87-
return this;
52+
if (password != null) {
53+
request.part(PARAM_API_KEY, password);
8854
}
89-
90-
public Sendgrid withAttachment(final File... file) {
91-
this.file = file;
92-
return this;
55+
if (from != null) {
56+
request.part(PARAM_FROM, from);
9357
}
94-
95-
public Sendgrid withHtml(final String html) {
96-
this.html = html;
97-
return this;
58+
if (to != null) {
59+
for (String s : to) {
60+
request.part(PARAM_TO, s);
61+
}
9862
}
99-
100-
public Sendgrid withSubject(final String subject) {
101-
this.subject = subject;
102-
return this;
63+
if (bcc != null) {
64+
for (String s : bcc) {
65+
request.part(PARAM_BCC, s);
66+
}
10367
}
104-
105-
public Sendgrid withText(final String text) {
106-
this.text = text;
107-
return this;
68+
if (subject != null) {
69+
request.part(PARAM_SUBJECT, subject);
10870
}
71+
if (text != null) {
72+
request.part(PARAM_TEXT, text);
73+
}
74+
if (html != null) {
75+
request.part(PARAM_HTML, html);
76+
}
77+
if (file != null) {
78+
for (File f : file) {
79+
request.part(String.format(PARAM_FILES, f.getName()), f);
80+
}
81+
}
82+
83+
return request.body();
84+
}
85+
86+
public Sendgrid to(final String... to) {
87+
this.to = to;
88+
return this;
89+
}
90+
91+
public Sendgrid withAttachment(final File... file) {
92+
this.file = file;
93+
return this;
94+
}
95+
96+
public Sendgrid withHtml(final String html) {
97+
this.html = html;
98+
return this;
99+
}
100+
101+
public Sendgrid withSubject(final String subject) {
102+
this.subject = subject;
103+
return this;
104+
}
105+
106+
public Sendgrid withText(final String text) {
107+
this.text = text;
108+
return this;
109+
}
109110
}

src/test/java/com/github/scottmotte/sendgrid/SendgridTest.java

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,71 @@
77
import static org.junit.Assert.assertEquals;
88

99
public class SendgridTest {
10-
private static final String FROM_EMAIL = "[email protected]";
11-
private static final String PASSWORD = "password";
12-
private static final String TO_ANOTHER_EMAIL = "bcc@email.to";
13-
private static final String TO_EMAIL = "[email protected]";
14-
private static final String USERNAME = "username";
10+
private static final String FROM_EMAIL = "[email protected]";
11+
private static final String TO_ANOTHER_EMAIL = "[email protected]";
12+
private static final String TO_EMAIL = "to@email.to";
13+
private static final String USERNAME = "username";
14+
private static final String PASSWORD = "password";
1515

16-
@Test
17-
public void testSendSuccess() {
18-
String result = Sendgrid
19-
.withCredentials(USERNAME, PASSWORD)
20-
.from(FROM_EMAIL)
21-
.to(TO_EMAIL)
22-
.withSubject("This is a test subject")
23-
.withText("This is a test text.")
24-
.send();
25-
assertEquals("{\"message\":\"success\"}", result);
26-
}
16+
@Test
17+
public void testSendSuccess() {
18+
String result = Sendgrid
19+
.withCredentials(USERNAME, PASSWORD)
20+
.from(FROM_EMAIL)
21+
.to(TO_EMAIL)
22+
.withSubject("This is a test subject")
23+
.withText("This is a test text.")
24+
.send();
25+
assertEquals("{\"message\":\"success\"}", result);
26+
}
2727

28-
@Test
29-
public void testSendSuccessBcc() {
30-
String result = Sendgrid
31-
.withCredentials(USERNAME, PASSWORD)
32-
.from(FROM_EMAIL)
33-
.to(TO_EMAIL)
34-
.bcc(TO_ANOTHER_EMAIL)
35-
.withSubject("This is a test subject")
36-
.withText("This is a test text.")
37-
.send();
38-
assertEquals("{\"message\":\"success\"}", result);
39-
}
28+
@Test
29+
public void testSendSuccessBcc() {
30+
String result = Sendgrid
31+
.withCredentials(USERNAME, PASSWORD)
32+
.from(FROM_EMAIL)
33+
.to(TO_EMAIL)
34+
.bcc(TO_ANOTHER_EMAIL)
35+
.withSubject("This is a test subject")
36+
.withText("This is a test text.")
37+
.send();
38+
assertEquals("{\"message\":\"success\"}", result);
39+
}
4040

41-
@Test
42-
public void testSendSuccessWithAttachment() {
43-
File attachment = new File(getClass().getResource("/test.txt").getFile());
44-
String result = Sendgrid
45-
.withCredentials(USERNAME, PASSWORD)
46-
.from(FROM_EMAIL)
47-
.to(TO_EMAIL)
48-
.withSubject("This is a test subject")
49-
.withText("This is a test text.")
50-
.withAttachment(attachment)
51-
.send();
52-
assertEquals("{\"message\":\"success\"}", result);
53-
}
41+
@Test
42+
public void testSendSuccessWithAttachment() {
43+
File attachment = new File(getClass().getResource("/test.txt").getFile());
44+
String result = Sendgrid
45+
.withCredentials(USERNAME, PASSWORD)
46+
.from(FROM_EMAIL)
47+
.to(TO_EMAIL)
48+
.withSubject("This is a test subject")
49+
.withText("This is a test text.")
50+
.withAttachment(attachment)
51+
.send();
52+
assertEquals("{\"message\":\"success\"}", result);
53+
}
5454

55-
@Test
56-
public void testSendSuccessWithMultipleRecipients() {
57-
String result = Sendgrid
58-
.withCredentials(USERNAME, PASSWORD)
59-
.from(FROM_EMAIL)
60-
.to(TO_EMAIL, TO_ANOTHER_EMAIL)
61-
.withSubject("This is a test subject")
62-
.withText("This is a test text.")
63-
.send();
64-
assertEquals("{\"message\":\"success\"}", result);
65-
}
55+
@Test
56+
public void testSendSuccessWithMultipleRecipients() {
57+
String result = Sendgrid
58+
.withCredentials(USERNAME, PASSWORD)
59+
.from(FROM_EMAIL)
60+
.to(TO_EMAIL, TO_ANOTHER_EMAIL)
61+
.withSubject("This is a test subject")
62+
.withText("This is a test text.")
63+
.send();
64+
assertEquals("{\"message\":\"success\"}", result);
65+
}
6666

67-
@Test
68-
public void testSendWithoutFrom() {
69-
String result = Sendgrid
70-
.withCredentials(USERNAME, PASSWORD)
71-
.to(TO_EMAIL)
72-
.withSubject("This is a test subject")
73-
.withText("This is a test text.")
74-
.send();
75-
assertEquals("{\"message\": \"error\", \"errors\": [\"Empty from email address (required)\"]}", result);
76-
}
67+
@Test
68+
public void testSendWithoutFrom() {
69+
String result = Sendgrid
70+
.withCredentials(USERNAME, PASSWORD)
71+
.to(TO_EMAIL)
72+
.withSubject("This is a test subject")
73+
.withText("This is a test text.")
74+
.send();
75+
assertEquals("{\"message\": \"error\", \"errors\": [\"Empty from email address (required)\"]}", result);
76+
}
7777
}

0 commit comments

Comments
 (0)