### Question:
TransactionalLastReadPostService implements LastReadPostService, PluginLastReadPostService { @Override @PreAuthorize("hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.VIEW_TOPICS')") public void markTopicAsRead(Topic topic) { JCUser current = userService.getCurrentUser(); if (!current.isAnonymous()) { saveLastReadPost(current, topic, topic.getLastPost()); } } TransactionalLastReadPostService(
            UserService userService,
            LastReadPostDao lastReadPostDao,
            UserDao userDao,
            BranchReadedMarkerDao branchReadedMarkerDao); @Override List<Topic> fillLastReadPostForTopics(List<Topic> topics); @Override @PreAuthorize("hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.VIEW_TOPICS')") void markTopicPageAsRead(Topic topic, int pageNum); @Override @PreAuthorize("hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.VIEW_TOPICS')") void markTopicAsRead(Topic topic); @Override @PreAuthorize("hasPermission(#branch.id, 'BRANCH', 'BranchPermission.VIEW_TOPICS')") void markAllTopicsAsRead(Branch branch); @Override void markAllForumAsReadForCurrentUser();  }### Answer:
@Test public void authenticatedUserShouldHaveAbilityToMarkTopicAsRead() { Topic topic = this.createTestTopic(); when(userService.getCurrentUser()).thenReturn(user); lastReadPostService.markTopicAsRead(topic); verify(lastReadPostDao).saveOrUpdate(argThat(new LastReadPostMatcher(topic, topic.getLastPost().getCreationDate()))); }
@Test public void anonymousUserShouldNotHaveAbilityToMarkTopicAsRead() { when(userService.getCurrentUser()).thenReturn(new AnonymousUser()); Topic topic = this.createTestTopic(); lastReadPostService.markTopicAsRead(topic); verifyZeroInteractions(lastReadPostDao); }
@Test public void markTopicAsReadShouldReupdateLastReadPostInRepositoryIfLastReadDateIsNewer() { Topic topic = this.createTestTopic(); LastReadPost post = new LastReadPost(user, topic, new DateTime(1L)); when(userService.getCurrentUser()).thenReturn(user); when(lastReadPostDao.getLastReadPost(user, topic)).thenReturn(post); lastReadPostService.markTopicAsRead(topic); verify(lastReadPostDao).saveOrUpdate(argThat( new LastReadPostMatcher(topic, topic.getLastPost().getCreationDate()))); }
@Test public void markTopicAsReadShouldNotReupdateLastReadPostInRepositoryIfLastReadDateIsNotNew() { Topic topic = this.createTestTopic(); LastReadPost post = new LastReadPost(user, topic, topic.getLastPost().getCreationDate()); when(userService.getCurrentUser()).thenReturn(user); when(lastReadPostDao.getLastReadPost(user, topic)).thenReturn(post); lastReadPostService.markTopicAsRead(topic); verify(lastReadPostDao, never()).saveOrUpdate(argThat( new LastReadPostMatcher(topic, topic.getLastPost().getCreationDate()))); }