Skip to content

TestSubscriber throws AssertionError in .assertError even if Exceptions are the same #3134

@theblang

Description

@theblang

I am trying to use a TestSubscriber to unit test a function that receives an Observable. I am arranging the test using TestSubscriber and its onError call. When I try to assert using assertError I get an AssertionError: Exceptions differ; expected: java.net.SocketTimeoutException, actual: java.net.SocketTimeoutException.

My unit test:

    // arrange
    Mockito.when(mockJobRepository.getJobCountRefreshedTime()).thenReturn(0l);
    Mockito.when(mockJobRepository.refreshJobCount()).thenReturn(Observable.just(1337));
    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    testSubscriber.onError(new SocketTimeoutException());
    mockJobRepository.refreshJobCount().subscribe(testSubscriber);

    // act
    dashboardPresenter.onViewCreated();

    // assert
    testSubscriber.assertCompleted();
    testSubscriber.assertError(new SocketTimeoutException());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions