package .service;
import java.util.List;
import java.util.ArrayList;
import .service.BaseManagerTestCase;
import .dao.Dao;
import .;
import .service.impl.ManagerImpl;
import org.jmock.Mock;
import org.springframework.orm.ObjectRetrievalFailureException;
public class ManagerTest extends BaseManagerTestCase {
private final String Id = "1";
private ManagerImpl Manager = new ManagerImpl();
private Mock Dao = null;
protected void setUp() throws Exception {
super.setUp();
Dao = new Mock(Dao.class);
Manager.setDao((Dao) Dao.proxy());
}
protected void tearDown() throws Exception {
super.tearDown();
Manager = null;
}
public void testGets() throws Exception {
List results = new ArrayList();
= new ();
results.add();
// set expected behavior on dao
Dao.expects(once()).method("gets")
.will(returnValue(results));
List s = Manager.gets(null);
assertTrue(s.size() == 1);
Dao.verify();
}
public void testGet() throws Exception {
// set expected behavior on dao
Dao.expects(once()).method("get")
.will(returnValue(new ()));
= Manager.get(Id);
assertTrue( != null);
Dao.verify();
}
public void testSave() throws Exception {
= new ();
// set expected behavior on dao
Dao.expects(once()).method("save")
.with(same()).isVoid();
Manager.save();
Dao.verify();
}
public void testAddAndRemove() throws Exception {
= new ();
// set required fields
// set expected behavior on dao
Dao.expects(once()).method("save")
.with(same()).isVoid();
Manager.save();
Dao.verify();
// reset expectations
Dao.reset();
Dao.expects(once()).method("remove").with(eq(new (Id)));
Manager.remove(Id);
Dao.verify();
// reset expectations
Dao.reset();
// remove
Exception ex = new ObjectRetrievalFailureException(.class, .());
Dao.expects(once()).method("remove").isVoid();
Dao.expects(once()).method("get").will(throwException(ex));
Manager.remove(Id);
try {
Manager.get(Id);
fail(" with identifier '" + Id + "' found in database");
} catch (ObjectRetrievalFailureException e) {
assertNotNull(e.getMessage());
}
Dao.verify();
}
}