提交 2f33a9e2 编写于 作者: X xiaochun.liu

delete dup code

上级 bd10b78e
...@@ -35,15 +35,11 @@ public class ScriptRunnerTest { ...@@ -35,15 +35,11 @@ public class ScriptRunnerTest {
Assert.assertNotNull(exception); Assert.assertNotNull(exception);
//connect is not null //connect is not null
try { runScript("");
ScriptRunner s2 = getScriptRunner();
s2.runScript(new StringReader("select 1;"));
} catch(Exception e) {
Assert.assertNotNull(e);
}
} }
private ScriptRunner getScriptRunner() throws SQLException { private void runScript(String dbName) {
try {
Connection conn = Mockito.mock(Connection.class); Connection conn = Mockito.mock(Connection.class);
Mockito.when(conn.getAutoCommit()).thenReturn(true); Mockito.when(conn.getAutoCommit()).thenReturn(true);
PreparedStatement st = Mockito.mock(PreparedStatement.class); PreparedStatement st = Mockito.mock(PreparedStatement.class);
...@@ -54,18 +50,21 @@ public class ScriptRunnerTest { ...@@ -54,18 +50,21 @@ public class ScriptRunnerTest {
Mockito.when(rs.getMetaData()).thenReturn(md); Mockito.when(rs.getMetaData()).thenReturn(md);
Mockito.when(md.getColumnCount()).thenReturn(1); Mockito.when(md.getColumnCount()).thenReturn(1);
Mockito.when(rs.next()).thenReturn(true, false); Mockito.when(rs.next()).thenReturn(true, false);
ScriptRunner s2 = new ScriptRunner(conn, true, true); ScriptRunner s = new ScriptRunner(conn, true, true);
if (dbName.isEmpty()) {
s.runScript(new StringReader("select 1;"));
} else {
s.runScript(new StringReader("select 1;"), dbName);
}
Mockito.verify(md).getColumnLabel(0); Mockito.verify(md).getColumnLabel(0);
} catch(Exception e) {
Assert.assertNotNull(e);
}
} }
@Test @Test
public void testRunScriptWithDbName() { public void testRunScriptWithDbName() {
//connect is not null //connect is not null
try { runScript("db_test");
ScriptRunner s = getScriptRunner();
s.runScript(new StringReader("select 1;"), "test_db");
} catch(Exception e) {
Assert.assertNotNull(e);
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册