ConfigParser { public static void validateConfig(final Properties config, final String[] requiredStrings, final String[] requiredBooleans, final String[] requiredIntegers, final String[] requiredLongs) throws ExitException { for (final String param : requiredStrings) { parseString(config, param); } for (final String param : requiredBooleans) { parseBoolean(config, param); } for (final String param : requiredIntegers) { parseInteger(config, param); } for (final String param : requiredLongs) { parseLong(config, param); } } private  ConfigParser(); static void checkParamExists(final Properties properties, final String param); static boolean parseBoolean(final Properties properties, final String param); static boolean parseBoolean(final Properties properties, final String param, final Boolean defaultValue); static int parseInteger(final Properties properties, final String param); static int parseInteger(final Properties properties, final String param, final Integer defaultValue); static long parseLong(final Properties properties, final String param); static long parseLong(final Properties properties, final String param, final Long defaultValue); static String parseString(final Properties properties, final String param); static String parseString(final Properties properties, final String param, final String defaultValue); static void validateBooleanParam(final String val); static void validateConfig(final Properties config, final String[] requiredStrings,
        final String[] requiredBooleans, final String[] requiredIntegers, final String[] requiredLongs); static void validateIntegerParam(final String val); static void validateLongParam(final String val);  }
@Test public void testValidateConfig() { try { final Properties properties = new Properties(); final String requiredStrings[] = {"p1", "p2", "p3"}; final String requiredBooleans[] = {"p4", "p5", "p6"}; final String requiredIntegers[] = {"p7", "p8", "p9"}; final String requiredLongs[] = {"p10", "p11", "p12"}; for (final String param : requiredStrings) { properties.put(param, STRING_TEST_VALUE); } for (final String param : requiredBooleans) { properties.put(param, BOOLEAN_TEST_VALUE); } for (final String param : requiredIntegers) { properties.put(param, INT_TEST_VALUE); } for (final String param : requiredLongs) { properties.put(param, LONG_TEST_VALUE); } ConfigParser.validateConfig(properties, requiredStrings, requiredBooleans, requiredIntegers, requiredLongs); } catch (final ExitException e) { fail(); } }
@Test(expected = ExitException.class) public void testValidateConfigMissingBoolean() throws ExitException { final Properties properties = new Properties(); final String requiredStrings[] = {}; final String requiredBooleans[] = {"p1", "p2", "p3"}; final String requiredIntegers[] = {}; final String requiredLongs[] = {}; properties.put("p1", BOOLEAN_TEST_VALUE); properties.put("p3", BOOLEAN_TEST_VALUE); ConfigParser.validateConfig(properties, requiredStrings, requiredBooleans, requiredIntegers, requiredLongs); }
@Test(expected = ExitException.class) public void testValidateConfigMissingInteger() throws ExitException { final Properties properties = new Properties(); final String requiredStrings[] = {}; final String requiredBooleans[] = {}; final String requiredIntegers[] = {"p1", "p2", "p3"}; final String requiredLongs[] = {}; properties.put("p1", LONG_TEST_VALUE); properties.put("p3", LONG_TEST_VALUE); ConfigParser.validateConfig(properties, requiredStrings, requiredBooleans, requiredIntegers, requiredLongs); }
@Test(expected = ExitException.class) public void testValidateConfigMissingLong() throws ExitException { final Properties properties = new Properties(); final String requiredStrings[] = {}; final String requiredBooleans[] = {}; final String requiredIntegers[] = {}; final String requiredLongs[] = {"p1", "p2", "p3"}; properties.put("p1", "9e18"); properties.put("p3", "9e18"); ConfigParser.validateConfig(properties, requiredStrings, requiredBooleans, requiredIntegers, requiredLongs); }
@Test(expected = ExitException.class) public void testValidateConfigMissingString() throws ExitException { final Properties properties = new Properties(); final String requiredStrings[] = {"p1", "p2", "p3"}; final String requiredBooleans[] = {}; final String requiredIntegers[] = {}; final String requiredLongs[] = {}; properties.put("p1", STRING_TEST_VALUE); properties.put("p3", STRING_TEST_VALUE); ConfigParser.validateConfig(properties, requiredStrings, requiredBooleans, requiredIntegers, requiredLongs); }