NonEmptyValueValidation implements Validation { @Override public ValidationResult validate(Config config) { try { config.getAnyRef(path); } catch (ConfigException.Null e) { return new ValidationResult(this, Validity.INVALID, "Configuration '" + path + "' is null but must be non-empty"); } catch (Exception e) { } if (config.hasPath(path)) { if (config.getValue(path).valueType() == ConfigValueType.STRING && config.getString(path).isEmpty()) { return new ValidationResult(this, Validity.INVALID, "Configuration '" + path + "' is an empty string but must be non-empty"); } else if (config.getValue(path).valueType() == ConfigValueType.LIST && config.getAnyRefList(path).size() == 0) { return new ValidationResult(this, Validity.INVALID, "Configuration '" + path + "' is an empty list but must be non-empty"); } else { return new ValidationResult(this, Validity.VALID, "Configuration '" + path + "' is non-empty"); } } else { return new ValidationResult(this, Validity.VALID, "Configuration '" + path + "' does not exist so not checking if non-empty"); } } NonEmptyValueValidation(String path); @Override ValidationResult validate(Config config); @Override String toString(); @Override Set<String> getKnownPaths();  }
@Test public void testNotEmptyString() { Validation v = new NonEmptyValueValidation("hello"); ValidationResult vr = v.validate(ConfigFactory.parseString("hello = \"world\"")); assertEquals(vr.getValidity(), Validity.VALID); }
@Test public void testEmptyString() { Validation v = new NonEmptyValueValidation("hello"); ValidationResult vr = v.validate(ConfigFactory.parseString("hello = \"\"")); assertEquals(vr.getValidity(), Validity.INVALID); }
@Test public void testNotEmptyList() { Validation v = new NonEmptyValueValidation("test"); ValidationResult vr = v.validate(ConfigFactory.parseString("test = [\"hello\", \"world\"]")); assertEquals(vr.getValidity(), Validity.VALID); }
@Test public void testEmptyList() { Validation v = new NonEmptyValueValidation("test"); ValidationResult vr = v.validate(ConfigFactory.parseString("test = []")); assertEquals(vr.getValidity(), Validity.INVALID); }
@Test public void testNull() { Validation v = new NonEmptyValueValidation("test"); ValidationResult vr = v.validate(ConfigFactory.parseString("test = null")); assertEquals(vr.getValidity(), Validity.INVALID); }
@Test public void testPathDoesntExist() { Validation v = new NonEmptyValueValidation("test"); ValidationResult vr = v.validate(ConfigFactory.parseString("hello = \"world\"")); assertEquals(vr.getValidity(), Validity.VALID); }