Add some test demonstrating null pointer problems in the DateRangeParam class

This commit is contained in:
Heinz-Dieter Conradi 2018-08-01 14:57:34 +02:00
parent dc4c0809a4
commit 734835de96
1 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,67 @@
package ca.uhn.fhir.rest.param;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.QualifiedParamList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;
@RunWith(JUnit4.class)
public class DateRangeParamTest {
private FhirContext fhirContext;
@Before
public void initMockContext() {
fhirContext = Mockito.mock(FhirContext.class);
}
/** Can happen e.g. when the query parameter for {@code _lastUpdated} is left empty. */
@Test
public void testParamWithoutPrefixAndWithoutValue() {
QualifiedParamList qualifiedParamList = new QualifiedParamList(1);
qualifiedParamList.add("");
List<QualifiedParamList> params = new ArrayList<>(1);
params.add(qualifiedParamList);
DateRangeParam dateRangeParam = new DateRangeParam();
dateRangeParam.setValuesAsQueryTokens(fhirContext, "_lastUpdated", params);
assertTrue(dateRangeParam.isEmpty());
}
/** Can happen e.g. when the query parameter for {@code _lastUpdated} is given as {@code lt} without any value. */
@Test
public void testUpperBoundWithPrefixWithoutValue() {
QualifiedParamList qualifiedParamList = new QualifiedParamList(1);
qualifiedParamList.add("lt");
List<QualifiedParamList> params = new ArrayList<>(1);
params.add(qualifiedParamList);
DateRangeParam dateRangeParam = new DateRangeParam();
dateRangeParam.setValuesAsQueryTokens(fhirContext, "_lastUpdated", params);
assertTrue(dateRangeParam.isEmpty());
}
/** Can happen e.g. when the query parameter for {@code _lastUpdated} is given as {@code gt} without any value. */
@Test
public void testLowerBoundWithPrefixWithoutValue() {
QualifiedParamList qualifiedParamList = new QualifiedParamList(1);
qualifiedParamList.add("gt");
List<QualifiedParamList> params = new ArrayList<>(1);
params.add(qualifiedParamList);
DateRangeParam dateRangeParam = new DateRangeParam();
dateRangeParam.setValuesAsQueryTokens(fhirContext, "_lastUpdated", params);
assertTrue(dateRangeParam.isEmpty());
}
}