### Question:
CharsetSettingsDefinition implements EnumSettingsDefinition { public String getCharset(Settings settings, String defaultValue) { String cs = settings.getString(CHARSET_SETTING_NAME); if (cs == null) { cs = getDeprecatedEncodingValue(settings); } return (cs != null) ? cs : defaultValue; } private  CharsetSettingsDefinition(); String getCharset(Settings settings, String defaultValue); void setCharset(Settings settings, String charset); @Override int getChoice(Settings settings); @Override void setChoice(Settings settings, int ordinalOfValue); @Override String[] getDisplayChoices(Settings settings); @Override String getName(); @Override String getDescription(); @Override String getDisplayChoice(int ordinalOfValue, Settings s1); @Override void clear(Settings settings); @Override void copySetting(Settings settings, Settings destSettings); @Override boolean hasValue(Settings setting); static void setStaticEncodingMappingValues(Map<Long, List<String>> mappingValues); static final CharsetSettingsDefinition CHARSET; }### Answer:
@Test public void testDeprecatedEncoding() { Settings s = new SettingsBuilder(); s.setLong("language", 1); s.setLong("encoding", 2); String cs = CharsetSettingsDefinition.CHARSET.getCharset(s, null); assertEquals("charset_1_2", cs); }
@Test public void testDeprecatedEncoding_OutOfRangeLanguageId() { Settings s = new SettingsBuilder(); s.setLong("language", 5); s.setLong("encoding", 2); String cs = CharsetSettingsDefinition.CHARSET.getCharset(s, null); assertNull(cs); s.setLong("language", -1); cs = CharsetSettingsDefinition.CHARSET.getCharset(s, null); assertNull(cs); }
@Test public void testDeprecatedEncoding_OutOfRangeEncodingId() { Settings s = new SettingsBuilder(); s.setLong("language", 1); s.setLong("encoding", 20); String cs = CharsetSettingsDefinition.CHARSET.getCharset(s, null); assertNull(cs); s.setLong("encoding", -1); cs = CharsetSettingsDefinition.CHARSET.getCharset(s, null); assertNull(cs); }
@Test public void testCharset() { Settings s = new SettingsBuilder(); s.setString("charset", "expected_charset_value"); String cs = CharsetSettingsDefinition.CHARSET.getCharset(s, null); assertEquals("expected_charset_value", cs); }
@Test public void testCharsetAndDeprecated() { Settings s = new SettingsBuilder(); s.setString("charset", "expected_charset_value"); s.setLong("language", 1); s.setLong("encoding", 2); String cs = CharsetSettingsDefinition.CHARSET.getCharset(s, null); assertEquals("expected_charset_value", cs); }