how to use assert java code example
Example 1: java assertions
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class AssertionExample {
@Test
public void assertionExample()
{
Assertions.assertEquals(2+2,4);
Assertions.assertNotEquals(6+3,10);
Assertions.assertTrue("Radu".length()==4);
String tester = null;
Assertions.assertThrows(NullPointerException.class,()->tester.equals("emptyString"));
}
}
Example 2: assert java
public void setup() { Connection conn = getConnection(); assert conn != null;}