2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.netconf.nettyutil.handler.ssh.client;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
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;
22 @RunWith(MockitoJUnitRunner.StrictStubs.class)
23 public class AsyncSshHandlerWriterTest {
25 private ByteBuf byteBuf;
28 public void setUp() throws Exception {
29 byteBuf = mock(ByteBuf.class, Mockito.CALLS_REAL_METHODS);
30 doReturn(byteBuf).when(byteBuf).resetReaderIndex();
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));
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));