Fix test flagged by errorprone

This commit is contained in:
James Agnew 2018-05-30 10:48:53 -04:00
parent 4c655cfa13
commit be1e0df9e2
2 changed files with 149 additions and 244 deletions

View File

@ -30,7 +30,7 @@ public class RoundTripDstu3Test {
} }
// @Test @Test
public void testRoundTrip() throws Exception { public void testRoundTrip() throws Exception {
ZipInputStream is = new ZipInputStream(new FileInputStream("src/test/resources/examples.zip")); ZipInputStream is = new ZipInputStream(new FileInputStream("src/test/resources/examples.zip"));
try { try {

View File

@ -1,280 +1,185 @@
package ca.uhn.fhir.model; package ca.uhn.fhir.model;
import static org.hamcrest.Matchers.endsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.hl7.fhir.instance.model.Address;
import org.hl7.fhir.instance.model.BackboneElement;
import org.hl7.fhir.instance.model.Base;
import org.hl7.fhir.instance.model.Binary;
import org.hl7.fhir.instance.model.BooleanType;
import org.hl7.fhir.instance.model.Bundle;
import org.hl7.fhir.instance.model.CodeType;
import org.hl7.fhir.instance.model.Coding;
import org.hl7.fhir.instance.model.DecimalType;
import org.hl7.fhir.instance.model.DomainResource;
import org.hl7.fhir.instance.model.Element;
import org.hl7.fhir.instance.model.Enumeration;
import org.hl7.fhir.instance.model.Extension;
import org.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.Identifier;
import org.hl7.fhir.instance.model.IntegerType;
import org.hl7.fhir.instance.model.List_;
import org.hl7.fhir.instance.model.Meta;
import org.hl7.fhir.instance.model.Money;
import org.hl7.fhir.instance.model.Narrative;
import org.hl7.fhir.instance.model.Parameters;
import org.hl7.fhir.instance.model.PrimitiveType;
import org.hl7.fhir.instance.model.Quantity;
import org.hl7.fhir.instance.model.Reference;
import org.hl7.fhir.instance.model.Resource;
import org.hl7.fhir.instance.model.StringType;
import org.hl7.fhir.instance.model.Timing;
import org.hl7.fhir.instance.model.Type;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.instance.model.api.IBaseBinary;
import org.hl7.fhir.instance.model.api.IBaseBooleanDatatype;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseCoding;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
import org.hl7.fhir.instance.model.api.IBaseDecimalDatatype;
import org.hl7.fhir.instance.model.api.IBaseEnumeration;
import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
import org.hl7.fhir.instance.model.api.IBaseIntegerDatatype;
import org.hl7.fhir.instance.model.api.IBaseMetaType;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseXhtml;
import org.hl7.fhir.instance.model.api.ICompositeType;
import org.hl7.fhir.instance.model.api.IDomainResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.INarrative;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.Test;
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition; import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition; import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition;
import ca.uhn.fhir.model.api.annotation.Block; import ca.uhn.fhir.model.api.annotation.Block;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.DatatypeDef; import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import org.hl7.fhir.instance.model.*;
import org.hl7.fhir.instance.model.api.*;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.Test;
import static org.hamcrest.Matchers.endsWith;
import static org.junit.Assert.*;
public class ModelInheritanceTest { public class ModelInheritanceTest {
/* /*
* <pre> * <pre>
* Other changes: * Other changes:
* *
* Reference: * Reference:
* * Add "resource" field, plus constructors and getter/setters for that field * * Add "resource" field, plus constructors and getter/setters for that field
* *
* Narrative: * Narrative:
* * Add getValueAsDiv and setValueAsDiv * * Add getValueAsDiv and setValueAsDiv
* *
* XhtmlParser and XhtmlEncoder: * XhtmlParser and XhtmlEncoder:
* * Do we need a better exception declaration? * * Do we need a better exception declaration?
* *
* ElementDefinition * ElementDefinition
* * Backbone elements (eg .ElementDefinitionSlicingComponent) do not extend BackboneElement or have a @Block annotation for some reason * * Backbone elements (eg .ElementDefinitionSlicingComponent) do not extend BackboneElement or have a @Block annotation for some reason
* *
* Extension * Extension
* * Should URL not be StringType since it can't take extensions? * * Should URL not be StringType since it can't take extensions?
* </pre> * </pre>
*/ */
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org(); private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
/**
* Disabled for now...
*/
// @Test
public void testDatatypeNames() {
for (BaseRuntimeElementDefinition<?> next : ourCtx.getElementDefinitions()) {
if (next instanceof BaseRuntimeElementCompositeDefinition || next instanceof RuntimePrimitiveDatatypeDefinition) {
String name = next.getImplementingClass().getName();
// TODO: these are all badly named
if (name.endsWith(".Enumeration")) {
continue;
}
if (name.endsWith(".Reference")) {
continue;
}
if (name.endsWith(".Extension")) {
continue;
}
if (name.endsWith(".Attachment")) {
continue;
}
if (name.endsWith(".Period")) {
continue;
}
if (name.endsWith(".Address")) {
continue;
}
assertThat(name, endsWith("Type"));
}
}
}
@Test
public void testList() {
assertEquals("List", ourCtx.getResourceDefinition(List_.class).getName());
}
/**
* This one should apply to all composite types
*/
@Test
public void testAddress() {
assertTrue(ICompositeType.class.isAssignableFrom(Address.class));
}
@Test /**
public void testXhtml() { * This one should apply to all composite types
assertTrue(IBaseXhtml.class.isAssignableFrom(XhtmlNode.class)); */
} @Test
public void testAddress() {
assertTrue(ICompositeType.class.isAssignableFrom(Address.class));
}
@Test @Test
public void testBackboneElement() { public void testBackboneElement() {
assertTrue(IBaseBackboneElement.class.isAssignableFrom(BackboneElement.class)); assertTrue(IBaseBackboneElement.class.isAssignableFrom(BackboneElement.class));
assertTrue(IBaseHasExtensions.class.isAssignableFrom(BackboneElement.class)); assertTrue(IBaseHasExtensions.class.isAssignableFrom(BackboneElement.class));
assertTrue(IBaseHasModifierExtensions.class.isAssignableFrom(BackboneElement.class)); assertTrue(IBaseHasModifierExtensions.class.isAssignableFrom(BackboneElement.class));
} }
@Test @Test
public void testBase() { public void testBase() {
assertTrue(IBase.class.isAssignableFrom(Base.class)); assertTrue(IBase.class.isAssignableFrom(Base.class));
} }
@Test @Test
public void testProfiledDatatype() { public void testBinary() {
assertEquals(StringType.class, CodeType.class.getSuperclass()); assertTrue(IBaseBinary.class.isAssignableFrom(Binary.class));
assertEquals(StringType.class, CodeType.class.getAnnotation(DatatypeDef.class).profileOf()); }
assertEquals(Quantity.class, Money.class.getSuperclass());
assertEquals(Quantity.class, Money.class.getAnnotation(DatatypeDef.class).profileOf());
}
@Test
public void testBinary() {
assertTrue(IBaseBinary.class.isAssignableFrom(Binary.class));
}
@Test
@Test public void testBooleanType() {
public void testBooleanType() { assertTrue(IBaseBooleanDatatype.class.isAssignableFrom(BooleanType.class));
assertTrue(IBaseBooleanDatatype.class.isAssignableFrom(BooleanType.class)); }
}
@Test
public void testBundle() {
assertTrue(IBaseBundle.class.isAssignableFrom(Bundle.class));
}
@Test @Test
public void testBundle() { public void testCoding() {
assertTrue(IBaseBundle.class.isAssignableFrom(Bundle.class)); assertTrue(IBaseCoding.class.isAssignableFrom(Coding.class));
} }
@Test @Test
public void testCoding() { public void testDecimalType() {
assertTrue(IBaseCoding.class.isAssignableFrom(Coding.class)); assertTrue(IBaseDecimalDatatype.class.isAssignableFrom(DecimalType.class));
} }
@Test @Test
public void testDecimalType() { public void testDomainResource() {
assertTrue(IBaseDecimalDatatype.class.isAssignableFrom(DecimalType.class)); assertTrue(IBaseHasExtensions.class.isAssignableFrom(DomainResource.class));
} assertTrue(IBaseHasModifierExtensions.class.isAssignableFrom(DomainResource.class));
assertTrue(IDomainResource.class.isAssignableFrom(DomainResource.class));
}
@Test @Test
public void testDomainResource() { public void testElement() {
assertTrue(IBaseHasExtensions.class.isAssignableFrom(DomainResource.class)); assertTrue(IBaseHasExtensions.class.isAssignableFrom(Element.class));
assertTrue(IBaseHasModifierExtensions.class.isAssignableFrom(DomainResource.class)); }
assertTrue(IDomainResource.class.isAssignableFrom(DomainResource.class));
}
@Test @Test
public void testElement() { public void testEnumeration() {
assertTrue(IBaseHasExtensions.class.isAssignableFrom(Element.class)); assertTrue(IBaseEnumeration.class.isAssignableFrom(Enumeration.class));
}
@Test DatatypeDef def = Enumeration.class.getAnnotation(DatatypeDef.class);
public void testEnumeration() { assertTrue(def.isSpecialization());
assertTrue(IBaseEnumeration.class.isAssignableFrom(Enumeration.class)); }
DatatypeDef def = Enumeration.class.getAnnotation(DatatypeDef.class);
assertTrue(def.isSpecialization());
}
/** /**
* Should be "implements IBaseExtension<Extension>" * Should be "implements IBaseExtension<Extension>"
*/ */
@Test @Test
public void testExtension() { public void testExtension() {
assertTrue(IBaseExtension.class.isAssignableFrom(Extension.class)); assertTrue(IBaseExtension.class.isAssignableFrom(Extension.class));
assertTrue(IBaseHasExtensions.class.isAssignableFrom(Extension.class)); assertTrue(IBaseHasExtensions.class.isAssignableFrom(Extension.class));
} }
public void testIdentifierUse() throws Exception { @Test
Child child = Identifier.class.getField("use").getAnnotation(Child.class); public void testIdType() {
// assertEquals(IdentifierUseEnumFactory.class, child.enumFactory()); assertTrue(IIdType.class.isAssignableFrom(IdType.class));
} }
public void testIdType() { @Test
assertTrue(IIdType.class.isAssignableFrom(IdType.class)); public void testIntegerType() {
} assertTrue(IBaseIntegerDatatype.class.isAssignableFrom(IntegerType.class));
}
@Test @Test
public void testIntegerType() { public void testList() {
assertTrue(IBaseIntegerDatatype.class.isAssignableFrom(IntegerType.class)); assertEquals("List", ourCtx.getResourceDefinition(List_.class).getName());
} }
@Test @Test
public void testMeta() { public void testMeta() {
assertTrue(IBaseMetaType.class.isAssignableFrom(Meta.class)); assertTrue(IBaseMetaType.class.isAssignableFrom(Meta.class));
} }
@Test @Test
public void testNarrative() { public void testNarrative() {
assertTrue(INarrative.class.isAssignableFrom(Narrative.class)); assertTrue(INarrative.class.isAssignableFrom(Narrative.class));
} }
@Test @Test
public void testPrimitiveType() { public void testParameters() {
assertTrue(IPrimitiveType.class.isAssignableFrom(PrimitiveType.class)); assertTrue(IBaseParameters.class.isAssignableFrom(Parameters.class));
assertTrue(IBaseHasExtensions.class.isAssignableFrom(PrimitiveType.class)); }
}
@Test @Test
public void testReference() { public void testPrimitiveType() {
assertTrue(IBaseReference.class.isAssignableFrom(Reference.class)); assertTrue(IPrimitiveType.class.isAssignableFrom(PrimitiveType.class));
} assertTrue(IBaseHasExtensions.class.isAssignableFrom(PrimitiveType.class));
}
@Test @Test
public void testParameters() { public void testProfiledDatatype() {
assertTrue(IBaseParameters.class.isAssignableFrom(Parameters.class)); assertEquals(StringType.class, CodeType.class.getSuperclass());
} assertEquals(StringType.class, CodeType.class.getAnnotation(DatatypeDef.class).profileOf());
assertEquals(Quantity.class, Money.class.getSuperclass());
assertEquals(Quantity.class, Money.class.getAnnotation(DatatypeDef.class).profileOf());
}
@Test @Test
public void testResource() { public void testReference() {
assertTrue(IAnyResource.class.isAssignableFrom(Resource.class)); assertTrue(IBaseReference.class.isAssignableFrom(Reference.class));
} }
@Test @Test
public void testTiming_TimingRepeatComponent() { public void testResource() {
assertTrue(IBaseDatatypeElement.class.isAssignableFrom(Timing.TimingRepeatComponent.class)); assertTrue(IAnyResource.class.isAssignableFrom(Resource.class));
assertNotNull(Timing.TimingRepeatComponent.class.getAnnotation(Block.class)); }
}
@Test @Test
public void testType() { public void testTiming_TimingRepeatComponent() {
assertTrue(IBaseDatatype.class.isAssignableFrom(Type.class)); assertTrue(IBaseDatatypeElement.class.isAssignableFrom(Timing.TimingRepeatComponent.class));
} assertNotNull(Timing.TimingRepeatComponent.class.getAnnotation(Block.class));
}
@Test
public void testType() {
assertTrue(IBaseDatatype.class.isAssignableFrom(Type.class));
}
@Test
public void testXhtml() {
assertTrue(IBaseXhtml.class.isAssignableFrom(XhtmlNode.class));
}
} }