### Question:
SchemaToolTaskDrop extends SchemaToolTask { @Override void execute() throws HiveMetaException { if (!schemaTool.isDryRun() && !this.yes) { boolean confirmed = promptToConfirm(); if (!confirmed) { System.out.println("Operation cancelled, exiting."); return; } } Connection conn = schemaTool.getConnectionToMetastore(true); try { try (Statement stmt = conn.createStatement()) { final String def = Warehouse.DEFAULT_DATABASE_NAME; List<String> databases = new ArrayList<>(); try (ResultSet rs = stmt.executeQuery("SHOW DATABASES")) { while (rs.next()) { databases.add(rs.getString(1)); } } for (String database : databases) { if (!def.equalsIgnoreCase(database)) { if (schemaTool.isDryRun()) { System.out.println("would drop database " + database); } else { logIfVerbose("dropping database " + database); stmt.execute(String.format("DROP DATABASE `%s` CASCADE", database)); } } } List<String> tables = new ArrayList<>(); try (ResultSet rs = stmt.executeQuery(String.format("SHOW TABLES IN `%s`", def))) { while (rs.next()) { tables.add(rs.getString(1)); } } for (String table : tables) { if (schemaTool.isDryRun()) { System.out.println("would drop table " + table); } else { logIfVerbose("dropping table " + table); stmt.execute(String.format("DROP TABLE `%s`.`%s`", def, table)); } } } } catch (SQLException se) { throw new HiveMetaException("Failed to drop databases.", se); } }    }### Answer:
@Test public void testExecutePromptYes() throws Exception { setUpTwoDatabases(); mockPromptWith("y"); uut.execute(); Mockito.verify(stmtMock).execute("DROP DATABASE `mydb` CASCADE"); Mockito.verify(stmtMock).execute(String.format("DROP TABLE `%s`.`table1`", Warehouse.DEFAULT_DATABASE_NAME)); Mockito.verify(stmtMock).execute(String.format("DROP TABLE `%s`.`table2`", Warehouse.DEFAULT_DATABASE_NAME)); Mockito.verify(stmtMock, times(3)).execute(anyString()); }
@Test public void testExecutePromptNo() throws Exception { setUpTwoDatabases(); mockPromptWith("n"); uut.execute(); Mockito.verify(stmtMock, times(0)).execute(anyString()); }
@Test public void testExecuteDryRun() throws Exception { setUpTwoDatabases(); when(uut.schemaTool.isDryRun()).thenReturn(true); uut.execute(); Mockito.verify(stmtMock, times(0)).execute(anyString()); }
@Test public void testExecuteWithYes() throws Exception { setUpTwoDatabases(); uut.yes = true; uut.execute(); Mockito.verify(stmtMock, times(3)).execute(anyString()); }