Skip to content

Unable to test presenter ? #297

@devendroid

Description

@devendroid

Hi,
I have implemented the same architecture in kotlin but when I'm mocking a UseCase class, it's not initializing, my presenter test class is below:

   private var presenter:SetAddressPresenter? = null
   @Mock
   private var mockContext: Context? = null
   @Mock
   private var controller: Controller? = null
   @Mock
   private lateinit var setAddressUseCase: SetAddressUseCase

   @Before
   fun setUp() {
       MockitoAnnotations.initMocks(this)
       presenter = SetAddressPresenter(setAddressUseCase)
       presenter?.setAddressController(controller)
   }

   @Test
   fun testUserListPresenterInitialize() {
       given(controller?.context()).willReturn(mockContext)
       presenter?.loadPreviousAddresses()

       verify(controller)?.hideRetry()
       verify(controller)?.showLoading()
       verify(setAddressUseCase)?.execute(
           any(SetAddressPresenter.SetAddressObserver::class.java),
           any(Void::class.java)  )
    }

Getting the NullPointerException on
...domain.interactor.UseCase.execute(UseCase.kt:53)

my UseCase Class is:

..........
init {
        compositeDisposable = CompositeDisposable()
        this.threadExecutor = threadExecutor
        this.postExecutionThread = postExecutionThread
    }
fun execute(observer: DisposableObserver<T>, params: Any?) {
        val observable = this.buildUseCaseObservable(params)
            .subscribeOn(Schedulers.from(threadExecutor))   // Line no 53
            .observeOn(postExecutionThread.getScheduler())
        addDisposable(observable.subscribeWith(observer))
    }
..........

Could you please help or advice on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions