@Override public void run() throws Exception { assertThat(newServer.port(), is(12306)); } });
@Test public void should_return_many_expected_responses() throws Exception { server.request(by("foo")).response(line("bar")); server.request(by("bar")).response(line("blah")); running(server, new Runnable() { @Override public void run() throws Exception { helper.connect(); assertThat(helper.send("foo"), is("bar")); assertThat(helper.send("bar"), is("blah")); helper.close(); } }); }
@Test public void should_log_request_and_response_into_file() throws Exception { File file = folder.newFile(); SocketServer socketServer = socketServer(port(), log(file.getAbsolutePath())); socketServer.request(by("0XCAFE")).response(line("0XBABE")); running(socketServer, new Runnable() { @Override public void run() throws Exception { helper.connect(); assertThat(helper.send("0XCAFE"), is("0XBABE")); helper.close(); } }); String actual = Files.toString(file, Charset.defaultCharset()); assertThat(actual, containsString("0XBABE")); assertThat(actual, containsString("0XCAFE")); }
@Test public void should_return_expected_response() throws Exception { server.request(by("foo")).response(line("bar")); running(server, new Runnable() { @Override public void run() throws Exception { helper.connect(); assertThat(helper.send("foo"), is("bar")); helper.close(); } }); }
@Override public void run() throws Exception { assertThat(newServer.port(), is(12307)); } });
@Test public void should_match_extreme_big_request() throws Exception { server.request(by(times("a", 1025))).response(line("long_a")); running(server, new Runnable() { @Override public void run() throws Exception { helper.connect(); assertThat(helper.send(times("a", 1025)), is("long_a")); helper.close(); } }); }
@Override public void run() throws Exception { MocoSocketHelper mocoSocketHelper = new MocoSocketHelper(local(), server.port()); mocoSocketHelper.connect(); assertThat(mocoSocketHelper.send("foo", 3), is("bar")); mocoSocketHelper.close(); } });
@Test public void should_merge_socket_servers() throws Exception { SocketServer server = socketServer(12306); SocketServer secondServer = socketServer(12306); server.request(by("foo")).response(line("bar")); secondServer.request(by("foo1")).response(line("bar1")); SocketServer newServer = ((ActualSocketServer) server).mergeServer((ActualSocketServer) secondServer); running(newServer, new Runnable() { @Override public void run() throws Exception { helper.connect(); assertThat(helper.send("foo"), is("bar")); assertThat(helper.send("foo1"), is("bar1")); helper.close(); } }); }
@Override public void run() throws Exception { helper = new MocoSocketHelper(local(), socketServer.port()); helper.connect(); assertThat(helper.send("foo"), is("bar")); helper.close(); } });
@Test public void should_create_socket_server_without_specific_port() throws Exception { final SocketServer socketServer = socketServer(); socketServer.request(by("foo")).response(line("bar")); running(socketServer, new Runnable() { @Override public void run() throws Exception { helper = new MocoSocketHelper(local(), socketServer.port()); helper.connect(); assertThat(helper.send("foo"), is("bar")); helper.close(); } }); }
@Override public void run() throws Exception { helper = new MocoSocketHelper(local(), socketServer.port()); helper.connect(); assertThat(helper.send("foo"), is("bar")); helper.close(); } });
@Test public void should_monitor_socket_server_behavior() throws Exception { RequestHit hit = requestHit(); SocketServer socketServer = socketServer(port(), hit); socketServer.request(by("0XCAFE")).response(line("0XBABE")); running(socketServer, new Runnable() { @Override public void run() throws Exception { helper.connect(); assertThat(helper.send("0XCAFE"), is("0XBABE")); helper.close(); } }); hit.verify(by("0XCAFE"), once()); }
@Test public void should_verify_expected_request_and_log_at_same_time() throws Exception { RequestHit hit = requestHit(); final SocketServer socketServer = socketServer(port(), hit, log()); socketServer.request(by("foo")).response(line("bar")); running(socketServer, new Runnable() { @Override public void run() throws Exception { helper = new MocoSocketHelper(local(), socketServer.port()); helper.connect(); assertThat(helper.send("foo"), is("bar")); helper.close(); } }); hit.verify(by("foo"), once()); }