Listing 1: HelloWorld

public class HelloWorld {
  public String sayHello(){
    return "Hello World!";
  }
}

Listing 2: testSayHello()

public class HelloWorldTest extends AgitarTestCase {
  private static Class TARGET_CLASS = HelloWorld.class;
  public void testSayHello() throws Throwable {
    String result = new HelloWorld().sayHello();
    assertEquals("result", "Hello World!", result);1
  }
}


Listing 3: isLeapYear()

public class LeapYear {
  public static boolean isLeapYear(int year) {
    if(year < 1){
      throw new IllegalArgumentException();
    }
    if(year % 400 == 0){
      return true;
    }
    if(year % 100 == 0){
      return false;
    }
    if(year % 4 == 0){
      return true;
    }
    return false;
  }
}


Listing 4: testIsLeapYear

public class LeapYearTest extends AgitarTestCase {
  private static Class TARGET_CLASS = LeapYear.class;
  
  public void testIsLeapYearThrowsIllegalArgumentException()
    throws Throwable {
    try {
      LeapYear.isLeapYear(0);
      fail("Expected IllegalArgumentException to be thrown");2
    } catch (IllegalArgumentException ex) {
        assertNull("ex.getMessage()", ex.getMessage());
        assertThrownBy(LeapYear.class, ex);
      }
  }

  public void testIsLeapYear() throws Throwable {
    boolean result = LeapYear.isLeapYear(101);
    assertFalse("result", result);
  }
    
  // ... Snipped several unit tests ... 
    
  public void testIsLeapYear6() throws Throwable {
    boolean result = LeapYear.isLeapYear(4);
    assertTrue("result", result);
  }
    
}



Listing 5: testGetTotalPrice

public void testGetTotalPrice2() throws Throwable {
        Item item = new Item();
        CartItem cartItem = new CartItem();
        item.setListPrice(100.0);
        cartItem.setItem(item);
        cartItem.incrementQuantity();
        double result = cartItem.getTotalPrice();
        assertEquals("result", 100.0, result, 1.0E-6);
    }

Listing 6: testInitOrderThrowsNullPointerException

public void testInitOrderThrowsNullPointerException() throws Throwable {
        Order order = new Order();
        order.setLineItems(null);
        Cart cart = new Cart();
        cart.addItem(new Item(), true);
        try {
            order.initOrder(new Account(), cart);
            fail("Expected NullPointerException to be thrown");
        } catch (NullPointerException ex) {




Listing 7: Out of Order

public class Order implements Serializable {

// ... 

private List lineItems = new ArrayList();

// ... 

  public void setLineItems(List lineItems) { 
    this.lineItems = lineItems; }
  public List getLineItems() { return lineItems; }

// ... 


Listing 8: Out of lineItems

  public List getLineItems() { 
    if (lineItems==null) lineItems = new ArrayList();
    return lineItems; 
 }


Listing 9: TestHelpers

package org.springframework.samples.jpetstore.domain;
import com.agitar.lib.TestHelper;
public class TestHelpers implements TestHelper{
    
    public static Item createEst1() {
        Item item = new Item();
        item.setItemId("EST-1");
        item.setProductId("FI-SW-01");
        item.setListPrice(16.50);
        item.setUnitCost(10.00);
        item.setSupplierId(1);
        item.setStatus("P");
        item.setAttribute1("Large");
        return item;
    }
    
    // ...Snip 26 Item objects...

    public static Item createEst28() {
        Item item = new Item();
        item.setItemId("EST-28");
        item.setProductId("K9-RT-01");
        item.setListPrice(155.29);
        item.setUnitCost(90.00);
        item.setSupplierId(1);
        item.setStatus("P");
        item.setAttribute1("Adult Female");
        return item;
    }   

}


Listing 10: testToString

public void testToString() throws Throwable {
    String result = TestHelpers.createEst1().toString();
    assertEquals("result", "(EST-1-FI-SW-01)", result);
}