DbUpgradeUtils { public static void dropKeysIfExist(Connection conn, String tableName, List<String> keys, boolean isForeignKey) { for (String key : keys) { dao.dropKey(conn, tableName, key, isForeignKey); } }  static void dropKeysIfExist(Connection conn, String tableName, List<String> keys, boolean isForeignKey); static void dropPrimaryKeyIfExists(Connection conn, String tableName); static void dropTableColumnsIfExist(Connection conn, String tableName, List<String> columns);  }
@Test public void testDropKeyIfExistWhenNoKeysAreSupplied() throws Exception { Connection conn = connectionMock; String tableName = "tableName"; List<String> keys = new ArrayList<String>(); boolean isForeignKey = false; DbUpgradeUtils.dropKeysIfExist(conn, tableName, keys, isForeignKey); verify(daoMock, times(0)).dropKey(eq(conn), eq(tableName), anyString(), eq(isForeignKey)); }
@Test public void testDropKeyIfExistWhenOneKeysIsSupplied() throws Exception { Connection conn = connectionMock; String tableName = "tableName"; String key = "key"; List<String> keys = Arrays.asList(new String[] {key}); boolean isForeignKey = false; DbUpgradeUtils.dropKeysIfExist(conn, tableName, keys, isForeignKey); verify(daoMock, times(1)).dropKey(conn, tableName, key, isForeignKey); }
@Test public void testDropKeyIfExistWhenThreeKeysAreSupplied() throws Exception { Connection conn = connectionMock; String tableName = "tableName"; String key1 = "key1"; String key2 = "key2"; List<String> keys = Arrays.asList(new String[] {key1, key2}); boolean isForeignKey = false; DbUpgradeUtils.dropKeysIfExist(conn, tableName, keys, isForeignKey); verify(daoMock, times(1)).dropKey(conn, tableName, key1, isForeignKey); verify(daoMock, times(1)).dropKey(conn, tableName, key2, isForeignKey); }