### Question:
TransactionalBranchLastPostService implements BranchLastPostService { @Override public void refreshLastPostInBranch(Branch branch) { Post lastPostOfBranch = postDao.getLastPostFor(branch); branch.setLastPost(lastPostOfBranch); branchDao.saveOrUpdate(branch); } TransactionalBranchLastPostService(PostDao postDao, BranchDao branchDao); @Override void refreshLastPostInBranch(Branch branch);  }### Answer:
@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); }