Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.util.Pair holds String[] as parameters in androidTest but null in (unit) test

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.

like image 981
TomaszRykala Avatar asked Nov 03 '15 15:11

TomaszRykala


1 Answers

As njk2 and TomaszRykala discovered, using android.support.v4.util.Pair instead of android.util.Pair fixes this issue.

like image 97
Patrick Dattilio Avatar answered Nov 15 '22 20:11

Patrick Dattilio