MySQLDataSourceChecker extends AbstractDataSourceChecker { @Override public void checkPrivilege(final Collection<? extends DataSource> dataSources) { for (DataSource each : dataSources) { checkPrivilege(each); } }  @Override void checkPrivilege(final Collection<? extends DataSource> dataSources); @Override void checkVariable(final Collection<? extends DataSource> dataSources);  }
@Test public void assertCheckPrivilegeWithParticularSuccess() throws SQLException { when(resultSet.next()).thenReturn(true); when(resultSet.getString(1)).thenReturn("GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '%'@'%'"); dataSourceChecker.checkPrivilege(dataSources); verify(preparedStatement, Mockito.times(1)).executeQuery(); }
@Test public void assertCheckPrivilegeWithAllSuccess() throws SQLException { when(resultSet.next()).thenReturn(true); when(resultSet.getString(1)).thenReturn("GRANT ALL PRIVILEGES CLIENT ON *.* TO '%'@'%'"); dataSourceChecker.checkPrivilege(dataSources); verify(preparedStatement, Mockito.times(1)).executeQuery(); }
@Test(expected = PrepareFailedException.class) public void assertCheckPrivilegeLackPrivileges() throws SQLException { when(resultSet.next()).thenReturn(false); dataSourceChecker.checkPrivilege(dataSources); }
@Test(expected = PrepareFailedException.class) public void assertCheckPrivilegeFailure() throws SQLException { when(resultSet.next()).thenThrow(new SQLException("")); dataSourceChecker.checkPrivilege(dataSources); }