From 5c83dddb9182c0d74ba3685d6f5c7f09f7417681 Mon Sep 17 00:00:00 2001 From: Roger Yates <587230+rojyates@users.noreply.github.com> Date: Mon, 16 Mar 2020 06:23:33 +1000 Subject: [PATCH] BAEL-3603 Update method names and variable name for PR --- .../blockingnonblocking/BlockingClientUnitTest.java | 2 +- .../NonBlockingClientUnitTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java index 3fc968ded0..cd3d688763 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java @@ -25,7 +25,7 @@ public class BlockingClientUnitTest { } @Test - public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenReadSuccessfully() throws IOException { + public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenSuccess() throws IOException { // given an IO socket and somewhere to store our result Socket socket = new Socket("localhost", wireMockRule.port()); StringBuilder ourStore = new StringBuilder(); diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java index 47115887ab..90edee0306 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java @@ -31,7 +31,7 @@ public class NonBlockingClientUnitTest { } @Test - public void givenJavaNIOSocketChannel_whenReadingAndWriting_thenUseBuffers() throws IOException { + public void givenJavaNIOSocketChannel_whenReadingAndWritingWithBuffers_thenSuccess() throws IOException { // given a NIO SocketChannel and a charset InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); SocketChannel socketChannel = SocketChannel.open(address); @@ -58,25 +58,25 @@ public class NonBlockingClientUnitTest { } @Test - public void givenJavaNIO_whenReadingAndWriting_thenSmallBuffers() throws IOException { + public void givenJavaNIOSocketChannel_whenReadingAndWritingWithSmallBuffers_thenSuccess() throws IOException { // given a NIO SocketChannel and a charset InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); - SocketChannel socket = SocketChannel.open(address); + SocketChannel socketChannel = SocketChannel.open(address); Charset charset = StandardCharsets.UTF_8; // when we write and read using buffers that are too small for our message - socket.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); + socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access CharBuffer charBuffer = CharBuffer.allocate(8); CharsetDecoder decoder = charset.newDecoder(); StringBuilder ourStore = new StringBuilder(); - while (socket.read(buffer) != -1 || buffer.position() > 0) { + while (socketChannel.read(buffer) != -1 || buffer.position() > 0) { buffer.flip(); storeBufferContents(buffer, charBuffer, decoder, ourStore); buffer.compact(); } - socket.close(); + socketChannel.close(); // then we read and saved our data assertTrue(ourStore