Test the new isEmpty() method on IBundleProvider
This commit is contained in:
parent
1c7c83cd8e
commit
24536941c2
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue