squaretest

Open full view…

union of 2 Lists

ls67
Tue, 07 Apr 2020 18:58:07 GMT

Exists a way to compute the union of 2 lists compared by a property of the elements. I would need a list of the parameters of the method under test and all methods of the mocks which this method needs.

ls67
Tue, 07 Apr 2020 18:59:20 GMT

Sorry, more corrcet I would need the set of these parameters.

nate-squaretest
Thu, 09 Jul 2020 13:53:03 GMT

Sorry for the delayed response. I added FluentList.union(...) APIs in update 1.5.4 (released today). The APIs are described on https://squaretest.com/#template_api_fluent_list. You can add the following code to the #renderTestMethod(...) macro after the "// Setup" comment in order to retrieve the set of variables used in the source method arguments or the dependency interaction method arguments. --- #set($macro.mockedDIs = $method.dependencyInteractions.satisfiedBy($dependencies.filter('shoul dBeMocked'))) #set($macro.variablesToDeclare = $method.parameters.filter('shouldStoreInReference', true)) #foreach($di in $macro.mockedDIs) #set($macro.variablesToDeclare = $macro.variablesToDeclare.union($di.method.parameters, 'type.canonicalName')) #end #foreach($param in $macro.variablesToDeclare) #declareAndInitLocalVar($param, true) #end --- You would need to add some logic here or in other places in the template to make this work as expected. The exact changes depend on which variables you want to store as local variables.