CurrentTelnetHandler implements TelnetHandler { @Override public String telnet(Channel channel, String message) { if (message.length() > 0) { return "Unsupported parameter " + message + " for pwd."; } String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY); StringBuilder buf = new StringBuilder(); if (service == null || service.length() == 0) { buf.append("/"); } else { buf.append(service); } return buf.toString(); }  @Override String telnet(Channel channel, String message);  }
@Test public void testService() throws RemotingException { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService"); String result = count.telnet(mockChannel, ""); assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService", result); }
@Test public void testService() throws RemotingException { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService"); String result = count.telnet(mockChannel, ""); assertEquals("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService", result); }
@Test public void testSlash() throws RemotingException { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn(null); String result = count.telnet(mockChannel, ""); assertEquals("/", result); }
@Test public void testMessageError() throws RemotingException { mockChannel = mock(Channel.class); given(mockChannel.getAttribute("telnet.service")).willReturn(null); String result = count.telnet(mockChannel, "test"); assertEquals("Unsupported parameter test for pwd.", result); }