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