Issue
I want to unit test a UtilsClass-type static method, that returns a Pair<String[], String[]>
. Inside this method I inject a pair of String[] into its constructor, eg. final Pair<String[], String[]> pair = new Pair<>(new String[] {"Hello", "World"}, new String[] {"£33", "£44"});
and expect this object to be returned.
When I unit test this method, I get a non-null Pair object but with its fields first = null
and second = null
. When I run the same test code in a Instrumentation-type test, the fields are populated properly. I can see that in the latter case, the constructor public Pair(F first, S second) {
where I place the debug point is entered and fields set, but not in Unit test.
I am looking for explanation why this would be the case, and if I should avoid passing the String[]
as constructor params in the code in first place.
Solution
As njk2 and TomaszRykala discovered, using android.support.v4.util.Pair instead of android.util.Pair fixes this issue.
Answered By - Patrick Dattilio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.