Skip to content

2.X Null object reference on Completable.test() with Mockito #6046

@JuanDavid31

Description

@JuanDavid31

Hello, I'm actually having the following issue:

java.lang.NullPointerException: Attempt to invoke virtual method 'io.reactivex.observers.TestObserver io.reactivex.Completable.test()' on a null object reference
at repositorio.RepositorioProductoTest.insertarProductoTest(RepositorioProductoTest.java:48)

While testing a Completable in my code

    @Test
    public void insertarProductoTest(){
        repo.agregarElemento(productoDummy)
            .test()
            .assertComplete();

        verify(repo).darInstanciaDB().darDaoProducto().agregarProducto(argumentCaptor.capture());
        assertThat(argumentCaptor.getValue().getNombre(), Matchers.is("producto"));
    }

repo variable is being mocked with the @mocked anotattion
And if it is useful, here is the .agregarElemento(...) method

   public Completable agregarElemento(Producto elemento) {
        return Completable.fromAction(()-> darInstanciaDB().darDaoProducto().agregarProducto(elemento));
    }

I'm following this as example
https://github.com/googlesamples/android-architecture-components/blob/master/BasicRxJavaSample/app/src/test/java/com/example/android/observability/UserViewModelTest.java

Hope you can help me.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions