![JAR search and dependency download from the Maven repository](/logo.png)
com.mockrunner.example.struts.MockOrderManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.example.struts;
import java.util.HashMap;
import java.util.Map;
/**
* Mock implementation of {@link OrderManager}.
* Used in the test {@link OrderActionTest}.
*/
public class MockOrderManager extends OrderManager
{
private Map products = new HashMap();
public MockOrderManager()
{
}
public void setStock(String id, int amount)
{
products.put(id, new Integer(amount));
}
public int getStock(String id)
{
Integer amount = (Integer)products.get(id);
if(null == amount) return 0;
return amount.intValue();
}
public void order(String id, int amount)
{
int available = getStock(id);
if(available < amount) throw new RuntimeException("not enough in stock");
Integer newStock = new Integer(available - amount);
products.put(id, newStock);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy