@Test public void shouldCallListenersAsynchronouslyOnMessageReceived() throws Exception { when(connection.readStringByDelimiter(anyString())).thenReturn(encodedMessage); networkingService.onData(connection); verify(listener, timeout(2000)).onMessage(any(LanDownloaderMessage.class)); }
public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException { String cmd = connection.readStringByDelimiter("\r\n"); if (cmd.startsWith("A")) { connection.write("OK\r\n"); } else { connection.write(cmd + " failed\r\n"); } return true; }
public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException { connection.readStringByDelimiter("\r\n"); File file = QAUtil.createTestfile_400k(); RandomAccessFile raf = new RandomAccessFile(file, "r"); ReadableByteChannel in = raf.getChannel(); connection.transferFrom(in); in.close(); raf.close(); file.delete(); return true; }