Skip to content

Commit

Permalink
Introduces PrimitiveTestSuite protos that encapsulate all the testdat…
Browse files Browse the repository at this point in the history
…a currently in individual wrapper tests, as well as .{invalid|valid}.{ndjson|prototxt} files that do weird stuff like dash-delimited prototxt.

Replaces existing java primitive tests with unified PrimitiveWrapperTest that uses these suites.  Follow-up changes will reuse these protos in other languages.

Minor bug fix to decimal wrapper: Validating a proto with scientific notation would not check the bounds, so things like "10E+500" would be valid despite being beyond the bounds of a double.

PiperOrigin-RevId: 356774567
  • Loading branch information
nickgeorge committed Feb 16, 2021
1 parent ca89728 commit fa1526c
Show file tree
Hide file tree
Showing 38 changed files with 960 additions and 1,418 deletions.
16 changes: 0 additions & 16 deletions java/com/google/fhir/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,3 @@ java_library(
"@maven//:junit_junit",
],
)

java_library(
name = "validation_test_base",
testonly = 1,
srcs = ["ValidationTestBase.java"],
deps = [
"//java/com/google/fhir/common:exceptions",
"//java/com/google/fhir/common:json_format",
"//java/com/google/fhir/wrappers:primitive_wrappers",
"@bazel_tools//tools/java/runfiles",
"@com_google_protobuf//:protobuf_java",
"@maven//:com_google_guava_guava",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
],
)
161 changes: 0 additions & 161 deletions java/com/google/fhir/testing/ValidationTestBase.java

This file was deleted.

13 changes: 13 additions & 0 deletions java/com/google/fhir/wrappers/DecimalWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public DecimalWrapper(String input) {
super(input == null ? NULL_DECIMAL : parseAndValidate(input));
}

// TODO: This should throw a checked InvalidFhirException.
private static void validate(String input) {
try {
// We don't use Double.parseDouble() here because that function simply
Expand All @@ -63,6 +64,18 @@ private static void validate(String input) {
}
}

/** Override to also check that the string is within double bounds. */
// TODO: This should throw a checked InvalidFhirException.
@Override
public void validateWrapped() {
if (hasValue()) {
validateUsingPattern(getPattern(), printValue());
validate(printValue());
} else {
validatePrimitiveWithoutValue();
}
}

private static Decimal parseAndValidate(String input) {
validateUsingPattern(REGEX_PATTERN, input);
validate(input);
Expand Down
20 changes: 0 additions & 20 deletions javatests/com/google/fhir/r4/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,3 @@ java_test(
"@maven//:junit_junit",
],
)

java_test(
name = "ValidationR4Test",
size = "medium",
srcs = ["ValidationTest.java"],
data = [
"//testdata/r4:validation",
],
test_class = "com.google.fhir.r4.ValidationTest",
deps = [
"//java/com/google/fhir/common:json_format",
"//java/com/google/fhir/testing:validation_test_base",
"//proto/google/fhir/proto/r4:fhirproto_extensions_java_proto",
"//proto/google/fhir/proto/r4:uscore_java_proto",
"//proto/google/fhir/proto/r4/core:datatypes_java_proto",
"@bazel_tools//tools/java/runfiles",
"@com_google_protobuf//:protobuf_java",
"@maven//:junit_junit",
],
)
Loading

0 comments on commit fa1526c

Please sign in to comment.