Skip to content

Commit

Permalink
feat: Update LambdaDsl.newJsonArray to allow setting the number of ex…
Browse files Browse the repository at this point in the history
…amples
  • Loading branch information
rholshausen committed Dec 3, 2024
1 parent 19c663c commit 38c0d27
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public static LambdaDslJsonArray newJsonArray(Consumer<LambdaDslJsonArray> array
return dslArray;
}

/**
* DSL function to simplify creating a {@link DslPart} generated from a {@link LambdaDslJsonArray}.
* @param examples Number of examples to populate the array with
*/
public static LambdaDslJsonArray newJsonArray(Integer examples, Consumer<LambdaDslJsonArray> array) {
final PactDslJsonArray pactDslJsonArray = new PactDslJsonArray();
pactDslJsonArray.setNumberExamples(examples);
final LambdaDslJsonArray dslArray = new LambdaDslJsonArray(pactDslJsonArray);
array.accept(dslArray);
return dslArray;
}

/**
* DSL function to simplify creating a {@link DslPart} generated from a {@link LambdaDslJsonArray} where a minimum base array size is specified
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,4 +764,21 @@ public void testUnorderedArrayMatcher() {
assertThat(lambdaPactDsl.getMatchers(), is(pactDslJson.getMatchers()));
}

@Test
public void arrayEachLike() {
// Old DSL
final DslPart pactDslJson = PactDslJsonArray
.arrayEachLike(2)
.stringType("name", "Berlin")
.close();

// Lambda DSL
final DslPart lambdaPactDsl = LambdaDsl.newJsonArray(2, array ->
array.object(obj ->
obj.stringType("name", "Berlin")
)
).build().close();

assertThat(lambdaPactDsl.getBody().toString(), is(pactDslJson.getBody().toString()));
}
}

0 comments on commit 38c0d27

Please sign in to comment.