Test the new isEmpty() method on IBundleProvider

This commit is contained in:
James Agnew 2019-07-05 17:15:02 -04:00
parent 1c7c83cd8e
commit 24536941c2
2 changed files with 43 additions and 1 deletions

View File

@ -158,7 +158,7 @@ public interface IBundleProvider {
default boolean isEmpty() {
Integer size = size();
if (size != null) {
return size > 0;
return size == 0;
}
return getResources(0, 1).isEmpty();
}

View File

@ -0,0 +1,42 @@
package ca.uhn.fhir.rest.api.server;
import ca.uhn.fhir.rest.server.SimpleBundleProvider;
import com.google.common.collect.Lists;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
public class IBundleProviderTest {
@Test
public void testIsEmptyDefaultMethod_SizePopulated() {
SimpleBundleProvider provider = new SimpleBundleProvider();
assertTrue(provider.isEmpty());
provider = new SimpleBundleProvider(Lists.newArrayList(mock(IBaseResource.class)));
assertFalse(provider.isEmpty());
}
@Test
public void testIsEmptyDefaultMethod_SizeReturnsNull() {
SimpleBundleProvider provider = new SimpleBundleProvider() {
@Override
public Integer size() {
return null;
}
};
assertTrue(provider.isEmpty());
provider = new SimpleBundleProvider(Lists.newArrayList(mock(IBaseResource.class))) {
@Override
public Integer size() {
return null;
}
};
assertFalse(provider.isEmpty());
}
}