commit
0e1d0b4092
|
@ -14,46 +14,44 @@ public class EchoMultiTest {
|
|||
Executors.newSingleThreadExecutor().submit(() -> new EchoMultiServer().start(5555));
|
||||
}
|
||||
|
||||
EchoClient client = new EchoClient();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
@Test
|
||||
public void givenClient1_whenServerResponds_thenCorrect() {
|
||||
EchoClient client = new EchoClient();
|
||||
client.startConnection("127.0.0.1", 5555);
|
||||
}
|
||||
|
||||
@After
|
||||
public void finish(){
|
||||
String msg1 = client.sendMessage("hello");
|
||||
String msg2 = client.sendMessage("world");
|
||||
String terminate = client.sendMessage(".");
|
||||
assertEquals(msg1, "hello");
|
||||
assertEquals(msg2, "world");
|
||||
assertEquals(terminate, "bye");
|
||||
client.stopConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClient1_whenServerResponds_thenCorrect() {
|
||||
String msg1 = client.sendMessage("hello");
|
||||
String msg2 = client.sendMessage("world");
|
||||
String terminate = client.sendMessage(".");
|
||||
assertEquals(msg1, "hello");
|
||||
assertEquals(msg2, "world");
|
||||
assertEquals(terminate, "bye");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClient2_whenServerResponds_thenCorrect() {
|
||||
EchoClient client = new EchoClient();
|
||||
client.startConnection("127.0.0.1", 5555);
|
||||
String msg1 = client.sendMessage("hello");
|
||||
String msg2 = client.sendMessage("world");
|
||||
String terminate = client.sendMessage(".");
|
||||
assertEquals(msg1, "hello");
|
||||
assertEquals(msg2, "world");
|
||||
assertEquals(terminate, "bye");
|
||||
client.stopConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClient3_whenServerResponds_thenCorrect() {
|
||||
EchoClient client = new EchoClient();
|
||||
client.startConnection("127.0.0.1", 5555);
|
||||
String msg1 = client.sendMessage("hello");
|
||||
String msg2 = client.sendMessage("world");
|
||||
String terminate = client.sendMessage(".");
|
||||
assertEquals(msg1, "hello");
|
||||
assertEquals(msg2, "world");
|
||||
assertEquals(terminate, "bye");
|
||||
client.stopConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,19 +4,23 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EchoTest {
|
||||
EchoClient client = null;
|
||||
{
|
||||
Executors.newSingleThreadExecutor().submit(() -> new EchoServer().start(4444));
|
||||
}
|
||||
|
||||
EchoClient client = new EchoClient();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
client = new EchoClient();
|
||||
public void init() {
|
||||
client.startConnection("127.0.0.1", 4444);
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
@Test
|
||||
public void givenClient_whenServerEchosMessage_thenCorrect() {
|
||||
|
||||
String resp1 = client.sendMessage("hello");
|
||||
|
|
|
@ -19,11 +19,12 @@ public class GreetServerTest {
|
|||
@Before
|
||||
public void init() {
|
||||
client = new GreetClient();
|
||||
client.startConnection("127.0.0.1", 6666);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenGreetingClient_whenServerRespondsWhenStarted_thenCorrect() {
|
||||
client.startConnection("127.0.0.1", 6666);
|
||||
String response = client.sendMessage("hello server");
|
||||
assertEquals("hello client", response);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue