package com.vst.service;
import java.util.List;
import java.util.ArrayList;
import com.vst.service.BaseManagerTestCase;
import com.vst.dao.HintDao;
import com.vst.model.Hint;
import com.vst.service.impl.HintManagerImpl;
import org.jmock.Mock;
import org.springframework.orm.ObjectRetrievalFailureException;
public class HintManagerTest extends BaseManagerTestCase {
private final String hintId = "1";
private HintManagerImpl hintManager = new HintManagerImpl();
private Mock hintDao = null;
protected void setUp() throws Exception {
super.setUp();
hintDao = new Mock(HintDao.class);
hintManager.setHintDao((HintDao) hintDao.proxy());
}
protected void tearDown() throws Exception {
super.tearDown();
hintManager = null;
}
public void testGetHints() throws Exception {
List results = new ArrayList();
Hint hint = new Hint();
results.add(hint);
// set expected behavior on dao
hintDao.expects(once()).method("getHints")
.will(returnValue(results));
List hints = hintManager.getHints(null);
assertTrue(hints.size() == 1);
hintDao.verify();
}
public void testGetHint() throws Exception {
// set expected behavior on dao
hintDao.expects(once()).method("getHint")
.will(returnValue(new Hint()));
Hint hint = hintManager.getHint(hintId);
assertTrue(hint != null);
hintDao.verify();
}
public void testSaveHint() throws Exception {
Hint hint = new Hint();
// set expected behavior on dao
hintDao.expects(once()).method("saveHint")
.with(same(hint)).isVoid();
hintManager.saveHint(hint);
hintDao.verify();
}
public void testAddAndRemoveHint() throws Exception {
Hint hint = new Hint();
// set required fields
// set expected behavior on dao
hintDao.expects(once()).method("saveHint")
.with(same(hint)).isVoid();
hintManager.saveHint(hint);
hintDao.verify();
// reset expectations
hintDao.reset();
hintDao.expects(once()).method("removeHint").with(eq(new Long(hintId)));
hintManager.removeHint(hintId);
hintDao.verify();
// reset expectations
hintDao.reset();
// remove
Exception ex = new ObjectRetrievalFailureException(Hint.class, hint.getHintId());
hintDao.expects(once()).method("removeHint").isVoid();
hintDao.expects(once()).method("getHint").will(throwException(ex));
hintManager.removeHint(hintId);
try {
hintManager.getHint(hintId);
fail("Hint with identifier '" + hintId + "' found in database");
} catch (ObjectRetrievalFailureException e) {
assertNotNull(e.getMessage());
}
hintDao.verify();
}
}