public CfbException(String msg) {
super(msg);
}
+
+ public CfbException(Throwable cause) {
+ super(cause);
+ }
}
m_msgColl = msgColl;
}
- public Analysis getPrior(Analysis analysis) throws SQLException, TypeMismatchException {
+ public Analysis getPrior(Analysis analysis) throws SQLException, TypeMismatchException, StoreException {
if (null == analysis) {
return null;
}
}
- Location getLoc(Long locId) throws SQLException, TypeMismatchException
+ Location getLoc(Long locId) throws TypeMismatchException, StoreException
{
if (null == locId) {
return null;
Table[] tables = { CfbSchema.LOCATIONS };
Condition[] conditions = { new Condition(CfbSchema.LOCID, locId, Operation.EQUAL) };
- Row row = m_driver.selectExactlyOne(m_con, columns, tables, conditions);
-
- String className = row.getString(0);
- String methodName = row.getString(1);
- String methodRole = row.getString(2);
- Integer startLine = row.getInt(3);
- Integer endLine = row.getInt(4);
-
- Location loc = new Location(locId, className, methodName, methodRole, startLine, endLine);
- return loc;
+ try {
+ Row row = m_driver.selectExactlyOne(m_con, columns, tables, conditions);
+
+ String className = row.getString(0);
+ String methodName = row.getString(1);
+ String methodRole = row.getString(2);
+ Integer startLine = row.getInt(3);
+ Integer endLine = row.getInt(4);
+
+ Location loc = new Location(locId, className, methodName, methodRole, startLine, endLine);
+ return loc;
+ }
+ catch (SQLException exc) {
+ throw new StoreException(exc, StoreException.Type.INVALID_LOC_ID, ""+locId);
+ }
}
Long getLocId(Location loc) throws SQLException, TypeMismatchException
return rows.get(0).getLong(0);
}
- Analysis getAnalysis(Long analysisId) throws SQLException, TypeMismatchException
+ Analysis getAnalysis(Long analysisId) throws SQLException, TypeMismatchException, StoreException
{
Column[] columns = { CfbSchema.PROJNAME, CfbSchema.VERSION, CfbSchema.STARTTIME, CfbSchema.ENDTIME };
Table[] tables = { CfbSchema.RUNS };
return prior;
}
- BugCollection getBugCollection(Long runId) throws SQLException, TypeMismatchException
+ BugCollection getBugCollection(Long runId) throws SQLException, TypeMismatchException, StoreException
{
Column[] columns = {
CfbSchema.FOUNDID,
public class StoreException extends CfbException {
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
+ UNKNOWN_CATEGORY, // bug category is not found in the message collection
+ INVALID_LOC_ID // the specified location ID is not found in the database
}
private Type m_type;
m_info = info;
}
+ public StoreException(Throwable cause, Type type, String... info) {
+ super(cause);
+
+ m_type = type;
+ m_info = info;
+ }
+
+ public Type getType() { return m_type; }
+
@Override
public String toString() {
return "" + getClass().getName() + ": " + m_type + ": " + Arrays.toString(m_info);
return (a == b);
}
+ if ((a instanceof Number) && (b instanceof Number)) {
+ Number aNum = (Number)a;
+ Number bNum = (Number)b;
+
+ return ( (aNum.longValue() == bNum.longValue())
+ || (aNum.doubleValue() == bNum.doubleValue()) );
+ }
+
return a.equals(b);
}
import net.jaekl.cfb.db.Table;
import net.jaekl.cfb.db.TableMock;
import net.jaekl.cfb.db.TypeMismatchException;
+import net.jaekl.cfb.util.Util;
public class DbDriverMock extends DbDriver {
if (condition.getColumn().equals(col)) {
switch(condition.getOperation()) {
case EQUAL:
- return (condition.getValue().equals(row.getValue(idx)));
+ return Util.objsAreEqual(condition.getValue(), row.getValue(idx));
case GREATER_THAN:
return (aLessThanB(condition.getValue(), row.getValue(idx)));
case LESS_THAN:
}
@Test
- public void testGetPrior_withNoEntries() throws SQLException, TypeMismatchException {
+ public void testGetPrior_withNoEntries() throws SQLException, TypeMismatchException, StoreException {
// First test: getPrior(null) should return null
Analysis actual = m_store.getPrior(null);
assertNull(actual);
assertEquals(firstAnalysis.getEnd(), priorAnalysis.getEnd());
assertEquals(firstAnalysis.getBugCollection(), priorAnalysis.getBugCollection());
}
-/*
- @Test
- public void testGetBugType() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testGetCategoryName() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testGetLoc() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testGetLocId() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testFindLocId() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testStoreLoc() {
- fail("Not yet implemented");
- }
@Test
- public void testGetVarIdBugInstance() {
- fail("Not yet implemented");
+ public void testGetLocId_nullReturnsNull() throws SQLException, TypeMismatchException {
+ Long locId = m_store.getLocId(null);
+ assertNull(locId);
}
@Test
- public void testGetVar() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testGetVarIdLocalVariable() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testFindVarId() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testStoreVar() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testGetPriorId() {
- fail("Not yet implemented");
+ public void testGetLocId_notFoundIsStored() throws SQLException, TypeMismatchException {
+ Location loc = new Location(1234567890L,
+ "ThisClassDoesNotExist",
+ "thisMethodDoesNotExist",
+ "INVALID_METHOD_ROLE",
+ 0, 90909);
+ Long locId = m_store.getLocId(loc);
+ assertNotNull(locId);
+ assertTrue(locId.longValue() > 0);
+
+ Long secondLocId = m_store.getLocId(loc);
+ assertEquals(locId, secondLocId);
}
@Test
- public void testGetAnalysis() {
- fail("Not yet implemented");
+ public void testGetLoc_nullReturnsNull() throws SQLException, TypeMismatchException, StoreException {
+ Location loc = m_store.getLoc(null);
+ assertNull(loc);
}
-
+
@Test
- public void testGetBugCollection() {
- fail("Not yet implemented");
+ public void testGetLoc_invalidId() throws SQLException, TypeMismatchException {
+ try {
+ m_store.getLoc(Long.valueOf(-3));
+ fail("Should have thrown a StoreException");
+ }
+ catch (StoreException exc) {
+ assertEquals(StoreException.Type.INVALID_LOC_ID, exc.getType());
+ }
}
-*/
}