Получение этой ошибки при запуске тестового примера для проверки репозитория в MVVM - PullRequest
0 голосов
/ 18 октября 2018
@RunWith(JUnit4::class)
    class RepositoryTest {
        private lateinit var repository: Repository
        private val service = mock(RetrofitService::class.java)

        @get:Rule
        val instantExecutorRule = InstantTaskExecutorRule()

        @Before
        fun init() {
            repository = Repository(service, InstantAppExecutor())
        }

        @Test
        fun submitFeedbackTest() {
            val feedback = Feedback()
            feedback.feedback = "Nice App"
            val response = Response()
            response.isSuccess = true
            val call = successCall(response)
            `when`(service.submitFeedback(feedback)).thenReturn(call)

            val data = repository.submitFeedback(feedback.feedback)

            val observer = package.util.mock<Observer<Resource<Boolean>>>()
            data.observeForever(observer)
            verifyNoMoreInteractions(service)
            verify(observer).onChanged(Resource.loading(null))
            verify(service).submitFeedback(feedback)

            verify(observer).onChanged(Resource.success(response.isSuccess))
        }
    }

java.lang.NullPointerException
    at android.arch.lifecycle.MediatorLiveData$Source.plug(MediatorLiveData.java:141)
    at android.arch.lifecycle.MediatorLiveData.addSource(MediatorLiveData.java:96)
    at package.repository.NetworkBoundResource.fetchFromNetwork(NetworkBoundResource.java:70)
    at package.repository.NetworkBoundResource.lambda$new$1(NetworkBoundResource.java:59)
    at android.arch.lifecycle.MediatorLiveData$Source.onChanged(MediatorLiveData.java:152)
    at android.arch.lifecycle.LiveData.considerNotify(LiveData.java:109)
    at android.arch.lifecycle.LiveData.dispatchingValue(LiveData.java:126)
    at android.arch.lifecycle.LiveData.setValue(LiveData.java:282)
    at android.arch.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33)
    at android.arch.lifecycle.Transformations$1.onChanged(Transformations.java:70)
    at android.arch.lifecycle.MediatorLiveData$Source.onChanged(MediatorLiveData.java:152)
    at android.arch.lifecycle.LiveData.considerNotify(LiveData.java:109)
    at android.arch.lifecycle.LiveData.dispatchingValue(LiveData.java:121)
    at android.arch.lifecycle.LiveData.access$400(LiveData.java:59)
    at android.arch.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:416)
    at android.arch.lifecycle.LiveData.observeForever(LiveData.java:207)
    at android.arch.lifecycle.MediatorLiveData$Source.plug(MediatorLiveData.java:141)
    at android.arch.lifecycle.MediatorLiveData.onActive(MediatorLiveData.java:118)
    at android.arch.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:410)
    at android.arch.lifecycle.LiveData.observeForever(LiveData.java:207)
    at android.arch.lifecycle.MediatorLiveData$Source.plug(MediatorLiveData.java:141)
    at android.arch.lifecycle.MediatorLiveData.onActive(MediatorLiveData.java:118)
    at android.arch.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:410)
    at android.arch.lifecycle.LiveData.observeForever(LiveData.java:207)
    at package.repository.FeedbackRepositoryTest.submitFeedbackTest(RepositoryTest.kt:43)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...