Sentence implements AbstractServerSocket<Sentence> { public Sentence find(ServerSocketPredicate predicate) { return new Sentence(server, this.predicate.and(predicate)); } Sentence(Server server, ServerSocketPredicate predicate); Sentence find(ServerSocketPredicate predicate); Sentence execute(SerializableAction<ServerSocket> action); @Override Sentence send(String event, Object data); @Override void close(); @Override Sentence tag(String... names); @Override Sentence untag(String... names);  }
@Test public void find() { ServerSocket socket = mock(ServerSocket.class); Server server = new DefaultServer() { @Override public Server find(ServerSocketPredicate predicate, SerializableAction<ServerSocket> action) { when(socket.get("stop")).thenReturn("doing"); when(socket.get("start")).thenReturn("talking"); assertFalse(predicate.test(socket)); when(socket.get("stop")).thenReturn("talking"); when(socket.get("start")).thenReturn("talking"); assertFalse(predicate.test(socket)); when(socket.get("stop")).thenReturn("talking"); when(socket.get("start")).thenReturn("doing"); assertTrue(predicate.test(socket)); return this; } }; Sentence s1 = server.find(ServerSocketPredicates.attr("stop", "talking")); Sentence s2 = s1.find(ServerSocketPredicates.attr("start", "doing")); assertNotSame(s1, s2); s2.execute(NOOP_ACTION); }