I've encountered into a strange situation. Maybe someone has an idea why this can happen.
I've added one argument to the MyActivity
in main_graph.xml - isRecommended
- with a default value (false
):
<activity
android:id="@+id/myActivity"
android:name="com.mydomen.MyActivity"
android:label="MyActivity"
tools:layout="@layout/my_activity">
<argument
android:name="contentItems"
app:argType="com.myActivity"
android:name="com.mydomen.MyItem[]" />
<argument
android:name="myMetadata"
android:defaultValue="@null"
app:argType="com.mydomen.MyMetadata"
app:nullable="true" />
<argument
android:name="isRecommended"
android:defaultValue="false"
app:argType="boolean" />
</activity>
and everything works fine, but one of my unit tests fails - namely, a NullPointerException
is thrown in the test on the line with this verify:
@Test
fun `check onSomeMethodClicked`() {
...
myViewModel.testAction()
verify(exactly = 0) {
navigationObserver.onChanged(
NavigationCommand.To(
MainGraphDirections.actionGlobalMyActivity(
listOf<MyItem>()
)
)
)
}
}
java.lang.NullPointerException
at com.mydomen.MainGraphDirections$ActionGlobalMyActivity.getIsRecommended(MainGraphDirections.java:371)
at com.mydomen.android.MainGraphDirections$ActionGlobalPlayerActivity.hashCode(MainGraphDirections.java:412)
at com.mydomen.android.common.base.navigation.NavigationCommand$To.hashCode(NavigationCommand.kt)
While there is only one actionGlobalMyActivity
method in the generated MainGraphDirections
class:
@NonNull
public static ActionGlobalMyctivity actionGlobalMyActivity(@NonNull MyItem[] myItems) {
return new ActionGlobalMyActivity(myItems);
}
There are no methods that also take in isRecommended
argument. So why is this exception thrown?..