PinyinMapDict implements PinyinDict { @Override public String[] toPinyin(String word) { return mapping() != null ? mapping().get(word) : null; }  abstract Map<String, String[]> mapping(); @Override Set<String> words(); @Override String[] toPinyin(String word);  }
@Test public void toPinyin_null_map_return_null() throws Exception { PinyinMapDict dict = new PinyinMapDict() { @Override public Map<String, String[]> mapping() { return null; } }; assertThat(dict.toPinyin("1"), nullValue()); }
@Test public void toPinyin_nonnull_map_return_value() throws Exception { final Map<String, String[]> map = new HashMap<String, String[]>(); map.put("1", new String[]{"ONE"}); PinyinMapDict dict = new PinyinMapDict() { @Override public Map<String, String[]> mapping() { return map; } }; assertThat(dict.toPinyin("1"), is(map.get("1"))); }
@Test public void toPinyin_nonnull_map_nokey_return_null() throws Exception { final Map<String, String[]> map = new HashMap<String, String[]>(); map.put("1", new String[]{"ONE"}); PinyinMapDict dict = new PinyinMapDict() { @Override public Map<String, String[]> mapping() { return map; } }; assertThat(dict.toPinyin("2"), nullValue()); }