Note that there are some explanatory texts on larger screens.

plurals
  1. POjmockit capturing mocked method arguments
    primarykey
    data
    text
    <p>I am using JMockit for unit test a data service that calls different web services and populates the database. I am mocking each web service call, and using Expectations/results to feed the service my return data. </p> <p>I am having a problem where I have to iterate over a list of objects and call a web service each time using a different argument. I want to capture the argument so I can feed it into a CreateTestData method that will return what I want. The dataSets are somewhat dependent on each other </p> <p>The test Class:</p> <pre><code>public class testDataService { @Mocked private WebService1 webServiceClientMocked1; @Mocked private WebService2 webServiceClientMocked2; @Autowired private DataService dataService; @Test public void createTestData() { final DataSet1 dataSet1 = CreateMyTestData.createDataSet1(); final DataSet1 dataSet2 = CreateMyTestData.createDataSet2(); // these are populated using other methods not shown final List&lt;String&gt; listStrings = new ArrayList&lt;String&gt;(); final List&lt;String&gt; entities = new ArrayList&lt;String&gt;(); new Expectations() {{ webServiceClientMocked1.getDataSet1("stringA", true); result = dataSet1; }}; new Expectations() {{ webServiceClientMocked2.getDataSet2("stringB"); result = dataSet2; }}; new Expectations() {{ for(String s : listStrings){ webServiceClientMocked1.getDataSet4(s,(List&lt;String&gt;) any); returns(CreateMyTestData.createDataSet4(s, entities)); } }}; //doesnt work //new Expectations() {{ //webServiceClientMocked1.findDataPerParamters(anyString, (List&lt;String&gt;) any ); //result = CreateMyTestData.createDataSet4(capturedString, capturedListStrings); //}}; //call data service to test dataService.doSaveData(); } </code></pre> <p>Data Service class:</p> <pre><code>public class DataServiceImpl implements DataService { public void doSaveData() { //do a bunch of stuff dataSet1 =webServiceClientMocked1.getDataSet1("stringA", true); //do more stuff dataSet2 = webServiceClientMocked2.getDataSet2("stringB"); Collection&lt;Stuff&gt; dataSet3 = saveToDB(dataSet2); //save data and return a different set of data for(Stuff data : dataSet3) { //take dataSet3, iterate over it and call another webservice dataSet4 = webServiceClientMocked1.getDataSet4(data.getStringX(), data.getListStrings()); // keep doing more junk } } </code></pre> <p>Is this possible?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload