From 7ac6be132ecd6872971a1de56f033b4434d3173a Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Wed, 30 Dec 2015 18:35:17 +0900 Subject: [PATCH] Further unit tests: getVar() --- prod/net/jaekl/cfb/store/DbStore.java | 4 ++-- prod/net/jaekl/cfb/store/StoreException.java | 3 ++- test/net/jaekl/cfb/store/DbStoreTest.java | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/prod/net/jaekl/cfb/store/DbStore.java b/prod/net/jaekl/cfb/store/DbStore.java index b17a419..917dc48 100644 --- a/prod/net/jaekl/cfb/store/DbStore.java +++ b/prod/net/jaekl/cfb/store/DbStore.java @@ -223,7 +223,7 @@ public class DbStore { 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; @@ -235,7 +235,7 @@ public class DbStore { List 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); diff --git a/prod/net/jaekl/cfb/store/StoreException.java b/prod/net/jaekl/cfb/store/StoreException.java index b7d7581..c1c3e78 100644 --- a/prod/net/jaekl/cfb/store/StoreException.java +++ b/prod/net/jaekl/cfb/store/StoreException.java @@ -8,7 +8,8 @@ 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 - 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; diff --git a/test/net/jaekl/cfb/store/DbStoreTest.java b/test/net/jaekl/cfb/store/DbStoreTest.java index 5c66c22..98656c8 100644 --- a/test/net/jaekl/cfb/store/DbStoreTest.java +++ b/test/net/jaekl/cfb/store/DbStoreTest.java @@ -23,6 +23,7 @@ import net.jaekl.cfb.db.driver.ConnectionMock; 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; @@ -274,4 +275,21 @@ public class DbStoreTest { 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()); + } + } } -- 2.30.2