Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Feb 8, 2024
1 parent 57243b0 commit 43a6826
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public String toString() {
// Print ONLY the values set, not default values
return root.toPrettyString();
}

/**
* Checks if any unknown or invalid properties were encountered while loading the configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ public Boolean asBoolean(boolean defaultValue) {
return ofOptional(BOOLEAN, defaultValue, JsonNode::asBoolean);
}

public Map<String, Boolean> asBooleanMap() {
return ofOptionalMap(BOOLEAN, JsonNode::asBoolean);
}

/** @throws OtpAppException if parameter is missing. */
public double asDouble() {
return ofRequired(DOUBLE).asDouble();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.opentripplanner._support.time.ZoneIds;
import org.opentripplanner.framework.application.OtpAppException;
Expand Down Expand Up @@ -557,6 +558,33 @@ void unusedParams() {
assertEquals("Unexpected config parameter: 'foo.b:false' in 'Test'", buf.toString());
}

@Nested
class Validation {

@Test
void invalidProperties() {
// Given: two parameters a and b
NodeAdapter subject = newNodeAdapterForTest("{ foo : { a: true, b: false } }");

// When: Access ONLY parameter 'a', but not 'b'
subject.of("foo").asObject().of("a").asBoolean();

assertTrue(subject.hasInvalidProperties());
}

@Test
void valid() {
// Given: two parameters a and b
NodeAdapter subject = newNodeAdapterForTest("{ foo : { a: true, b: false } }");

var object = subject.of("foo").asObject();
object.of("a").asBoolean();
object.of("b").asBoolean();

assertFalse(subject.hasInvalidProperties());
}
}

private static String unusedParams(NodeAdapter subject) {
var buf = new StringBuilder();
subject.logAllWarnings(m -> buf.append('\n').append(m));
Expand Down

0 comments on commit 43a6826

Please sign in to comment.