There is a need to check that the object in the array, which initially was null, was assigned a value.

There is a method confirming that the value is null

assertThat(result, is(nullValue())); 

And tell me an analogue with the opposite meaning

 assertThat(result, is( НЕ nullValue())); 

That is, it does not matter what the result is, the main thing is not null without having to specify what exactly is there.

  • 2
    so don't drive assertThat(result, !is(nullValue())); ? In general, like checking for null: assertThat(null, is(nullValue())); not null: assertThat("a", is(notNullValue())); - Alexey Shimansky
  • one
    there was still not() helper if memory serves - etki
  • one
    You can use hamcrest there is a method notNullValue (), a wrapper over not () hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/core/… - a.chugunov

1 answer 1

If we are talking about junit then it has methods:

public static void assertNotNull (java.lang.Object object)

and

public static void assertNull (java.lang.Object object)

You can use the import package Assert :

import static org.junit.Assert.*;