UDPOperations { public static final DatagramPacket receive(DatagramSocket socket) throws IOException { byte[] receive = new byte[15000]; DatagramPacket packet = new DatagramPacket(receive, receive.length); socket.receive(packet); byte[] data = ByteArray.trim(receive); packet.setData(data); Logger.info(TAG, format("%s[%d]\tPacket received\tlength: %d", packet.getAddress().getHostAddress(), packet.getPort(), data.length)); return packet; } private  UDPOperations(); static final void send(DatagramSocket socket, InetAddress receiverIP, int receiverPort, byte[] data); static final byte[] receiveData(DatagramSocket socket); static final DatagramPacket receive(DatagramSocket socket);  }
@Test public void testError() throws Exception { final String data = new String("hello"); new Thread() { @Override public void run() { super.run(); try { DatagramSocket receiver = new DatagramSocket(9); UDPOperations.receive(receiver); receiver.close(); assert false; } catch (SocketException e) { assert true; } catch (IOException e) { e.printStackTrace(); } } }.start(); }