### Question:
DbNodeServiceImpl extends AbstractBaseService<DbNodeEntity> implements CacheUpdateService, DbNodeService, TimerService, PortalTimerService { protected void checkSlave(DbNodeEntity dbNodeEntity) throws SQLException { if (hasSlave(dbNodeEntity)) { DruidDataSource dataSource = dataSourceFactory.createDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername(dbNodeEntity.getDbUserNameBak()); dataSource.setPassword(dbNodeEntity.getDbPassBak()); dataSource.setUrl(getCon(dbNodeEntity, false)); dataSource.setInitialSize(1); dataSource.setMinIdle(0); dataSource.setMaxActive(1); List<Filter> filters = new ArrayList<Filter>(); filters.add(new DruidConnectionFilter(DbUtil.getDbIp(dataSource.getUrl()))); dataSource.setProxyFilters(filters); dataSource.init(); dataSource = null; } }  @Override void start(); @Override void updateCache(); @Override void checkDataSource(DbNodeEntity dbNodeEntity); @Override boolean hasSlave(DbNodeEntity dbNodeEntity); @Override void createDataSource(DbNodeEntity t1); void initDataSource(DbNodeEntity t1, String key, Map<String, DataSource> dataMap, boolean isMaster,
							   Transaction transaction); @Override Map<Long, DbNodeEntity> getCache(); @Override Map<String, List<DbNodeEntity>> getCacheByIp(); @Override void forceUpdateCache(); @PreDestroy @Override void stop(); @Override DataSource getDataSource(long id, boolean isMaster); @Override String info(); @Override Map<String, DataSource> getDataSource(); @Override void startPortal(); @Override void stopPortal(); @Override String getCacheJson();  }### Answer:
@Test public void checkSlaveTest() throws SQLException { DruidDataSource dataSource = mock(DruidDataSource.class); DbNodeServiceImpl.DataSourceFactory dataSourceFactory = new DbNodeServiceImpl.DataSourceFactory() { @Override public DruidDataSource createDataSource() { return dataSource; } }; dbNodeServiceImpl.setDataSourceFactory(dataSourceFactory); DbNodeEntity dbNodeEntity = new DbNodeEntity(); dbNodeEntity.setIpBak("faf"); dbNodeEntity.setDbUserNameBak("fa"); dbNodeEntity.setDbPassBak("faf"); dbNodeEntity.setPortBak(3); doThrow(new SQLException("tet")).when(dataSource).init(); boolean flag = false; try { dbNodeServiceImpl.checkSlave(dbNodeEntity); } catch (Exception e) { flag = true; } assertEquals(true, flag); flag = false; reset(dataSource); try { dbNodeServiceImpl.checkSlave(dbNodeEntity); } catch (Exception e) { flag = true; } assertEquals(false, flag); flag = false; dbNodeEntity.setDbPassBak(""); try { dbNodeServiceImpl.checkSlave(dbNodeEntity); } catch (Exception e) { flag = true; } assertEquals(false, flag); }