@Test public void testAdd() { Calculator calculator = new Calculator(); int result = calculator.add(2, 3); Assert.assertEquals(5, result); }
@Test(expected = NullPointerException.class) public void testNullPointer() { MyClass obj = null; obj.method(); }This code ensures that the "method" in "MyClass" class always throws a NullPointerException when "obj" is null. In conclusion, org.junit.Assert is a package library that provides assertion methods to verify the correctness of the code in unit tests. It is located within the org.junit package.