The org.junit.Assert.assertNotNull method is used to verify that an object is not null. This method ensures that the given object is not null and throws an AssertionError if it is null. The package library of this method is JUnit.
Example usage:
String str = "hello"; Assert.assertNotNull(str); // this will pass, as str is not null
String nullStr = null; Assert.assertNotNull(nullStr); // this will fail, as nullStr is null
int[] arr = new int[5]; Assert.assertNotNull(arr); // this will pass, as arr is not null
Object obj = getObject(); Assert.assertNotNull(obj); // this will pass, as getObject() method returns non-null object
In summary, the org.junit.Assert.assertNotNull method is a useful assertion method in JUnit testing to verify that an object is not null.
Java Assert.assertNotNull - 30 examples found. These are the top rated real world Java examples of org.junit.Assert.assertNotNull extracted from open source projects. You can rate examples to help us improve the quality of examples.