diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java index e8d693a4a61..1f5e48ca9f9 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java @@ -30,13 +30,16 @@ import ca.uhn.fhir.model.base.resource.BaseOperationOutcome; */ public class ValidationResult { private BaseOperationOutcome myOperationOutcome; + private boolean isSuccessful; - private ValidationResult(BaseOperationOutcome myOperationOutcome) { + private ValidationResult(BaseOperationOutcome myOperationOutcome, boolean isSuccessful) { this.myOperationOutcome = myOperationOutcome; + this.isSuccessful = isSuccessful; } public static ValidationResult valueOf(BaseOperationOutcome myOperationOutcome) { - return new ValidationResult(myOperationOutcome); + boolean noIssues = myOperationOutcome == null || myOperationOutcome.getIssue().isEmpty(); + return new ValidationResult(myOperationOutcome, noIssues); } public BaseOperationOutcome getOperationOutcome() { @@ -47,6 +50,7 @@ public class ValidationResult { public String toString() { return "ValidationResult{" + "myOperationOutcome=" + myOperationOutcome + + ", isSuccessful=" + isSuccessful + ", description='" + toDescription() + '\'' + '}'; } @@ -67,6 +71,6 @@ public class ValidationResult { * @return true if the validation was successful */ public boolean isSuccessful() { - return myOperationOutcome == null || myOperationOutcome.getIssue().isEmpty(); + return isSuccessful; } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java index d59cc768d1b..ab2b62d4493 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java @@ -1,18 +1,19 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.*; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - +import ca.uhn.fhir.model.api.TemporalPrecisionEnum; +import ca.uhn.fhir.parser.DataFormatException; import org.apache.commons.lang3.time.FastDateFormat; import org.junit.Before; import org.junit.Test; -import ca.uhn.fhir.model.api.TemporalPrecisionEnum; -import ca.uhn.fhir.parser.DataFormatException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class BaseDateTimeDtTest { private SimpleDateFormat myDateInstantParser; @@ -39,7 +40,7 @@ public class BaseDateTimeDtTest { Date instant = myDateInstantParser.parse("2001-02-03 13:01:02.555"); for (FastDateFormat next : BaseDateTimeDt.getFormatters()) { - GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("EST")); + Calendar cal = Calendar.getInstance(); cal.setTime(instant); String value = next.format(cal); ourLog.info("String: {}", value); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java index b4f2a2fa503..051bbde3e32 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java @@ -2,7 +2,6 @@ package ca.uhn.fhir.validation; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue; import ca.uhn.fhir.model.dstu.resource.OperationOutcome; - import org.junit.Test; import java.util.List; @@ -45,4 +44,17 @@ public class ValidationResultTest { assertThat("ValidationResult#toString should contain the issue description", result.toString(), containsString(errorMessage)); } -} \ No newline at end of file + + /* + Test for https://github.com/jamesagnew/hapi-fhir/issues/51 + */ + @Test + public void toString_ShouldNotCauseResultToBecomeFailure() { + OperationOutcome operationOutcome = new OperationOutcome(); + ValidationResult result = ValidationResult.valueOf(operationOutcome); + assertEquals(true, result.isSuccessful()); + // need to call toString to make sure any unwanted side effects are generated + @SuppressWarnings("UnusedDeclaration") String unused = result.toString(); + assertEquals(true, result.isSuccessful()); + } +}