Refactor examples

This commit is contained in:
Grzegorz Piwowarek 2016-10-23 11:57:11 +02:00
parent 8031458265
commit 65daa3aee2
6 changed files with 8 additions and 10 deletions

View File

@ -23,8 +23,7 @@ public class EchoClient {
public String sendMessage(String msg) { public String sendMessage(String msg) {
try { try {
out.println(msg); out.println(msg);
String resp = in.readLine(); return in.readLine();
return resp;
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }

View File

@ -46,7 +46,7 @@ public class EchoMultiServer {
clientSocket.getInputStream())); clientSocket.getInputStream()));
String inputLine; String inputLine;
while ((inputLine = in.readLine()) != null) { while ((inputLine = in.readLine()) != null) {
if ("".equals(inputLine)) { if (".".equals(inputLine)) {
out.println("bye"); out.println("bye");
break; break;
} }

View File

@ -18,7 +18,7 @@ public class EchoServer {
clientSocket.getInputStream())); clientSocket.getInputStream()));
String inputLine; String inputLine;
while ((inputLine = in.readLine()) != null) { while ((inputLine = in.readLine()) != null) {
if ("".equals(inputLine)) { if (".".equals(inputLine)) {
out.println("good bye"); out.println("good bye");
break; break;
} }

View File

@ -26,8 +26,7 @@ public class GreetClient {
public String sendMessage(String msg) { public String sendMessage(String msg) {
try { try {
out.println(msg); out.println(msg);
String resp = in.readLine(); return in.readLine();
return resp;
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }

View File

@ -23,7 +23,7 @@ public class EchoMultiTest {
client.startConnection("127.0.0.1", PORT); client.startConnection("127.0.0.1", PORT);
String msg1 = client.sendMessage("hello"); String msg1 = client.sendMessage("hello");
String msg2 = client.sendMessage("world"); String msg2 = client.sendMessage("world");
String terminate = client.sendMessage(""); String terminate = client.sendMessage(".");
assertEquals(msg1, "hello"); assertEquals(msg1, "hello");
assertEquals(msg2, "world"); assertEquals(msg2, "world");
@ -37,7 +37,7 @@ public class EchoMultiTest {
client.startConnection("127.0.0.1", PORT); client.startConnection("127.0.0.1", PORT);
String msg1 = client.sendMessage("hello"); String msg1 = client.sendMessage("hello");
String msg2 = client.sendMessage("world"); String msg2 = client.sendMessage("world");
String terminate = client.sendMessage(""); String terminate = client.sendMessage(".");
assertEquals(msg1, "hello"); assertEquals(msg1, "hello");
assertEquals(msg2, "world"); assertEquals(msg2, "world");
assertEquals(terminate, "bye"); assertEquals(terminate, "bye");
@ -50,7 +50,7 @@ public class EchoMultiTest {
client.startConnection("127.0.0.1", PORT); client.startConnection("127.0.0.1", PORT);
String msg1 = client.sendMessage("hello"); String msg1 = client.sendMessage("hello");
String msg2 = client.sendMessage("world"); String msg2 = client.sendMessage("world");
String terminate = client.sendMessage(""); String terminate = client.sendMessage(".");
assertEquals(msg1, "hello"); assertEquals(msg1, "hello");
assertEquals(msg2, "world"); assertEquals(msg2, "world");
assertEquals(terminate, "bye"); assertEquals(terminate, "bye");

View File

@ -31,7 +31,7 @@ public class EchoTest {
String resp1 = client.sendMessage("hello"); String resp1 = client.sendMessage("hello");
String resp2 = client.sendMessage("world"); String resp2 = client.sendMessage("world");
String resp3 = client.sendMessage("!"); String resp3 = client.sendMessage("!");
String resp4 = client.sendMessage(""); String resp4 = client.sendMessage(".");
assertEquals("hello", resp1); assertEquals("hello", resp1);
assertEquals("world", resp2); assertEquals("world", resp2);
assertEquals("!", resp3); assertEquals("!", resp3);