Utils { public static String getKeyByValue(final Map<String, String> map, final String value) { for (final Entry<String, String> entry : map.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); } } return null; }  static String toXMLDateTime(final Date date); static Date fromXMLDateTime(final String xmlDateTimeString); static String detectMimeType(final File f); static String getExtension(final String mimeType); static Path createFileWithUniqueName(final String baseName); static void sortFiles(final File array[]); static String getKeyByValue(final Map<String, String> map, final String value); static int compareStrings(final String s, final String p); static String getValue(final String value, final String defaultValue); static boolean isNullOrEmpty(final String s); static boolean isNullOrEmpty(final Collection<?> c); static boolean isNullOrEmpty(final Map<?,?> m); static boolean isNullOrEmpty(final Iterator<?> i); static Throwable getRootCause(final Throwable t); static List<Throwable> getCauses(final Throwable t); static String getExceptionTrace(final Throwable t); static boolean nullSafeEqual(final T o1, final T o2); static boolean nullSafeEqualIgnoreCase(final String s1, final String s2); static boolean isValidURI(final String uri); static boolean isTrue(String value);  }
@Test public void testGetKeyByValue() { HashMap<String, String> map = new HashMap<>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); assertEquals("key1", Utils.getKeyByValue(map, "value1")); assertEquals("key2", Utils.getKeyByValue(map, "value2")); assertEquals("key3", Utils.getKeyByValue(map, "value3")); }