Utils { public static String randomId() { String s = getRandomString(10); MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } messageDigest.update(s.getBytes()); return new String(messageDigest.digest(), Bencode.DEFAULT_CHARSET); }  static String getNeighbour(String s1, String s2); static String randomId(); static String getRandomString(int size); static byte[] enBencode(Map<String, Object> map); static Map<String, Object> deBencode(byte[] data); static List<Node> decodeNodes(String encodeNodes); static byte[] getByteArray(byte[] bytes, int start, int end); static int getPort(byte[] bytes); static List<Node> fixedNodes; }
@Test public void testRandomId() throws Exception { String result = Utils.randomId(); assertEquals(20, result.getBytes(Bencode.DEFAULT_CHARSET).length); }