I have got into a situation where I am stubbing through when-then to match a list but I am getting error most of the times due to ordering issue.
List<String> myListToMatch = new ArrayList<String>();
myListToMatch .add("1");
myListToMatch .add("2");
when(obj.methodName(eq(myListToMatch))).thenReturn("someStringValue");
Due to ordering as in the called method the list go as ["2","1"] which is not returning "someStringValue" as per the above stubbing which is affecting my test case. Any help is appreciated. I am using Mockito library. I dont have any hamcrest dependency(dont want to add any).
I tried sorting in the code and it works but I dont want to update my code if there is way or some kind of argument matcher which I can use in when-then stubbing.