Make methods 'static' where it possible

Motivation:

Even if it's a super micro-optimization (most JVM could optimize such
 cases in runtime), in theory (and according to some perf tests) it
 may help a bit. It also makes a code more clear and allows you to
 access such methods in the test scope directly, without instance of
 the class.

Modifications:

Add 'static' modifier for all methods, where it possible. Mostly in
test scope.

Result:

Cleaner code with proper 'static' modifiers.
This commit is contained in:
Idel Pivnitskiy 2017-10-14 06:49:45 -07:00 committed by Norman Maurer
parent 134ee2dbba
commit a1328419fd
9 changed files with 26 additions and 26 deletions

View File

@ -201,7 +201,7 @@ public class ReadOnlyByteBufTest {
ensureWritableIntStatusShouldFailButNotThrow(true);
}
private void ensureWritableIntStatusShouldFailButNotThrow(boolean force) {
private static void ensureWritableIntStatusShouldFailButNotThrow(boolean force) {
ByteBuf buf = buffer(1);
ByteBuf readOnly = unmodifiableBuffer(buf);
int result = readOnly.ensureWritable(1, force);

View File

@ -98,7 +98,7 @@ public class NettyRuntimeTests {
assertNull(secondRefernce.get());
}
private Runnable getRunnable(
private static Runnable getRunnable(
final NettyRuntime.AvailableProcessorsHolder holder,
final CyclicBarrier barrier,
final AtomicReference<IllegalStateException> reference) {

View File

@ -230,8 +230,8 @@ public class DefaultPromiseTest {
}
}
private void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor,
boolean runTestInExecutorThread)
private static void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor,
boolean runTestInExecutorThread)
throws InterruptedException {
final Promise<Void>[] p = new DefaultPromise[promiseChainLength];
final CountDownLatch latch = new CountDownLatch(promiseChainLength);
@ -253,8 +253,8 @@ public class DefaultPromiseTest {
}
}
private void testStackOverFlowChainedFuturesA(EventExecutor executor, final Promise<Void>[] p,
final CountDownLatch latch) {
private static void testStackOverFlowChainedFuturesA(EventExecutor executor, final Promise<Void>[] p,
final CountDownLatch latch) {
for (int i = 0; i < p.length; i ++) {
final int finalI = i;
p[i] = new DefaultPromise<Void>(executor);
@ -272,8 +272,8 @@ public class DefaultPromiseTest {
p[0].setSuccess(null);
}
private void testStackOverFlowChainedFuturesB(int promiseChainLength, final EventExecutor executor,
boolean runTestInExecutorThread)
private static void testStackOverFlowChainedFuturesB(int promiseChainLength, final EventExecutor executor,
boolean runTestInExecutorThread)
throws InterruptedException {
final Promise<Void>[] p = new DefaultPromise[promiseChainLength];
final CountDownLatch latch = new CountDownLatch(promiseChainLength);
@ -295,8 +295,8 @@ public class DefaultPromiseTest {
}
}
private void testStackOverFlowChainedFuturesB(EventExecutor executor, final Promise<Void>[] p,
final CountDownLatch latch) {
private static void testStackOverFlowChainedFuturesB(EventExecutor executor, final Promise<Void>[] p,
final CountDownLatch latch) {
for (int i = 0; i < p.length; i ++) {
final int finalI = i;
p[i] = new DefaultPromise<Void>(executor);

View File

@ -186,7 +186,7 @@ public class DefaultThreadFactoryTest {
}
}
private void runStickyThreadGroupTest(
private static void runStickyThreadGroupTest(
final Callable<DefaultThreadFactory> callable,
final ThreadGroup expected) throws InterruptedException {
final AtomicReference<ThreadGroup> captured = new AtomicReference<ThreadGroup>();

View File

@ -389,7 +389,7 @@ public class StringUtilTest {
assertEscapeCsvAndUnEscapeCsv("\n");
}
private void assertEscapeCsvAndUnEscapeCsv(String value) {
private static void assertEscapeCsvAndUnEscapeCsv(String value) {
assertEquals(value, unescapeCsv(StringUtil.escapeCsv(value)));
}

View File

@ -307,14 +307,14 @@ public class CipherSuiteConverterTest {
testUnknownJavaCiphersToOpenSSL("");
}
private void testUnknownOpenSSLCiphersToJava(String openSslCipherSuite) {
private static void testUnknownOpenSSLCiphersToJava(String openSslCipherSuite) {
CipherSuiteConverter.clearCache();
assertNull(CipherSuiteConverter.toJava(openSslCipherSuite, "TLS"));
assertNull(CipherSuiteConverter.toJava(openSslCipherSuite, "SSL"));
}
private void testUnknownJavaCiphersToOpenSSL(String javaCipherSuite) {
private static void testUnknownJavaCiphersToOpenSSL(String javaCipherSuite) {
CipherSuiteConverter.clearCache();
assertNull(CipherSuiteConverter.toOpenSsl(javaCipherSuite));

View File

@ -99,7 +99,7 @@ public class OcspTest {
testClientOcspNotEnabled(SslProvider.OPENSSL_REFCNT);
}
private void testClientOcspNotEnabled(SslProvider sslProvider) throws Exception {
private static void testClientOcspNotEnabled(SslProvider sslProvider) throws Exception {
SslContext context = SslContextBuilder.forClient()
.sslProvider(sslProvider)
.build();
@ -126,7 +126,7 @@ public class OcspTest {
testServerOcspNotEnabled(SslProvider.OPENSSL_REFCNT);
}
private void testServerOcspNotEnabled(SslProvider sslProvider) throws Exception {
private static void testServerOcspNotEnabled(SslProvider sslProvider) throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
try {
SslContext context = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
@ -161,7 +161,7 @@ public class OcspTest {
/**
* The Server provides an OCSP staple and the Client accepts it.
*/
private void testClientAcceptingOcspStaple(SslProvider sslProvider) throws Exception {
private static void testClientAcceptingOcspStaple(SslProvider sslProvider) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
ChannelInboundHandlerAdapter serverHandler = new ChannelInboundHandlerAdapter() {
@Override
@ -207,7 +207,7 @@ public class OcspTest {
/**
* The Server provides an OCSP staple and the Client rejects it.
*/
private void testClientRejectingOcspStaple(SslProvider sslProvider) throws Exception {
private static void testClientRejectingOcspStaple(SslProvider sslProvider) throws Exception {
final AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
final CountDownLatch latch = new CountDownLatch(1);
@ -250,7 +250,7 @@ public class OcspTest {
/**
* The server has OCSP stapling enabled but doesn't provide a staple.
*/
private void testServerHasNoStaple(SslProvider sslProvider) throws Exception {
private static void testServerHasNoStaple(SslProvider sslProvider) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
ChannelInboundHandlerAdapter serverHandler = new ChannelInboundHandlerAdapter() {
@Override
@ -297,7 +297,7 @@ public class OcspTest {
*
* The exception should bubble up on the client side and the connection should get closed.
*/
private void testClientException(SslProvider sslProvider) throws Exception {
private static void testClientException(SslProvider sslProvider) throws Exception {
final AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
final CountDownLatch latch = new CountDownLatch(1);

View File

@ -67,7 +67,7 @@ public class IdleStateHandlerTest {
IdleStateEvent.ALL_IDLE_STATE_EVENT, IdleStateEvent.ALL_IDLE_STATE_EVENT);
}
private void anyIdle(TestableIdleStateHandler idleStateHandler, Object... expected) throws Exception {
private static void anyIdle(TestableIdleStateHandler idleStateHandler, Object... expected) throws Exception {
assertTrue("The number of expected events must be >= 1", expected.length >= 1);
@ -159,8 +159,8 @@ public class IdleStateHandlerTest {
anyNotIdle(idleStateHandler, writer, IdleStateEvent.FIRST_ALL_IDLE_STATE_EVENT);
}
private void anyNotIdle(TestableIdleStateHandler idleStateHandler,
Action action, Object expected) throws Exception {
private static void anyNotIdle(TestableIdleStateHandler idleStateHandler,
Action action, Object expected) throws Exception {
final List<Object> events = new ArrayList<Object>();
ChannelInboundHandlerAdapter handler = new ChannelInboundHandlerAdapter() {
@ -205,7 +205,7 @@ public class IdleStateHandlerTest {
observeOutputIdle(false);
}
private void observeOutputIdle(boolean writer) throws Exception {
private static void observeOutputIdle(boolean writer) throws Exception {
long writerIdleTime = 0L;
long allIdleTime = 0L;

View File

@ -56,11 +56,11 @@ public class EpollSocketChannelConfigTest {
}
}
private long randLong(long min, long max) {
private static long randLong(long min, long max) {
return min + nextLong(max - min + 1);
}
private long nextLong(long n) {
private static long nextLong(long n) {
long bits, val;
do {
bits = (rand.nextLong() << 1) >>> 1;