/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.handler.codec.bytes;

import io.netty.buffer.ByteBuf;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.internal.EmptyArrays;
import org.junit.Before;
import org.junit.Test;

import java.util.Random;

import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;

@SuppressWarnings("ZeroLengthArrayAllocation")
public class ByteArrayEncoderTest {

    private EmbeddedChannel ch;

    @Before
    public void setUp() {
        ch = new EmbeddedChannel(new ByteArrayEncoder());
    }

    @Test
    public void testEncode() {
        byte[] b = new byte[2048];
        new Random().nextBytes(b);
        ch.writeOutbound(b);
        assertThat((ByteBuf) ch.readOutbound(), is(wrappedBuffer(b)));
    }

    @Test
    public void testEncodeEmpty() {
        ch.writeOutbound(EmptyArrays.EMPTY_BYTES);
        assertThat((ByteBuf) ch.readOutbound(), is(EMPTY_BUFFER));
    }

    @Test
    public void testEncodeOtherType() {
        String str = "Meep!";
        ch.writeOutbound(str);
        assertThat(ch.readOutbound(), is((Object) str));
    }
}

@@ -792,16 +792,40 @@
 Arrays;%0A
+import org.junit.After;%0A
 import o
@@ -964,14 +964,19 @@
 est.
-core.I
+CoreMatcher
 s.*;
@@ -1015,55 +1015,8 @@
 *;%0A%0A
-@SuppressWarnings(%22ZeroLengthArrayAllocation%22)%0A
 publ
@@ -1176,32 +1176,123 @@
 oder());%0A    %7D%0A%0A
+    @After%0A    public void tearDown() %7B%0A        assertThat(ch.finish(), is(false));%0A    %7D%0A%0A
     @Test%0A    pu
@@ -1427,68 +1427,120 @@
     
-assertThat((ByteBuf) ch.readOutbound(), is(wrappedBuffer(b))
+ByteBuf encoded = ch.readOutbound();%0A        assertThat(encoded, is(wrappedBuffer(b)));%0A        encoded.release(
 );%0A 
@@ -1693,16 +1693,29 @@
 d(), is(
+sameInstance(
 EMPTY_BU
@@ -1720,16 +1720,17 @@
 BUFFER))
+)
 ;%0A    %7D%0A

Fix resource leaks in ByteArrayEncoderTest