### Question:
TransactionalSpamProtectionService extends AbstractTransactionalEntityService<SpamRule, SpamRuleDao> implements SpamProtectionService { @Override public boolean isEmailInBlackList(String email) { if (email == null) return false; List<SpamRule> enabledRules = getDao().getEnabledRules(); for (SpamRule enabledRule : enabledRules) { if (matches(enabledRule.getRegex(), email)) return true; } return false; } TransactionalSpamProtectionService(SpamRuleDao dao); @Override boolean isEmailInBlackList(String email); @Override void saveOrUpdate(SpamRule rule); @Override void deleteRule(long id); @Override List<SpamRule> getAllRules(); @Override SpamRule get(Long id);  }### Answer:
@Test public void shouldReturnTrueIfEmailInBlackList(){ String domain = randomDomain(); String address = alphanumeric(10) + domain; List<SpamRule> spamRules = Collections.singletonList(spamRuleToBlock(domain)); when(dao.getEnabledRules()).thenReturn(spamRules); boolean inBlackList = spamProtectionService.isEmailInBlackList(address); Assert.assertTrue(inBlackList); }
@Test public void shouldReturnFalseIfEmailNotInBlackList(){ String domain = randomDomain(); String address = alphanumeric(10) + domain; List<SpamRule> spamRules = Collections.singletonList(spamRuleToBlock(randomDomain())); when(dao.getEnabledRules()).thenReturn(spamRules); boolean inBlackList = spamProtectionService.isEmailInBlackList(address); Assert.assertFalse(inBlackList); }