Utils { public static Map convert(String mapString) { Map res = new HashMap<>(); String[] pairs = mapString.substring(1, mapString.length() - 1).split(","); for (String pair : pairs) { String[] keyValue = pair.trim().split("="); checkFormat(keyValue.length); res.put(keyValue[0], keyValue[1]); } return res; }  static String toStringResult(List<String> result); static Map convert(String mapString); static Date getRegisterDateAsDdMmYyyy(String registrationDateString); static Date getRegisterDateByYyyyMmDd(String registrationDateString); static void clearAudioFile(String fileName); static void showMessageByToast(Context context, int ResId, int duration); static void showMessageByToast(Context context, String message, int duration);  }
@Test public void should_convert_string_to_map() { String mapString = "{a=1, b=2}"; Map<String, String> map = Utils.convert(mapString); assertThat(map.size(), is(2)); assertThat(map.get("a"), is("1")); assertThat(map.get("b"), is("2")); }
@Test(expected = IllegalArgumentException.class) public void should_throw_exception_when_invalid_string() { String mapString = "1234"; Utils.convert(mapString); }