Refactor examples
This commit is contained in:
parent
8031458265
commit
65daa3aee2
|
@ -23,8 +23,7 @@ public class EchoClient {
|
|||
public String sendMessage(String msg) {
|
||||
try {
|
||||
out.println(msg);
|
||||
String resp = in.readLine();
|
||||
return resp;
|
||||
return in.readLine();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class EchoMultiServer {
|
|||
clientSocket.getInputStream()));
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
if ("".equals(inputLine)) {
|
||||
if (".".equals(inputLine)) {
|
||||
out.println("bye");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class EchoServer {
|
|||
clientSocket.getInputStream()));
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
if ("".equals(inputLine)) {
|
||||
if (".".equals(inputLine)) {
|
||||
out.println("good bye");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ public class GreetClient {
|
|||
public String sendMessage(String msg) {
|
||||
try {
|
||||
out.println(msg);
|
||||
String resp = in.readLine();
|
||||
return resp;
|
||||
return in.readLine();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class EchoMultiTest {
|
|||
client.startConnection("127.0.0.1", PORT);
|
||||
String msg1 = client.sendMessage("hello");
|
||||
String msg2 = client.sendMessage("world");
|
||||
String terminate = client.sendMessage("");
|
||||
String terminate = client.sendMessage(".");
|
||||
|
||||
assertEquals(msg1, "hello");
|
||||
assertEquals(msg2, "world");
|
||||
|
@ -37,7 +37,7 @@ public class EchoMultiTest {
|
|||
client.startConnection("127.0.0.1", PORT);
|
||||
String msg1 = client.sendMessage("hello");
|
||||
String msg2 = client.sendMessage("world");
|
||||
String terminate = client.sendMessage("");
|
||||
String terminate = client.sendMessage(".");
|
||||
assertEquals(msg1, "hello");
|
||||
assertEquals(msg2, "world");
|
||||
assertEquals(terminate, "bye");
|
||||
|
@ -50,7 +50,7 @@ public class EchoMultiTest {
|
|||
client.startConnection("127.0.0.1", PORT);
|
||||
String msg1 = client.sendMessage("hello");
|
||||
String msg2 = client.sendMessage("world");
|
||||
String terminate = client.sendMessage("");
|
||||
String terminate = client.sendMessage(".");
|
||||
assertEquals(msg1, "hello");
|
||||
assertEquals(msg2, "world");
|
||||
assertEquals(terminate, "bye");
|
||||
|
|
|
@ -31,7 +31,7 @@ public class EchoTest {
|
|||
String resp1 = client.sendMessage("hello");
|
||||
String resp2 = client.sendMessage("world");
|
||||
String resp3 = client.sendMessage("!");
|
||||
String resp4 = client.sendMessage("");
|
||||
String resp4 = client.sendMessage(".");
|
||||
assertEquals("hello", resp1);
|
||||
assertEquals("world", resp2);
|
||||
assertEquals("!", resp3);
|
||||
|
|
Loading…
Reference in New Issue