DistributedLockServiceMySqlImpl implements DistributedLockService { @Override public boolean tryLock(String key) { return executeScalar(GET_LOCK_TEMPLATE, key, 1); }  @Autowired(required = false) @Qualifier("distLockingDataSource") void setSmartDataSource(DataSource dataSource); @Override boolean tryLock(String key); @Override boolean tryReleaseLock(String key); void setJdbcTemplate(JdbcTemplate jdbcTemplate);  }
@Test public void testTryLock() { when(service.jdbcTemplate.queryForObject(DistributedLockServiceMySqlImpl.GET_LOCK_TEMPLATE, new Object[]{"key1"},Integer.class)).thenReturn( 1); service.tryLock("key1"); verify(service.jdbcTemplate).queryForObject( DistributedLockServiceMySqlImpl.GET_LOCK_TEMPLATE, new Object[]{"key1"},Integer.class); }