branchLastPostService = new TransactionalBranchLastPostService(postDao, branchDao);
}
@Test
public void testUpdateLastPostInBranchWhenPostDeletedIsLastPost() {
Branch branchOfDeletedPost = new Branch(BRANCH_NAME, BRANCH_DESCRIPTION);
Post expectedNewLastPost = new Post(null, null);
when(postDao.getLastPostFor(branchOfDeletedPost))
.thenReturn(expectedNewLastPost);
branchLastPostService.refreshLastPostInBranch(branchOfDeletedPost);
Post actualNewLastPost = branchOfDeletedPost.getLastPost();
assertEquals(actualNewLastPost, expectedNewLastPost, "Incorrect last post was setted.");
verify(branchDao).saveOrUpdate(branchOfDeletedPost);
verify(postDao).getLastPostFor(branchOfDeletedPost);
}