import org.junit.Assert; import org.junit.Test; public class AssertTest { @Test public void testEquality() { Assert.assertEquals("foo", "foo"); Assert.assertNotEquals("foo", "bar"); } }
import org.junit.Assert; import org.junit.Test; public class AssertTest { @Test public void testNullity() { String foo = null; Assert.assertNull(foo); String bar = "bar"; Assert.assertNotNull(bar); } }
import org.junit.Assert; import org.junit.Test; public class AssertTest { @Test(expected = ArithmeticException.class) public void testException() { int x = 1 / 0; } }This example shows how to use the `@Test(expected = ...)` annotation to test for expected exceptions. In this case, the test will pass if an `ArithmeticException` is thrown while computing `1/0`. The org.junit Assert package library can be found in the JUnit testing framework, which can be downloaded from the official JUnit website or included as a dependency in a build tool like Maven or Gradle.