Skip to content

Commit

Permalink
issue - 44 - Correction related to generating short (#46)
Browse files Browse the repository at this point in the history
* issue - 44 - Correction related to generating short

* Increase version

---------

Co-authored-by: Tiago Simoes <[email protected]>
Co-authored-by: Alejandro Pena Lorenzo <[email protected]>
Co-authored-by: Alejandro Pena Lorenzo <[email protected]>
  • Loading branch information
4 people authored Nov 28, 2023
1 parent a931125 commit ca78d43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>pact-annotation-processor</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>

<name>PactDslBuilder - Annotation Processor</name>
<description>Pact DSL Builder annotation processor.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final String getFieldType() {

@Override
public final String getFunctionType() {
return "shortType";
return "integerType";
}

@Override
Expand All @@ -36,12 +36,15 @@ public final String getFunctionOnlyValue() {
public final Integer getRandomDefaultValue(final FieldValidations fieldValidations) {
final int randomDefaultValue;
if (Objects.nonNull(fieldValidations) && ObjectUtils.anyNotNull(fieldValidations.getMin(), fieldValidations.getMax())) {
final int minValue = ObjectUtils.defaultIfNull(fieldValidations.getMin(), (int) Byte.MIN_VALUE);
final int maxValue = ObjectUtils.defaultIfNull(fieldValidations.getMax(), (int) Byte.MAX_VALUE);
int minValue = ObjectUtils.defaultIfNull(fieldValidations.getMin(), (int) Short.MIN_VALUE);
minValue = minValue < Short.MIN_VALUE ? minValue : Short.MIN_VALUE;

int maxValue = ObjectUtils.defaultIfNull(fieldValidations.getMax(), (int) Short.MAX_VALUE);
maxValue = maxValue > Short.MAX_VALUE ? maxValue : Short.MAX_VALUE;

randomDefaultValue = uniformRandomProvider.nextInt(minValue, maxValue);
} else {
randomDefaultValue = uniformRandomProvider.nextInt(0, Integer.MAX_VALUE);
randomDefaultValue = uniformRandomProvider.nextInt(Short.MIN_VALUE, Short.MAX_VALUE);
}

return randomDefaultValue;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/templateDslBuilder.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
<#else>
pactDslJsonBody.${field.functionByType}("${field.name}", "${field.formatValue?no_esc}", ${field.name}.toInstant());
</#if>
<#elseif field.fieldType == "short">
pactDslJsonBody.${field.functionByType}("${field.name}", (int) ${field.name});
<#elseif field.fieldType == "BigInteger">
pactDslJsonBody.${field.functionByType}("${field.name}", ${field.name}.intValue());
<#else>
Expand Down

0 comments on commit ca78d43

Please sign in to comment.