IniReader { public String getString(String key, String defaultValue) { Optional<String> stringOptional = Optional.ofNullable(values.get(key)); return stringOptional.orElse(defaultValue); } IniReader(String fileName, SolFileReader reader);  IniReader(BufferedReader reader); static void write(String fileName, Object... keysVals); String getString(String key, String defaultValue); int getInt(String key, int defaultValue); boolean getBoolean(String key, boolean defaultValue); float getFloat(String key, float defaultValue);  }
@Test public void testInputHandling() { assertEquals("correctValue", iniReader.getString("missingKey", "correctValue")); assertEquals("terrible key value", iniReader.getString("terrible key name", "wrongValue")); assertEquals("correctValue1", iniReader.getString("partLineCommentKey", "wrongValue")); assertEquals("validValue2", iniReader.getString("doubleRequestedKey", "wrongValue")); assertEquals("validValue2", iniReader.getString("doubleRequestedKey", "wrongValue")); assertEquals("correctValue", iniReader.getString("this shouldn't throw exception", "correctValue")); assertEquals("unicodevalue áśǵj́ḱĺóí⋄«»⋄⋄ǫő", iniReader.getString("UnicodeKey çáč🧝", "wrongValue")); }
@Test public void testGetString() { assertEquals("correctValue", iniReader.getString("asdfghjk", "correctValue")); assertEquals("validString", iniReader.getString("validStringKey", "wrongValue")); }
@Test public void testEnums() { assertEquals(GameOptions.ControlType.MIXED, Enums.getIfPresent(GameOptions.ControlType.class, iniReader.getString("enumDefault", "MIXED")).or(GameOptions.ControlType.KEYBOARD)); assertEquals(GameOptions.ControlType.MIXED, Enums.getIfPresent(GameOptions.ControlType.class, iniReader.getString("enumDefault", "MIXED")).or(GameOptions.ControlType.MIXED)); assertEquals(GameOptions.ControlType.KEYBOARD, Enums.getIfPresent(GameOptions.ControlType.class, iniReader.getString("enumEmpty", "KEYBOARD")).or(GameOptions.ControlType.MIXED)); assertEquals(GameOptions.ControlType.MIXED, Enums.getIfPresent(GameOptions.ControlType.class, iniReader.getString("enumInvalid", "KEYBOARD")).or(GameOptions.ControlType.MIXED)); assertEquals(GameOptions.ControlType.MIXED, Enums.getIfPresent(GameOptions.ControlType.class, iniReader.getString("enumInvalid", "MIXED")).or(GameOptions.ControlType.MIXED)); assertEquals(GameOptions.ControlType.KEYBOARD, Enums.getIfPresent(GameOptions.ControlType.class, iniReader.getString("enumValid", "MIXED")).or(GameOptions.ControlType.MIXED)); }