Repository: netty/netty
File: handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java (Java)

Code before:
            assertThat(serverEventCause.getCause(),
                    not(CoreMatchers.<Throwable>instanceOf(ClosedChannelException.class)));
        } finally {
            group.shutdownGracefully();
            ReferenceCountUtil.release(sslClientCtx);
        }
    }

    @Test
    public void testIncorrectLength() throws SSLException {
        SelfSignedCertificate cert = CachedSelfSignedCertificate.getCachedCertificate();
        EmbeddedChannel channel = new EmbeddedChannel();
        channel.pipeline().addLast(
                SslContextBuilder.forServer(cert.key(), cert.cert())
                        .sslProvider(SslProvider.JDK)
                        .build()
                        .newHandler(channel.alloc()));
        ByteBuf buf = channel.alloc().buffer(5);
        buf.writeByte(0x0);
        buf.writeByte(0x1);
        buf.writeByte(0xfe);
        buf.writeByte(0x87);
        buf.writeByte(0x2);
        DecoderException e = assertThrows(DecoderException.class, () -> channel.writeInbound(buf));
        assertThat(e.getCause(), instanceOf(NotSslRecordException.class));
        channel.finishAndReleaseAll();
    }

    @Test
    public void testSslCompletionEventsTls12JDK() throws Exception {
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_2, true);
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_2, false);
    }

    @Test
    public void testSslCompletionEventsTls12Openssl() throws Exception {
        OpenSsl.ensureAvailability();
        testSslCompletionEvents(SslProvider.OPENSSL, SslProtocols.TLS_v1_2, true);
        testSslCompletionEvents(SslProvider.OPENSSL, SslProtocols.TLS_v1_2, false);
    }

    @Test
    public void testSslCompletionEventsTls13JDK() throws Exception {
        assumeTrue(SslProvider.isTlsv13Supported(SslProvider.JDK));
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_3, true);
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_3, false);
    }

    @Test
    public void testSslCompletionEventsTls13Openssl() throws Exception {
        OpenSsl.ensureAvailability();

Review comment (suggestion):
```suggestion
        assertTrue(channel.finishAndReleaseAll());
```

Code after:
            assertThat(serverEventCause.getCause(),
                    not(CoreMatchers.<Throwable>instanceOf(ClosedChannelException.class)));
        } finally {
            group.shutdownGracefully();
            ReferenceCountUtil.release(sslClientCtx);
        }
    }

    @Test
    public void testIncorrectLength() throws SSLException {
        final SelfSignedCertificate cert = CachedSelfSignedCertificate.getCachedCertificate();
        final EmbeddedChannel channel = new EmbeddedChannel();
        channel.pipeline().addLast(
                SslContextBuilder.forServer(cert.key(), cert.cert())
                        .sslProvider(SslProvider.JDK)
                        .build()
                        .newHandler(channel.alloc()));
        final ByteBuf buf = channel.alloc().buffer(5);
        buf.writeByte(0x0);
        buf.writeByte(0x1);
        buf.writeByte(0xfe);
        buf.writeByte(0x87);
        buf.writeByte(0x2);
        DecoderException e = assertThrows(DecoderException.class, new Executable() {
            @Override
            public void execute() {
                channel.writeInbound(buf);
            }
        });
        assertThat(e.getCause(), instanceOf(NotSslRecordException.class));
        assertTrue(channel.finishAndReleaseAll());
    }

    @Test
    public void testSslCompletionEventsTls12JDK() throws Exception {
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_2, true);
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_2, false);
    }

    @Test
    public void testSslCompletionEventsTls12Openssl() throws Exception {
        OpenSsl.ensureAvailability();
        testSslCompletionEvents(SslProvider.OPENSSL, SslProtocols.TLS_v1_2, true);
        testSslCompletionEvents(SslProvider.OPENSSL, SslProtocols.TLS_v1_2, false);
    }

    @Test
    public void testSslCompletionEventsTls13JDK() throws Exception {
        assumeTrue(SslProvider.isTlsv13Supported(SslProvider.JDK));
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_3, true);
        testSslCompletionEvents(SslProvider.JDK, SslProtocols.TLS_v1_3, false);