@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 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 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); }