Source:
<code>public void testSendQuotaAlert() throws UnsupportedEncodingException, MessagingException { Mockito.doCallRealMethod().when(quotaAlertManager).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); AccountVO account = new AccountVO(); account.setId(2L); account.setDomainId(1L); account.setType(Account.ACCOUNT_TYPE_NORMAL); account.setAccountName("admin"); account.setUuid("uuid"); QuotaAccountVO quotaAccount = new QuotaAccountVO(2L); quotaAccount.setQuotaBalance(new BigDecimal(404)); quotaAccount.setQuotaMinBalance(new BigDecimal(100)); quotaAccount.setQuotaBalanceDate(new Date()); quotaAccount.setQuotaAlertDate(null); quotaAccount.setQuotaEnforce(0); QuotaAlertManagerImpl.DeferredQuotaEmail email = new QuotaAlertManagerImpl.DeferredQuotaEmail(account, quotaAccount, new BigDecimal(100), QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW); QuotaEmailTemplatesVO quotaEmailTemplatesVO = new QuotaEmailTemplatesVO(); quotaEmailTemplatesVO.setTemplateSubject("Low quota"); quotaEmailTemplatesVO.setTemplateBody("Low quota {{accountID}}"); List<QuotaEmailTemplatesVO> emailTemplates = new ArrayList<>(); emailTemplates.add(quotaEmailTemplatesVO); Mockito.when(quotaEmailTemplateDao.listAllQuotaEmailTemplates(Mockito.anyString())).thenReturn(emailTemplates); DomainVO domain = new DomainVO(); domain.setUuid("uuid"); domain.setName("/domain"); Mockito.when(domainDao.findByIdIncludingRemoved(Mockito.anyLong())).thenReturn(new DomainVO()); UserVO user = new UserVO(); user.setUsername("user1"); user.setEmail("user1@apache.org"); List<UserVO> users = new ArrayList<>(); users.add(user); Mockito.when(userDao.listByAccount(Mockito.anyLong())).thenReturn(users); quotaAlertManager.sendQuotaAlert(email); <START> Mockito.verify(emailQuotaAlert, Mockito.times(1)).sendQuotaAlert(Mockito.anyList(), Mockito.anyString(), Mockito.anyString()); <END> }</code><technical_language>asserts in this test method. do verify successful send of quota alert simply determining throw exception</technical_language>

Target:
public void testSendQuotaAlert() throws UnsupportedEncodingException, MessagingException { Mockito.doCallRealMethod().when(quotaAlertManager).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); AccountVO account = new AccountVO(); account.setId(2L); account.setDomainId(1L); account.setType(Account.ACCOUNT_TYPE_NORMAL); account.setAccountName("admin"); account.setUuid("uuid"); QuotaAccountVO quotaAccount = new QuotaAccountVO(2L); quotaAccount.setQuotaBalance(new BigDecimal(404)); quotaAccount.setQuotaMinBalance(new BigDecimal(100)); quotaAccount.setQuotaBalanceDate(new Date()); quotaAccount.setQuotaAlertDate(null); quotaAccount.setQuotaEnforce(0); QuotaAlertManagerImpl.DeferredQuotaEmail email = new QuotaAlertManagerImpl.DeferredQuotaEmail(account, quotaAccount, new BigDecimal(100), QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW); QuotaEmailTemplatesVO quotaEmailTemplatesVO = new QuotaEmailTemplatesVO(); quotaEmailTemplatesVO.setTemplateSubject("Low quota"); quotaEmailTemplatesVO.setTemplateBody("Low quota {{accountID}}"); List<QuotaEmailTemplatesVO> emailTemplates = new ArrayList<>(); emailTemplates.add(quotaEmailTemplatesVO); Mockito.when(quotaEmailTemplateDao.listAllQuotaEmailTemplates(Mockito.anyString())).thenReturn(emailTemplates); DomainVO domain = new DomainVO(); domain.setUuid("uuid"); domain.setName("/domain"); Mockito.when(domainDao.findByIdIncludingRemoved(Mockito.anyLong())).thenReturn(new DomainVO()); UserVO user = new UserVO(); user.setUsername("user1"); user.setEmail("user1@apache.org"); List<UserVO> users = new ArrayList<>(); users.add(user); Mockito.when(userDao.listByAccount(Mockito.anyLong())).thenReturn(users); quotaAlertManager.sendQuotaAlert(email); assertTrue(email.getSendDate()!= null); Mockito.verify(emailQuotaAlert, Mockito.times(1)).sendQuotaAlert(Mockito.anyList(), Mockito.anyString(), Mockito.anyString()); }