Skip to content

Commit 3480c91

Browse files
committed
Have Assertions return tested object
1 parent 57f8540 commit 3480c91

File tree

12 files changed

+20
-36
lines changed

12 files changed

+20
-36
lines changed

client/src/main/java/org/asynchttpclient/Realm.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,9 @@ private Realm(AuthScheme scheme,//
8383
boolean useAbsoluteURI,//
8484
boolean omitQuery) {
8585

86-
assertNotNull(scheme, "scheme");
87-
assertNotNull(principal, "principal");
88-
assertNotNull(password, "password");
89-
90-
this.scheme = scheme;
91-
this.principal = principal;
92-
this.password = password;
86+
this.scheme = assertNotNull(scheme, "scheme");
87+
this.principal = assertNotNull(principal, "principal");
88+
this.password = assertNotNull(password, "password");
9389
this.realmName = realmName;
9490
this.nonce = nonce;
9591
this.algorithm = algorithm;

client/src/main/java/org/asynchttpclient/cookie/Cookie.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public class Cookie {
1818

1919
public static Cookie newValidCookie(String name, String value, boolean wrap, String domain, String path, long maxAge, boolean secure, boolean httpOnly) {
2020

21-
assertNotNull(name, "name");
22-
name = name.trim();
21+
name = assertNotNull(name, "name").trim();
2322
assertNotEmpty(name, "name");
2423

2524
for (int i = 0; i < name.length(); i++) {
@@ -47,11 +46,7 @@ public static Cookie newValidCookie(String name, String value, boolean wrap, Str
4746
throw new IllegalArgumentException("name starting with '$' not allowed: " + name);
4847
}
4948

50-
assertNotNull(value, "value");
51-
domain = validateValue("domain", domain);
52-
path = validateValue("path", path);
53-
54-
return new Cookie(name, value, wrap, domain, path, maxAge, secure, httpOnly);
49+
return new Cookie(name, assertNotNull(value, "value"), wrap, validateValue("domain", domain), validateValue("path", path), maxAge, secure, httpOnly);
5550
}
5651

5752
private static String validateValue(String name, String value) {

client/src/main/java/org/asynchttpclient/netty/channel/DefaultChannelPool.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ private static final class IdleChannel {
9999
final long start;
100100

101101
IdleChannel(Channel channel, long start) {
102-
assertNotNull(channel, "channel");
103-
this.channel = channel;
102+
this.channel = assertNotNull(channel, "channel");
104103
this.start = start;
105104
}
106105

client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public class BodyChunkedInput implements ChunkedInput<ByteBuf> {
3232
private boolean endOfInput;
3333

3434
public BodyChunkedInput(Body body) {
35-
assertNotNull(body, "body");
36-
this.body = body;
35+
this.body = assertNotNull(body, "body");
3736
long contentLength = body.getContentLength();
3837
if (contentLength <= 0)
3938
chunkSize = DEFAULT_CHUNK_SIZE;

client/src/main/java/org/asynchttpclient/netty/request/body/BodyFileRegion.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public class BodyFileRegion extends AbstractReferenceCounted implements FileRegi
3333
private long transfered;
3434

3535
public BodyFileRegion(RandomAccessBody body) {
36-
assertNotNull(body, "body");
37-
this.body = body;
36+
this.body = assertNotNull(body, "body");
3837
}
3938

4039
@Override

client/src/main/java/org/asynchttpclient/request/body/generator/FileBodyGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public FileBodyGenerator(File file) {
3232
}
3333

3434
public FileBodyGenerator(File file, long regionSeek, long regionLength) {
35-
assertNotNull(file, "file");
36-
this.file = file;
35+
this.file = assertNotNull(file, "file");
3736
this.regionLength = regionLength;
3837
this.regionSeek = regionSeek;
3938
}

client/src/main/java/org/asynchttpclient/request/body/multipart/ByteArrayPart.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public ByteArrayPart(String name, byte[] bytes, String contentType, Charset char
4242

4343
public ByteArrayPart(String name, byte[] bytes, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) {
4444
super(name, contentType, charset, contentId, transferEncoding);
45-
assertNotNull(bytes, "bytes");
46-
this.bytes = bytes;
45+
this.bytes = assertNotNull(bytes, "bytes");
4746
setFileName(fileName);
4847
}
4948

client/src/main/java/org/asynchttpclient/request/body/multipart/FilePart.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public FilePart(String name, File file, String contentType, Charset charset, Str
4343

4444
public FilePart(String name, File file, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) {
4545
super(name, contentType, charset, contentId, transferEncoding);
46-
assertNotNull(file, "file");
47-
if (!file.isFile())
46+
if (!assertNotNull(file, "file").isFile())
4847
throw new IllegalArgumentException("File is not a normal file " + file.getAbsolutePath());
4948
if (!file.canRead())
5049
throw new IllegalArgumentException("File is not readable " + file.getAbsolutePath());

client/src/main/java/org/asynchttpclient/request/body/multipart/MultipartBody.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ public class MultipartBody implements RandomAccessBody {
4242
private AtomicBoolean closed = new AtomicBoolean();
4343

4444
public MultipartBody(List<MultipartPart<? extends Part>> parts, String contentType, byte[] boundary) {
45-
assertNotNull(parts, "parts");
4645
this.boundary = boundary;
4746
this.contentType = contentType;
48-
this.parts = parts;
47+
this.parts = assertNotNull(parts, "parts");
4948
this.contentLength = computeContentLength();
5049
}
5150

client/src/main/java/org/asynchttpclient/uri/Uri.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ public Uri(String scheme,//
6060
String path,//
6161
String query) {
6262

63-
assertNotNull(scheme, "scheme");
64-
assertNotNull(host, "host");
65-
this.scheme = scheme;
63+
this.scheme = assertNotNull(scheme, "scheme");
6664
this.userInfo = userInfo;
67-
this.host = host;
65+
this.host = assertNotNull(host, "host");
6866
this.port = port;
6967
this.path = path;
7068
this.query = query;

client/src/main/java/org/asynchttpclient/util/Assertions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ public final class Assertions {
1818
private Assertions() {
1919
}
2020

21-
public static void assertNotNull(Object value, String name) {
21+
public static <T> T assertNotNull(T value, String name) {
2222
if (value == null)
2323
throw new NullPointerException(name);
24+
return value;
25+
2426
}
2527

26-
public static void assertNotEmpty(String value, String name) {
28+
public static String assertNotEmpty(String value, String name) {
2729
if (value.length() == 0)
2830
throw new IllegalArgumentException("empty " + name);
31+
return value;
2932
}
3033
}

client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public final WebSocket onCompleted() throws Exception {
9595
throw e;
9696
}
9797

98-
assertNotNull(webSocket, "webSocket");
99-
return webSocket;
98+
return assertNotNull(webSocket, "webSocket");
10099
}
101100

102101
/**

0 commit comments

Comments
 (0)