### Question:
TransactionalPrivateMessageService extends AbstractTransactionalEntityService<PrivateMessage, PrivateMessageDao> implements PrivateMessageService { @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") public void saveDraft(long id, JCUser userTo, String title, String body, JCUser userFrom) { PrivateMessage pm; if (this.getDao().isExist(id)) { pm = this.getDao().get(id); pm.setUserTo(userTo); pm.setTitle(title); pm.setBody(body); } else { pm = new PrivateMessage(userTo, userFrom, title, body); pm.setStatus(PrivateMessageStatus.DRAFT); } this.getDao().saveOrUpdate(pm); JCUser user = userService.getCurrentUser(); securityService.createAclBuilder().grant(GeneralPermission.READ).to(user).on(pm).flush(); securityService.createAclBuilder().grant(GeneralPermission.WRITE).to(user).on(pm).flush(); logger.debug("Updated private message draft. Message id={}", pm.getId()); } TransactionalPrivateMessageService(PrivateMessageDao pmDao,
                                              SecurityService securityService,
                                              UserService userService,
                                              UserDataCacheService userDataCache,
                                              MailService mailService,
                                              JCommuneProperty sendingNotificationsEnabledProperty); @Override Page<PrivateMessage> getInboxForCurrentUser(String page); @Override Page<PrivateMessage> getOutboxForCurrentUser(String page); @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") PrivateMessage sendMessage(String title, String body, JCUser recipient, JCUser userFrom); @Override Page<PrivateMessage> getDraftsForCurrentUser(String page); @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") void saveDraft(long id, JCUser userTo, String title, String body, JCUser userFrom); @Override int currentUserNewPmCount(); @Override @PreAuthorize("hasPermission(#userFrom.id, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") PrivateMessage sendDraft(long id, String title, String body,
                                    JCUser recipient, JCUser userFrom); @Override @PreAuthorize("hasPermission(#id, 'PRIVATE_MESSAGE', 'GeneralPermission.READ')") PrivateMessage get(Long id); @Override String delete(List<Long> ids); @Override @PreAuthorize("hasPermission(#senderId, 'USER', 'ProfilePermission.SEND_PRIVATE_MESSAGES')") void checkPermissionsToSend(Long senderId); static final int DEFAULT_MESSAGE_COUNT; }### Answer:
@Test public void testSaveDraft() throws NotFoundException { JCUser recipient = new JCUser("name", "example@example.com", "pwd"); when(securityService.<User>createAclBuilder()).thenReturn(aclBuilder); pmService.saveDraft(PM_ID, recipient, "title", "body", JC_USER); verify(pmDao).saveOrUpdate(any(PrivateMessage.class)); verify(aclBuilder).grant(GeneralPermission.WRITE); verify(aclBuilder).grant(GeneralPermission.READ); verify(aclBuilder, times(2)).on(any(PrivateMessage.class)); }