Skip to content

Commit 090ebb4

Browse files
committed
Minor fixes (#902)
1 parent 2704b09 commit 090ebb4

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

src/main/java/com/stripe/net/HttpContent.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.stripe.net;
22

3+
import static java.util.Objects.requireNonNull;
4+
35
import java.io.ByteArrayOutputStream;
46
import java.io.File;
57
import java.io.FileInputStream;
@@ -39,9 +41,7 @@ private HttpContent(byte[] byteArrayContent, String contentType) {
3941
*/
4042
public static HttpContent buildFormURLEncodedContent(
4143
Collection<KeyValuePair<String, String>> nameValueCollection) throws IOException {
42-
if (nameValueCollection == null) {
43-
throw new IllegalArgumentException("nameValueCollection may not be null");
44-
}
44+
requireNonNull(nameValueCollection);
4545

4646
return new HttpContent(
4747
FormEncoder.createQueryString(nameValueCollection).getBytes(ApiResource.CHARSET),
@@ -74,9 +74,7 @@ public static HttpContent buildMultipartFormDataContent(
7474
public static HttpContent buildMultipartFormDataContent(
7575
Collection<KeyValuePair<String, Object>> nameValueCollection, String boundary)
7676
throws IOException {
77-
if (nameValueCollection == null) {
78-
throw new IllegalArgumentException("nameValueCollection may not be null");
79-
}
77+
requireNonNull(nameValueCollection);
8078

8179
ByteArrayOutputStream baos = new ByteArrayOutputStream();
8280
MultipartProcessor multipartProcessor = null;

src/test/java/com/stripe/net/HttpContentTest.java

+24-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertThrows;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
65

76
import com.stripe.BaseStripeTest;
87
import java.io.ByteArrayInputStream;
@@ -14,32 +13,30 @@
1413

1514
public class HttpContentTest extends BaseStripeTest {
1615
@Test
17-
public void TestBuildFormURLEncodedContentNull() throws IOException {
18-
Throwable exception =
19-
assertThrows(
20-
IllegalArgumentException.class,
21-
() -> {
22-
HttpContent.buildFormURLEncodedContent(null);
23-
});
24-
assertTrue(exception.getMessage().contains("nameValueCollection may not be null"));
16+
public void testBuildFormURLEncodedContentNull() throws IOException {
17+
assertThrows(
18+
NullPointerException.class,
19+
() -> {
20+
HttpContent.buildFormURLEncodedContent(null);
21+
});
2522
}
2623

2724
@Test
28-
public void TestBuildFormURLEncodedContentEmptySourceSuccess() throws IOException {
25+
public void testBuildFormURLEncodedContentEmptySourceSuccess() throws IOException {
2926
HttpContent content =
3027
HttpContent.buildFormURLEncodedContent(new ArrayList<KeyValuePair<String, String>>());
3128
assertEquals(0, content.byteArrayContent().length);
3229
}
3330

3431
@Test
35-
public void TestBuildFormURLEncodedContentEmptySourceCorrectContentType() throws IOException {
32+
public void testBuildFormURLEncodedContentEmptySourceCorrectContentType() throws IOException {
3633
HttpContent content =
3734
HttpContent.buildFormURLEncodedContent(new ArrayList<KeyValuePair<String, String>>());
3835
assertEquals("application/x-www-form-urlencoded;charset=UTF-8", content.contentType());
3936
}
4037

4138
@Test
42-
public void TestBuildFormURLEncodedContentOneEntrySeparatedByEquals() throws IOException {
39+
public void testBuildFormURLEncodedContentOneEntrySeparatedByEquals() throws IOException {
4340
List<KeyValuePair<String, String>> data = new ArrayList<KeyValuePair<String, String>>();
4441
data.add(new KeyValuePair<String, String>("key", "value"));
4542

@@ -49,7 +46,7 @@ public void TestBuildFormURLEncodedContentOneEntrySeparatedByEquals() throws IOE
4946
}
5047

5148
@Test
52-
public void TestBuildFormURLEncodedContentOneUnicodeEntryEncoded() throws IOException {
49+
public void testBuildFormURLEncodedContentOneUnicodeEntryEncoded() throws IOException {
5350
List<KeyValuePair<String, String>> data = new ArrayList<KeyValuePair<String, String>>();
5451
data.add(new KeyValuePair<String, String>("key", "valueク"));
5552

@@ -60,7 +57,7 @@ public void TestBuildFormURLEncodedContentOneUnicodeEntryEncoded() throws IOExce
6057
}
6158

6259
@Test
63-
public void TestBuildFormURLEncodedContentTwoEntriesSeparatedByAnd() throws IOException {
60+
public void testBuildFormURLEncodedContentTwoEntriesSeparatedByAnd() throws IOException {
6461
List<KeyValuePair<String, String>> data = new ArrayList<KeyValuePair<String, String>>();
6562
data.add(new KeyValuePair<String, String>("key1", "value1"));
6663
data.add(new KeyValuePair<String, String>("key2", "value2"));
@@ -72,7 +69,7 @@ public void TestBuildFormURLEncodedContentTwoEntriesSeparatedByAnd() throws IOEx
7269
}
7370

7471
@Test
75-
public void TestBuildFormURLEncodedContentWithSpacesEncodedAsPlus() throws IOException {
72+
public void testBuildFormURLEncodedContentWithSpacesEncodedAsPlus() throws IOException {
7673
List<KeyValuePair<String, String>> data = new ArrayList<KeyValuePair<String, String>>();
7774
data.add(new KeyValuePair<String, String>("key 1", "val%20ue 1"));
7875
data.add(new KeyValuePair<String, String>("key 2", "val%ue 2"));
@@ -85,7 +82,7 @@ public void TestBuildFormURLEncodedContentWithSpacesEncodedAsPlus() throws IOExc
8582
}
8683

8784
@Test
88-
public void TestBuildFormURLEncodedContentWithSquareBracketsUnencoded() throws IOException {
85+
public void testBuildFormURLEncodedContentWithSquareBracketsUnencoded() throws IOException {
8986
List<KeyValuePair<String, String>> data = new ArrayList<KeyValuePair<String, String>>();
9087
data.add(new KeyValuePair<String, String>("key[subkey]", "[#value]"));
9188

@@ -96,18 +93,16 @@ public void TestBuildFormURLEncodedContentWithSquareBracketsUnencoded() throws I
9693
}
9794

9895
@Test
99-
public void TestBuildMultipartFormDataContentNull() throws IOException {
100-
Throwable exception =
101-
assertThrows(
102-
IllegalArgumentException.class,
103-
() -> {
104-
HttpContent.buildMultipartFormDataContent(null);
105-
});
106-
assertTrue(exception.getMessage().contains("nameValueCollection may not be null"));
96+
public void testBuildMultipartFormDataContentNull() throws IOException {
97+
assertThrows(
98+
NullPointerException.class,
99+
() -> {
100+
HttpContent.buildMultipartFormDataContent(null);
101+
});
107102
}
108103

109104
@Test
110-
public void TestBuildMultipartFormDataContentNullEmptySourceCorrectContentType()
105+
public void testBuildMultipartFormDataContentNullEmptySourceCorrectContentType()
111106
throws IOException {
112107
HttpContent content =
113108
HttpContent.buildMultipartFormDataContent(
@@ -116,7 +111,7 @@ public void TestBuildMultipartFormDataContentNullEmptySourceCorrectContentType()
116111
}
117112

118113
@Test
119-
public void TestBuildMultipartFormDataContentNullEmptySourceSuccess() throws IOException {
114+
public void testBuildMultipartFormDataContentNullEmptySourceSuccess() throws IOException {
120115
List<KeyValuePair<String, Object>> data = new ArrayList<KeyValuePair<String, Object>>();
121116

122117
HttpContent content = HttpContent.buildMultipartFormDataContent(data, "test-boundary");
@@ -126,7 +121,7 @@ public void TestBuildMultipartFormDataContentNullEmptySourceSuccess() throws IOE
126121
}
127122

128123
@Test
129-
public void TestBuildMultipartFormDataContentNullOneStringEntrySuccess() throws IOException {
124+
public void testBuildMultipartFormDataContentNullOneStringEntrySuccess() throws IOException {
130125
List<KeyValuePair<String, Object>> data = new ArrayList<KeyValuePair<String, Object>>();
131126
data.add(new KeyValuePair<String, Object>("key", "valueク"));
132127

@@ -139,7 +134,7 @@ public void TestBuildMultipartFormDataContentNullOneStringEntrySuccess() throws
139134
}
140135

141136
@Test
142-
public void TestBuildMultipartFormDataContentNullOneStreamEntrySuccess() throws IOException {
137+
public void testBuildMultipartFormDataContentNullOneStreamEntrySuccess() throws IOException {
143138
List<KeyValuePair<String, Object>> data = new ArrayList<KeyValuePair<String, Object>>();
144139
data.add(
145140
new KeyValuePair<String, Object>(
@@ -155,7 +150,7 @@ public void TestBuildMultipartFormDataContentNullOneStreamEntrySuccess() throws
155150
}
156151

157152
@Test
158-
public void TestBuildMultipartFormDataContentNullTwoEntriesSuccess() throws IOException {
153+
public void testBuildMultipartFormDataContentNullTwoEntriesSuccess() throws IOException {
159154
List<KeyValuePair<String, Object>> data = new ArrayList<KeyValuePair<String, Object>>();
160155
data.add(
161156
new KeyValuePair<String, Object>(

0 commit comments

Comments
 (0)