Avoid NPE in RequestPartitionId on Default Partition (#2382)
This commit is contained in:
parent
aaa91616aa
commit
b247e8cde7
|
@ -161,7 +161,10 @@ public class RequestPartitionId {
|
|||
* Returns true if this request partition contains only one partition ID and it is the DEFAULT partition ID (null)
|
||||
*/
|
||||
public boolean isDefaultPartition() {
|
||||
return getPartitionIds().size() == 1 && getPartitionIds().get(0) == null;
|
||||
if (isAllPartitions()) {
|
||||
return false;
|
||||
}
|
||||
return hasPartitionIds() && getPartitionIds().size() == 1 && getPartitionIds().get(0) == null;
|
||||
}
|
||||
|
||||
public boolean hasPartitionId(Integer thePartitionId) {
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package ca.uhn.fhir.interceptor.model;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class RequestPartitionIdTest {
|
||||
|
||||
|
@ -21,5 +24,17 @@ public class RequestPartitionIdTest {
|
|||
assertNotEquals(RequestPartitionId.fromPartitionId(123, LocalDate.of(2020, 1, 1)), "123");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartition() {
|
||||
assertFalse(RequestPartitionId.allPartitions().isDefaultPartition());
|
||||
assertFalse(RequestPartitionId.defaultPartition().isAllPartitions());
|
||||
assertTrue(RequestPartitionId.defaultPartition().isDefaultPartition());
|
||||
assertTrue(RequestPartitionId.allPartitions().isAllPartitions());
|
||||
assertFalse(RequestPartitionId.forPartitionIdsAndNames(Lists.newArrayList("Name1", "Name2"), null, null).isAllPartitions());
|
||||
assertFalse(RequestPartitionId.forPartitionIdsAndNames(Lists.newArrayList("Name1", "Name2"), null, null).isDefaultPartition());
|
||||
assertFalse(RequestPartitionId.forPartitionIdsAndNames(null, Lists.newArrayList(1, 2), null).isAllPartitions());
|
||||
assertFalse(RequestPartitionId.forPartitionIdsAndNames(null, Lists.newArrayList(1, 2), null).isDefaultPartition());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue