Hello all, is there any way to test a `RecyclerVie...
# android
a
Hello all, is there any way to test a
RecyclerView.Adapter
on a local VM? I have mocked some stuff but I'm getting a NPE when
notifyDataSetChanged
gets called
Copy code
java.lang.NullPointerException
	at androidx.recyclerview.widget.RecyclerView$AdapterDataObservable.notifyChanged(RecyclerView.java:11996)
	at androidx.recyclerview.widget.RecyclerView$Adapter.notifyDataSetChanged(RecyclerView.java:7070)
s
http://robolectric.org/ although it’s probably easier to extract the logic to a plain java class that doesn’t have any dependencies on android stuff
a
I want to test diffing and itemCount and stuff which are specific to the adapter
s
oo my itemCount method is usually as simple as
items.size()
although nowadays I tend to use groupie which handles that for you
and allows you to create pure java classes to hold the diffing logic
all to say - it is possible to extract that logic if you don’t want to deal with the headaches of testing w/ android classes
a
You don't use
ListAdapter
then?
Bc
DiffUtil
is heavily coupled with Android fwk
c
DiffUtil is not heavily coupled with android, there's actually only one method that takes an adapter that prevents it from being in an Android-free .jar library. I somewhat regret we didn't move DiffUtil to a separate package with the androidx refactor, to help us eventually move it to a .jar library on its own.
a
Yea, sorry about the "heavily". Theres just that one class which obliges me to use a non-mocked android.jar