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.
As njk2 and TomaszRykala discovered, using android.support.v4.util.Pair instead of android.util.Pair fixes this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With