on 2018 Mar 01 11:13 AM
I am using hybris 6.2 and trying to write Unit test cases using Mockito. In one scenario I should mock a session cart. Please help how can I mock the same.
Request clarification before answering.
Hi ,
If I understood your problem correctly, then the answer to your question is as follows: Cart is implemented with CartModel class (search in the Javadoc for more information: https://help.hybris.com/6.2.0/api/commercesuite/index.html).
Following this article: https://help.hybris.com/6.6.0/hcd/8c6e8668866910148fc390638f82bad2.html I’ve created an example mock.
//Create mock object
final CartModel mockedCartModel = mock(CartModel.class);
//Mock the method return value
when(mockedCartModel.getDescription()).thenReturn("Mocked description");
//Test the result
assertEquals("The call to getDescription() should've returned 'Mocked description'", "Mocked description", mockedCartModel.getDescription());
If I misunderstood your question, please correct me, and I will take another look at it.
Hope this helps and Best Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the description I have provided is not enough to give the correct answer. Here are the more details. 1. When I call a method like public void doB2BUnitChange(B2BUnit b2bUnit) then It should change the current user B2BUnit. But before changing the B2BUnit it should remove the session cart if is exist. 2. After removing the session cart I should assert the same in test method. But the method return type is void.
Thank you for the reply.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.