@Test public void myTest() { String result = someMethod(); assertThat(result, notNullValue()); } private String someMethod() { return "Hello, world!"; }
@Test public void myTest() { MyClass myObj = new MyClass(); assertThat(myObj.getSomeValue(), notNullValue()); } public class MyClass { private String someValue; public MyClass() { someValue = "Hello, world!"; } public String getSomeValue() { return someValue; } }In this example, we create an instance of the MyClass object and then use the notNullValue matcher to verify that its getSomeValue method returns a non-null value. The org.hamcrest library is a package for writing assertion style tests. It provides a set of matchers for use with the JUnit testing framework. More information can be found here: https://github.com/hamcrest/JavaHamcrest.