@Test
 public void testGetReturnsResultSet() {
   statementHandler.prepareReturnsResultSet("select.*", false);
   assertNull(statementHandler.getReturnsResultSet("select abc"));
   statementHandler.setUseRegularExpressions(true);
   assertEquals(Boolean.FALSE, statementHandler.getReturnsResultSet("select abc"));
 }
 @Test
 public void testGetUpdateCounts() {
   int[] updateCounts = new int[] {1, 2};
   statementHandler.prepareUpdateCounts(".*", updateCounts);
   statementHandler.prepareUpdateCount("insert xyz", 4);
   Integer[] returnedUpdateCounts = statementHandler.getUpdateCounts(".*");
   assertEquals(2, returnedUpdateCounts.length);
   assertEquals(new Integer(1), returnedUpdateCounts[0]);
   assertEquals(new Integer(2), returnedUpdateCounts[1]);
   returnedUpdateCounts = statementHandler.getUpdateCounts("insert xyz");
   assertEquals(1, returnedUpdateCounts.length);
   assertEquals(new Integer(4), returnedUpdateCounts[0]);
   assertNull(statementHandler.getUpdateCounts("do nothing"));
 }
 @Test
 public void testGetGeneratedKeys() {
   MockResultSet result = new MockResultSet("id");
   statementHandler.prepareGeneratedKeys("insert into table", result);
   statementHandler.prepareGeneratedKeys("insert .*", result);
   assertSame(result, statementHandler.getGeneratedKeys("insert into table abc"));
   assertSame(result, statementHandler.getGeneratedKeys("insert .*"));
   assertNull(statementHandler.getGeneratedKeys("insert into othertable"));
   statementHandler.setUseRegularExpressions(true);
   assertSame(result, statementHandler.getGeneratedKeys("insert into table"));
   assertSame(result, statementHandler.getGeneratedKeys("INSERt regular"));
   statementHandler.setCaseSensitive(true);
   assertNull(statementHandler.getGeneratedKeys("INSERt regular"));
 }
 @Test
 public void testGetResultSets() {
   MockResultSet result0 = new MockResultSet("id0");
   MockResultSet result1 = new MockResultSet("id1");
   MockResultSet[] results = new MockResultSet[] {result0, result1};
   statementHandler.prepareResultSets("select column from table", results);
   statementHandler.prepareResultSet("select .*", result0);
   MockResultSet[] returnedResults = statementHandler.getResultSets("select column from table");
   assertNotSame(returnedResults, results);
   assertEquals(2, returnedResults.length);
   assertSame(result0, returnedResults[0]);
   assertSame(result1, returnedResults[1]);
   assertNull(statementHandler.getResultSet("select xyz from table"));
   returnedResults = statementHandler.getResultSets("select .*");
   assertEquals(1, returnedResults.length);
   assertSame(result0, returnedResults[0]);
 }
 @Test
 public void testHasMutipleGlobalUpdateCounts() {
   statementHandler.prepareGlobalUpdateCount(4);
   assertFalse(statementHandler.hasMultipleGlobalUpdateCounts());
   statementHandler.prepareGlobalUpdateCounts(new int[] {1});
   assertTrue(statementHandler.hasMultipleGlobalUpdateCounts());
   statementHandler.prepareGlobalUpdateCounts(new int[] {7, 8});
   assertTrue(statementHandler.hasMultipleGlobalUpdateCounts());
 }
 @Test
 public void testHasMultipleResultSets() {
   MockResultSet result0 = new MockResultSet("id0");
   MockResultSet result1 = new MockResultSet("id1");
   statementHandler.prepareResultSets(
       "select column from table", new MockResultSet[] {result0, result1});
   statementHandler.prepareResultSets("select column from abc", new MockResultSet[] {result1});
   statementHandler.prepareResultSet("select .*", result0);
   assertTrue(statementHandler.hasMultipleResultSets("select column from table"));
   assertTrue(statementHandler.hasMultipleResultSets("select column from abc"));
   assertFalse(statementHandler.hasMultipleResultSets("select .*"));
   assertFalse(statementHandler.hasMultipleResultSets("do nothing"));
 }
 @Test
 public void testHasMultipleUpdateCounts() {
   statementHandler.prepareUpdateCount("update", 3);
   statementHandler.prepareUpdateCounts("insert into xyz", new int[] {4});
   statementHandler.prepareUpdateCounts("insert into abc", new int[] {1, 2, 4});
   assertFalse(statementHandler.hasMultipleUpdateCounts("update"));
   assertFalse(statementHandler.hasMultipleUpdateCounts("do nothing"));
   assertTrue(statementHandler.hasMultipleUpdateCounts("insert into xyz"));
   assertTrue(statementHandler.hasMultipleUpdateCounts("insert into abc"));
 }
 @Test
 public void testHasMutipleGlobalResultSets() {
   MockResultSet result0 = new MockResultSet("id0");
   MockResultSet result1 = new MockResultSet("id1");
   statementHandler.prepareGlobalResultSet(result0);
   assertFalse(statementHandler.hasMultipleGlobalResultSets());
   statementHandler.prepareGlobalResultSets(new MockResultSet[] {result1});
   assertTrue(statementHandler.hasMultipleGlobalResultSets());
   statementHandler.prepareGlobalResultSets(new MockResultSet[] {result0, result1});
   assertTrue(statementHandler.hasMultipleGlobalResultSets());
 }
 @Test
 public void testGetGlobalUpdateCount() {
   int[] updateCounts = new int[] {1, 2};
   statementHandler.prepareGlobalUpdateCount(4);
   assertEquals(4, statementHandler.getGlobalUpdateCount());
   int[] returnedUpdateCounts = statementHandler.getGlobalUpdateCounts();
   assertEquals(1, returnedUpdateCounts.length);
   assertEquals(4, returnedUpdateCounts[0]);
   statementHandler.prepareGlobalUpdateCounts(updateCounts);
   assertEquals(1, statementHandler.getGlobalUpdateCount());
   returnedUpdateCounts = statementHandler.getGlobalUpdateCounts();
   assertNotSame(updateCounts, returnedUpdateCounts);
   assertEquals(2, returnedUpdateCounts.length);
   assertEquals(1, returnedUpdateCounts[0]);
   assertEquals(2, returnedUpdateCounts[1]);
 }
 @Test
 public void testGetGlobalResultSet() {
   MockResultSet result0 = new MockResultSet("id0");
   MockResultSet result1 = new MockResultSet("id1");
   MockResultSet[] results = new MockResultSet[] {result0, result1};
   statementHandler.prepareGlobalResultSet(result0);
   assertSame(result0, statementHandler.getGlobalResultSet());
   MockResultSet[] returnedResults = statementHandler.getGlobalResultSets();
   assertEquals(1, returnedResults.length);
   assertSame(result0, returnedResults[0]);
   statementHandler.prepareGlobalResultSets(results);
   assertSame(result0, statementHandler.getGlobalResultSet());
   returnedResults = statementHandler.getGlobalResultSets();
   assertNotSame(results, returnedResults);
   assertEquals(2, returnedResults.length);
   assertSame(result0, returnedResults[0]);
   assertSame(result1, returnedResults[1]);
 }
 @Test
 public void testMakeStatCumulWithoutExistingData() throws Exception {
   MockConnection connexion = factory.getMockConnection();
   StatementResultSetHandler statementHandler = connexion.getStatementResultSetHandler();
   statementHandler.setExactMatch(true);
   MockResultSet result = statementHandler.createResultSet();
   result.addColumn("dateStat", new Object[] {"2011-04-17"});
   result.addColumn("fileDir", new Object[] {"/var/data/silverpeas/kmelia36"});
   result.addColumn("sizeDir", new Object[] {543L});
   statementHandler.prepareResultSet("SELECT * FROM SB_Stat_SizeDir", result);
   MockResultSet cumulResult = statementHandler.createResultSet();
   statementHandler.prepareResultSet(
       "SELECT dateStat,fileDir,sizeDir FROM SB_Stat_SizeDirCumul "
           + "WHERE dateStat='2011-04-01' AND fileDir='/var/data/silverpeas/kmelia36'",
       cumulResult);
   SilverStatisticsManagerDAO.makeStatCumul(connexion, typeofStat, config);
   module.verifyAllStatementsClosed();
   List<?> statements = module.getExecutedSQLStatements();
   assertNotNull(statements);
   assertThat(statements.size(), is(3));
   List<?> preparedStatements = module.getPreparedStatements();
   assertNotNull(preparedStatements);
   assertThat(preparedStatements, hasSize(2));
   MockPreparedStatement pstmt = module.getPreparedStatement(0);
   assertThat(
       pstmt.getSQL(),
       is(
           "UPDATE SB_Stat_SizeDirCumul SET sizeDir=?  WHERE "
               + "dateStat='2011-04-01' AND fileDir='/var/data/silverpeas/kmelia36'"));
   Map parameters = pstmt.getParameterMap();
   assertThat(parameters.size(), is(0));
   pstmt = module.getPreparedStatement(1);
   assertThat(
       pstmt.getSQL(),
       is("INSERT INTO SB_Stat_SizeDirCumul(dateStat,fileDir,sizeDir) " + "VALUES(?,?,?)"));
   parameters = pstmt.getParameterMap();
   assertThat(parameters.size(), is(3));
   assertThat((String) parameters.get(1), is("2011-04-01"));
   assertThat((String) parameters.get(2), is("/var/data/silverpeas/kmelia36"));
   assertThat((Long) parameters.get(3), is(543L));
 }
 @Test
 public void testGetResultSet() {
   MockResultSet result = new MockResultSet("id");
   statementHandler.prepareResultSet("select column from table", result);
   statementHandler.prepareResultSet("select .*", result);
   assertSame(result, statementHandler.getResultSet("select column from table"));
   assertNull(statementHandler.getResultSet("select xyz from table"));
   statementHandler.setUseRegularExpressions(true);
   assertSame(result, statementHandler.getResultSet("select column from table"));
   assertSame(result, statementHandler.getResultSet("SELECT xyz from table"));
   statementHandler.setCaseSensitive(true);
   assertNull(statementHandler.getResultSet("SELECT xyz from table"));
   MockResultSet result0 = new MockResultSet("id0");
   MockResultSet result1 = new MockResultSet("id1");
   MockResultSet[] results = new MockResultSet[] {result0, result1};
   statementHandler.clearResultSets();
   statementHandler.prepareResultSets("select abc", results);
   assertSame(result0, statementHandler.getResultSet("select abc"));
 }
 @Test
 public void testPreparedSQLOrdered() {
   MockResultSet result1 = new MockResultSet("id1");
   MockResultSet result2 = new MockResultSet("id2");
   statementHandler.prepareResultSet("select", result1);
   statementHandler.prepareResultSet("SelecT", result2);
   statementHandler.prepareUpdateCount("SelecT", 3);
   statementHandler.prepareUpdateCount("select2", 2);
   statementHandler.prepareReturnsResultSet("select", false);
   statementHandler.prepareReturnsResultSet("selecT", true);
   statementHandler.prepareGeneratedKeys("seLECT", result1);
   statementHandler.prepareGeneratedKeys("select", result2);
   assertSame(result2, statementHandler.getResultSet("select"));
   assertSame(result2, statementHandler.getResultSets("select")[0]);
   assertEquals(new Integer(3), statementHandler.getUpdateCount("SELECT"));
   assertEquals(new Integer(3), statementHandler.getUpdateCounts("selecT")[0]);
   assertTrue(statementHandler.getReturnsResultSet("select").booleanValue());
   assertSame(result1, statementHandler.getGeneratedKeys("select"));
 }
 @Test
 public void testClearMethods() {
   statementHandler.prepareResultSet("select", new MockResultSet("id"));
   statementHandler.prepareUpdateCount("select", 3);
   statementHandler.prepareThrowsSQLException("select");
   statementHandler.prepareReturnsResultSet("select", true);
   statementHandler.prepareGeneratedKeys("select", new MockResultSet("id"));
   statementHandler.clearResultSets();
   statementHandler.clearUpdateCounts();
   statementHandler.clearThrowsSQLException();
   statementHandler.clearReturnsResultSet();
   statementHandler.clearGeneratedKeys();
   assertNull(statementHandler.getResultSet("select"));
   assertNull(statementHandler.getUpdateCount("select"));
   assertFalse(statementHandler.getThrowsSQLException("select"));
   assertNull(statementHandler.getReturnsResultSet("select"));
   assertNull(statementHandler.getGeneratedKeys("select"));
 }
 @Test
 public void testGetThrowsSQLException() {
   SQLException exc = new BatchUpdateException();
   statementHandler.prepareThrowsSQLException("[abc] statement", exc);
   statementHandler.prepareThrowsSQLException("[abc] statementxyz");
   assertFalse(statementHandler.getThrowsSQLException("a stAtement"));
   assertNull(statementHandler.getSQLException("a stAtement"));
   statementHandler.setUseRegularExpressions(true);
   assertTrue(statementHandler.getThrowsSQLException("a stAtement"));
   assertSame(exc, statementHandler.getSQLException("a stAtement"));
   statementHandler.setCaseSensitive(true);
   assertFalse(statementHandler.getThrowsSQLException("a stAtement"));
   assertNull(statementHandler.getSQLException("a stAtement"));
   assertTrue(statementHandler.getThrowsSQLException("b statement"));
   assertSame(exc, statementHandler.getSQLException("b statement"));
   assertTrue(statementHandler.getThrowsSQLException("b statementxyz"));
   assertNotSame(exc, statementHandler.getSQLException("b statementxyz"));
   String message = statementHandler.getSQLException("b statementxyz").getMessage();
   assertTrue(message.indexOf("[abc] statementxyz") != -1);
 }
 @Test
 public void testGetUpdateCount() {
   statementHandler.prepareUpdateCount(".*", 3);
   statementHandler.prepareUpdateCount("insert xyz", 4);
   assertEquals(new Integer(4), statementHandler.getUpdateCount("insert xyz"));
   assertEquals(new Integer(3), statementHandler.getUpdateCount(".*"));
   statementHandler.setUseRegularExpressions(true);
   assertEquals(new Integer(3), statementHandler.getUpdateCount("insert xyz"));
   assertEquals(new Integer(3), statementHandler.getUpdateCount("insert"));
   statementHandler.setExactMatch(true);
   assertEquals(new Integer(4), statementHandler.getUpdateCount("insert Xyz"));
   assertNull(statementHandler.getUpdateCount("insert"));
   statementHandler.prepareUpdateCounts("update", new int[] {1, 2});
   assertEquals(new Integer(1), statementHandler.getUpdateCount("update"));
 }