@@ -0,0 +1,2900 @@
+/*%0A * Copyright 2014-2015 CyberVision, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.kaaproject.kaa.server.transports.tcp.transport.netty;%0A%0Aimport io.netty.channel.ChannelFuture;%0Aimport io.netty.channel.ChannelHandlerContext;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.Disconnect;%0Aimport org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.Disconnect.DisconnectReason;%0Aimport org.kaaproject.kaa.server.common.server.BadRequestException;%0Aimport org.mockito.ArgumentCaptor;%0A%0A%0Aimport java.util.Arrays;%0A%0Aimport static org.mockito.Matchers.any;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Apublic class KaaTcpExceptionHandlerTest %7B%0A    private KaaTcpExceptionHandler kaaTcpExceptionHandler = new KaaTcpExceptionHandler();%0A    private ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);%0A%0A    @Before%0A    public void before() %7B%0A        ChannelFuture future = mock(ChannelFuture.class);%0A        when(ctx.writeAndFlush(any(Object.class))).thenReturn(future);%0A    %7D%0A%0A    @Test%0A    public void badRequestExceptionTest() throws Exception %7B%0A        kaaTcpExceptionHandler.exceptionCaught(ctx, new BadRequestException(%22Bad request%22));%0A        verify(ctx).writeAndFlush(any(Object.class));%0A        ArgumentCaptor%3Cbyte%5B%5D%3E argumentCaptor = ArgumentCaptor.forClass(byte%5B%5D.class);%0A        verify(ctx).writeAndFlush(argumentCaptor.capture());%0A        Assert.assertTrue(Arrays.equals(argumentCaptor.getValue(), getMessageByteArrayForReason(DisconnectReason.BAD_REQUEST)));%0A        verify(ctx).close();%0A    %7D%0A%0A    @Test%0A    public void internalErrorExceptionTest() throws  Exception %7B%0A        kaaTcpExceptionHandler.exceptionCaught(ctx, new Exception(%22Internal error occurred%22));%0A        verify(ctx).writeAndFlush(any(Object.class));%0A        ArgumentCaptor%3Cbyte%5B%5D%3E argumentCaptor = ArgumentCaptor.forClass(byte%5B%5D.class);%0A        verify(ctx).writeAndFlush(argumentCaptor.capture());%0A        Assert.assertTrue(Arrays.equals(argumentCaptor.getValue(), getMessageByteArrayForReason(DisconnectReason.INTERNAL_ERROR)));%0A        verify(ctx).close();%0A    %7D%0A%0A    private byte%5B%5D getMessageByteArrayForReason(DisconnectReason reason) %7B%0A        return new Disconnect(reason).getFrame().array();%0A    %7D%0A%7D%0A

add test for KaaTcpExceptionHandler