1 package demo; 2 3 import org.junit.Before; 4 import org.junit.Test; 5 import static org.junit.Assert.*; 6 7 public class FooTest { 8 Foo obj; 9 10 @Before 11 public void setup() { 12 obj = new Foo(); 13 } 14 15 @Test 16 public void testBarNonNegativeNumber() { 17 String result = obj.bar(0); 18 assertEquals("bar did not return \"baz\"", "baz", result); 19 } 20 21 @Test(expected=IllegalArgumentException.class) 22 public void testBarNegativeNumber() { 23 24 obj.bar(-1); 25 } 26 } 27