Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

contains(..) is not null-safe #3

@runeflobakk

Description

@runeflobakk

A Stream may contain nulls (though whether that's a good idea is up for debate ;) ), but StreamMatchers.contains(..) is not null safe. A workaround is to collect the steam to e.g. a List and use Hamcrest's Matchers.contains(..), which handles expected null-elements. The workaround also demonstrates that StreamMatchers.contains(..) should indeed handle null-elements.

The sollution is simple. Just replace the nextExpected.equals(nextActual) (https://github.com/unruly/java-8-matchers/blob/master/src/main/java/co/unruly/matchers/StreamMatchers.java#L650) with java.util.Objects.equals(nextExpected, nextActual), and it handles expected null-elements.

I have implemented the fix with testcase that I will issue a pull request for.

Thanks for making the library!

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