Fix #394 - Don't use a method from Commons-Lang3 3.3

This commit is contained in:
jamesagnew 2016-06-27 06:19:22 -04:00
parent 40a65fb2cc
commit c28a2c40f0
6 changed files with 69 additions and 5 deletions

View File

@ -30,6 +30,7 @@ import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.util.ValidateUtil;
public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChildDefinition {
private final IAccessor myAccessor;
@ -46,7 +47,7 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
BaseRuntimeDeclaredChildDefinition(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName) throws ConfigurationException {
super();
Validate.notNull(theField, "No field speficied");
Validate.inclusiveBetween(0, Integer.MAX_VALUE, theChildAnnotation.min(), "Min must be >= 0");
ValidateUtil.isGreaterThanOrEqualTo(theChildAnnotation.min(), 0, "Min must be >= 0");
Validate.isTrue(theChildAnnotation.max() == -1 || theChildAnnotation.max() >= theChildAnnotation.min(), "Max must be >= Min (unless it is -1 / unlimited)");
Validate.notBlank(theElementName, "Element name must not be blank");

View File

@ -26,7 +26,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
@ -41,6 +40,7 @@ import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.method.QualifiedParamList;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.util.ValidateUtil;
@SuppressWarnings("deprecation")
public class DateParam extends BaseParamWithPrefix<DateParam> implements IQueryParameterType , IQueryParameterOr<DateParam> {
@ -81,7 +81,7 @@ public class DateParam extends BaseParamWithPrefix<DateParam> implements IQueryP
* Constructor
*/
public DateParam(ParamPrefixEnum thePrefix, long theDate) {
Validate.inclusiveBetween(1, Long.MAX_VALUE, theDate, "theDate must not be 0 or negative");
ValidateUtil.isGreaterThan(theDate, 0, "theDate must not be 0 or negative");
setPrefix(thePrefix);
setValue(new Date(theDate));
}
@ -138,7 +138,7 @@ public class DateParam extends BaseParamWithPrefix<DateParam> implements IQueryP
*/
@Deprecated
public DateParam(QuantityCompararatorEnum theComparator, long theDate) {
Validate.inclusiveBetween(1, Long.MAX_VALUE, theDate, "theDate must not be 0 or negative");
ValidateUtil.isGreaterThan(theDate, 0, "theDate must not be 0 or negative");
setPrefix(toPrefix(theComparator));
setValue(new Date(theDate));
}

View File

@ -38,4 +38,22 @@ public class ValidateUtil {
}
}
/**
* Throws {@link IllegalArgumentException} if theValue is <= theMinimum
*/
public static void isGreaterThan(long theValue, long theMinimum, String theMessage) {
if (theValue <= theMinimum) {
throw new IllegalArgumentException(theMessage);
}
}
/**
* Throws {@link IllegalArgumentException} if theValue is <= theMinimum
*/
public static void isGreaterThanOrEqualTo(long theValue, long theMinimum, String theMessage) {
if (theValue < theMinimum) {
throw new IllegalArgumentException(theMessage);
}
}
}

View File

@ -21,6 +21,28 @@ public class ValidateUtilTest {
}
}
@Test
public void testIsGreaterThan() {
ValidateUtil.isGreaterThan(2L, 1L, "");
try {
ValidateUtil.isGreaterThan(1L, 1L, "The message");
fail();
} catch (IllegalArgumentException e) {
assertEquals("The message", e.getMessage());
}
}
@Test
public void testIsGreaterThanOrEqualTo() {
ValidateUtil.isGreaterThanOrEqualTo(1L, 1L, "");
try {
ValidateUtil.isGreaterThanOrEqualTo(0L, 1L, "The message");
fail();
} catch (IllegalArgumentException e) {
assertEquals("The message", e.getMessage());
}
}
@Test
public void testIsNotBlank() {
ValidateUtil.isNotBlankOrThrowInvalidRequest("aa", "");

View File

@ -1,17 +1,35 @@
package ca.uhn.fhir.rest.param;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import java.util.Date;
import java.util.TimeZone;
import org.junit.Test;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.InstantDt;
public class DateParamTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateParamTest.class);
@SuppressWarnings("deprecation")
@Test
public void testConstructors() {
new DateParam();
new DateParam("2011-01-02");
new DateParam(ParamPrefixEnum.GREATERTHAN,new Date());
new DateParam(ParamPrefixEnum.GREATERTHAN,new DateTimeDt("2011-01-02"));
new DateParam(ParamPrefixEnum.GREATERTHAN,InstantDt.withCurrentTime());
new DateParam(ParamPrefixEnum.GREATERTHAN,"2011-01-02");
new DateParam(QuantityCompararatorEnum.GREATERTHAN,new Date());
new DateParam(QuantityCompararatorEnum.GREATERTHAN,new DateTimeDt("2011-01-02"));
new DateParam(QuantityCompararatorEnum.GREATERTHAN,InstantDt.withCurrentTime());
new DateParam(QuantityCompararatorEnum.GREATERTHAN,"2011-01-02");
}
@Test
public void testParse() {
Date date = new Date();

View File

@ -386,6 +386,11 @@
create a BigDecimal from a double, resulting in weird floating point
conversions. Thanks to Craig McClendon for reporting!
</action>
<action type="fix" issue="394">
Remove the depdendency on a method from commons-lang3 3.3 which was
causing issues on some Android phones which come with an older version
of this library bundled. Thanks to Paolo Perliti for reporting!
</action>
</release>
<release version="1.5" date="2016-04-20">
<action type="fix" issue="339">