I have implemented a method getUsers()
, which basically construct a List<ShoppingCart>
, then create a List<User>
:
public List<User> getUsers() {
// construct a liste of List<ShoppingCart>
....
// update
...
}
The construction of List<ShoppingCart>
contains a lot of logic, so I decided to move those code out and create a private method:
public List<User> getUsers() {
// construct a liste of List<ShoppingCart>
List<ShoppingCart> shoppingList = getShoppingList();
// update
...
}
private List<ShoppingCart> getShoppingList() {
...
}
Now I need to unit test getUsers()
. But I realized that I have difficulty to get the List<ShoppingCart>
because it's a private method.
And I don't want to make getShoppingList()
public because I don't need it anywhere else.
I think there is a design problem in my code, what is the best way to unit test these kinds of methods containing returned value of private methods ?
Thanks.
UPDATE
No it's not the same question as Java test class with many private methods, my question is not if it's necessary to test private method, but what should be a better design