Skip to content

Commit

Permalink
Adding buildExpectedInstance to dsl builder template (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
apenlor authored Nov 21, 2023
1 parent cb3c0a3 commit c74db2e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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.0.4</version>
<version>1.1.4</version>

<name>PactDslBuilder - Annotation Processor</name>
<description>Pact DSL Builder annotation processor.</description>
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/templates/templateDslBuilder.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
}
</#macro>

<#macro writeExpectedInstanceSetters field>
<#if field.fieldType == "char">
object.set${field.name?cap_first}(this.${field.name}.charAt(0));
<#else>
object.set${field.name?cap_first}(this.${field.name});
</#if>
</#macro>

<#function writeDefaultsList fieldList>
<#list fieldList as internalField>
${writeRightValue(internalField.defaultValue, internalField.functionByType, internalField.format)}<#if internalField?is_last>, </#if>
Expand Down Expand Up @@ -228,6 +236,8 @@ import java.time.Instant;
import java.util.Date;
import java.util.List;

import ${schema.modelPackage}.${schema.className};

<#function complex(field)>
<#return field.functionByType??>
</#function>
Expand Down Expand Up @@ -264,6 +274,14 @@ public class ${schema.className}Builder {
return pactDslJsonBody;
}

public ${schema.className} buildExpectedInstance() {
${schema.className} object = new ${schema.className}();
<#list schema.fieldList as field>
<@writeExpectedInstanceSetters field=field/>
</#list>
return object;
}

<#if schema.customModifiers??>
private static void applyCustomModifiers(PactDslJsonBody pactDslJsonBody) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
<#list schema.customModifiers as customMod>
Expand Down

0 comments on commit c74db2e

Please sign in to comment.