return getVarId(vars.get(0));
}
- LocalVariable getVar(Long varId) throws SQLException, TypeMismatchException
+ LocalVariable getVar(Long varId) throws SQLException, TypeMismatchException, StoreException
{
if (null == varId) {
return null;
List<Row> result = m_driver.select(m_con, columns, tables, conditions);
if (result.size() < 1) {
- throw new SQLException("No variable found for ID " + varId);
+ throw new StoreException(StoreException.Type.INVALID_VAR_ID, ""+varId);
}
if (result.size() > 1) {
throw new SQLException("Too many matches (" + result.size() + ") found for variable ID " + varId);
public enum Type {
UNKNOWN_PATTERN, // bug pattern type is not found in the message collection
UNKNOWN_CATEGORY, // bug category is not found in the message collection
- INVALID_LOC_ID // the specified location ID is not found in the database
+ INVALID_LOC_ID, // the specified location ID is not found in the database
+ INVALID_VAR_ID // the specified variable ID is not found in the database
}
private Type m_type;
import net.jaekl.cfb.db.driver.DbDriverMock;
import net.jaekl.cfb.util.Command;
import net.jaekl.cfb.xml.BugCollection;
+import net.jaekl.cfb.xml.LocalVariable;
import net.jaekl.cfb.xml.MessagesXmlData;
import org.junit.Before;
assertEquals(StoreException.Type.INVALID_LOC_ID, exc.getType());
}
}
+
+ @Test
+ public void testGetVar_nullReturnsNull() throws SQLException, TypeMismatchException, StoreException {
+ LocalVariable var = m_store.getVar(null);
+ assertNull(var);
+ }
+
+ @Test
+ public void testGetVar_invalidId() throws SQLException, TypeMismatchException {
+ try {
+ m_store.getVar(Long.valueOf(-3));
+ fail("Should have thrown a StoreException");
+ }
+ catch (StoreException exc) {
+ assertEquals(StoreException.Type.INVALID_VAR_ID, exc.getType());
+ }
+ }
}