Skip to content

Commit

Permalink
Call to ‘asList’ with only one argument could be replaced with ‘singl…
Browse files Browse the repository at this point in the history
…etonList’ (netty#9288)

Motivation:

asList should only be used if there are multiple elements.

Modification:

Call to asList with only one argument could be replaced with singletonList

Result:

Cleaner code and a bit of memory savings
  • Loading branch information
slievrly authored and normanmaurer committed Jun 26, 2019
1 parent 52169cb commit 6bd8f05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void addIterableCsvSingleValue() {
public void addIterableCsvEmpty() {
final CombinedHttpHeaders headers = newCombinedHttpHeaders();
headers.add(HEADER_NAME, Collections.<CharSequence>emptyList());
assertEquals(Arrays.asList(""), headers.getAll(HEADER_NAME));
assertEquals(Collections.singletonList(""), headers.getAll(HEADER_NAME));
}

@Test
Expand Down Expand Up @@ -294,9 +294,9 @@ public void testGetAll() {
headers.set(HEADER_NAME, Arrays.asList("\"a\"", "\"b\"", "\"c\""));
assertEquals(Arrays.asList("a", "b", "c"), headers.getAll(HEADER_NAME));
headers.set(HEADER_NAME, "a,b,c");
assertEquals(Arrays.asList("a,b,c"), headers.getAll(HEADER_NAME));
assertEquals(Collections.singletonList("a,b,c"), headers.getAll(HEADER_NAME));
headers.set(HEADER_NAME, "\"a,b,c\"");
assertEquals(Arrays.asList("a,b,c"), headers.getAll(HEADER_NAME));
assertEquals(Collections.singletonList("a,b,c"), headers.getAll(HEADER_NAME));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;

import static io.netty.util.internal.StringUtil.NEWLINE;
import static io.netty.util.internal.StringUtil.commonSuffixOfLength;
Expand Down Expand Up @@ -446,15 +447,15 @@ private static void assertEscapeCsvAndUnEscapeCsv(String value) {

@Test
public void testUnescapeCsvFields() {
assertEquals(Arrays.asList(""), unescapeCsvFields(""));
assertEquals(Collections.singletonList(""), unescapeCsvFields(""));
assertEquals(Arrays.asList("", ""), unescapeCsvFields(","));
assertEquals(Arrays.asList("a", ""), unescapeCsvFields("a,"));
assertEquals(Arrays.asList("", "a"), unescapeCsvFields(",a"));
assertEquals(Arrays.asList("\""), unescapeCsvFields("\"\"\"\""));
assertEquals(Collections.singletonList("\""), unescapeCsvFields("\"\"\"\""));
assertEquals(Arrays.asList("\"", "\""), unescapeCsvFields("\"\"\"\",\"\"\"\""));
assertEquals(Arrays.asList("netty"), unescapeCsvFields("netty"));
assertEquals(Collections.singletonList("netty"), unescapeCsvFields("netty"));
assertEquals(Arrays.asList("hello", "netty"), unescapeCsvFields("hello,netty"));
assertEquals(Arrays.asList("hello,netty"), unescapeCsvFields("\"hello,netty\""));
assertEquals(Collections.singletonList("hello,netty"), unescapeCsvFields("\"hello,netty\""));
assertEquals(Arrays.asList("hello", "netty"), unescapeCsvFields("\"hello\",\"netty\""));
assertEquals(Arrays.asList("a\"b", "c\"d"), unescapeCsvFields("\"a\"\"b\",\"c\"\"d\""));
assertEquals(Arrays.asList("a\rb", "c\nd"), unescapeCsvFields("\"a\rb\",\"c\nd\""));
Expand Down
8 changes: 4 additions & 4 deletions handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1918,13 +1918,13 @@ public void testHandshakeCompletesWithNonContiguousProtocolsTLSv1_2CipherOnly()
final String sharedCipher = "TLS_RSA_WITH_AES_128_CBC_SHA";
clientSslCtx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.ciphers(Arrays.asList(sharedCipher))
.ciphers(Collections.singletonList(sharedCipher))
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
.sslProvider(sslClientProvider())
.build();

serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
.ciphers(Arrays.asList(sharedCipher))
.ciphers(Collections.singletonList(sharedCipher))
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
.sslProvider(sslServerProvider())
.build();
Expand All @@ -1949,13 +1949,13 @@ public void testHandshakeCompletesWithoutFilteringSupportedCipher() throws Excep
final String sharedCipher = "TLS_RSA_WITH_AES_128_CBC_SHA";
clientSslCtx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.ciphers(Arrays.asList(sharedCipher), SupportedCipherSuiteFilter.INSTANCE)
.ciphers(Collections.singletonList(sharedCipher), SupportedCipherSuiteFilter.INSTANCE)
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
.sslProvider(sslClientProvider())
.build();

serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
.ciphers(Arrays.asList(sharedCipher), SupportedCipherSuiteFilter.INSTANCE)
.ciphers(Collections.singletonList(sharedCipher), SupportedCipherSuiteFilter.INSTANCE)
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
.sslProvider(sslServerProvider())
.build();
Expand Down

0 comments on commit 6bd8f05

Please sign in to comment.