Merge pull request #1272 from pnewhook/getLink-enum-bug

Bundle.getLink(String) comparing string to enum
This commit is contained in:
Grahame Grieve 2023-05-24 06:15:58 +10:00 committed by GitHub
commit a7026ca51d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 17 deletions

View File

@ -13,7 +13,7 @@
public BundleLinkComponent getLink(String theRelation) { public BundleLinkComponent getLink(String theRelation) {
org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty");
for (BundleLinkComponent next : getLink()) { for (BundleLinkComponent next : getLink()) {
if (theRelation.equals(next.getRelation())) { if (theRelation.equals(next.getRelation().toCode())) {
return next; return next;
} }
} }

View File

@ -5307,7 +5307,7 @@ public class Bundle extends Resource implements IBaseBundle {
public BundleLinkComponent getLink(String theRelation) { public BundleLinkComponent getLink(String theRelation) {
org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty");
for (BundleLinkComponent next : getLink()) { for (BundleLinkComponent next : getLink()) {
if (theRelation.equals(next.getRelation())) { if (theRelation.equals(next.getRelation().toCode())) {
return next; return next;
} }
} }

View File

@ -0,0 +1,31 @@
package org.hl7.fhir.r5.model;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class BundleTypeTest {
@Test
@DisplayName("Test getLink by string when present")
public void getLinkShouldFindWhenPresent() {
Bundle bundle = new Bundle();
Bundle.BundleLinkComponent link = new Bundle.BundleLinkComponent();
link.setRelation(Bundle.LinkRelationTypes.NEXT);
bundle.getLink().add(link);
Bundle.BundleLinkComponent returnedLink = bundle.getLink(IBaseBundle.LINK_NEXT);
Assertions.assertNotNull(returnedLink);
}
@Test
@DisplayName("Test getLink by string when not present")
public void getLinkStringShouldReturnNullWhenNoLinksMatch() {
Bundle bundle = new Bundle();
Bundle.BundleLinkComponent previousLink = new Bundle.BundleLinkComponent();
previousLink.setRelation(Bundle.LinkRelationTypes.PREV);
bundle.getLink().add(previousLink);
Bundle.BundleLinkComponent returnedLink = bundle.getLink(IBaseBundle.LINK_NEXT);
Assertions.assertNull(returnedLink);
}
}