9644315c4703442d9c7c1406952f55ea593f77ee
[netconf.git] / netconf / netconf-netty-util / src / test / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / AsyncSshHandlerWriterTest.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.nettyutil.handler.ssh.client;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13
14 import io.netty.buffer.ByteBuf;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.ArgumentMatchers;
19 import org.mockito.Mockito;
20 import org.mockito.junit.MockitoJUnitRunner;
21
22 @RunWith(MockitoJUnitRunner.StrictStubs.class)
23 public class AsyncSshHandlerWriterTest {
24
25     private ByteBuf byteBuf;
26
27     @Before
28     public void setUp() throws Exception {
29         byteBuf = mock(ByteBuf.class, Mockito.CALLS_REAL_METHODS);
30         doReturn(byteBuf).when(byteBuf).resetReaderIndex();
31     }
32
33     @Test
34     public void testByteBufToString() {
35         String testText = "Lorem Ipsum 0123456780!@#$%^&*<>\\|/?[]()\n\r";
36         doReturn(testText).when(byteBuf).toString(ArgumentMatchers.any());
37         assertEquals(testText, AsyncSshHandlerWriter.byteBufToString(byteBuf));
38
39         testText = "Lorem Ipsum" + (char) 0x8 + " 0123456780" + (char) 0x11 + (char) 0x7F + "9 !@#$%^&*<>\\|/?[]()\n\r";
40         doReturn(testText).when(byteBuf).toString(ArgumentMatchers.any());
41         assertEquals("Lorem Ipsum\"08\" 0123456780\"117F\"9 !@#$%^&*<>\\|/?[]()\n\r",
42                 AsyncSshHandlerWriter.byteBufToString(byteBuf));
43     }
44 }