@Test public void testAddPostToTopic() throws Exception { User user = new User(); Topic topic = new Topic(); Post submittedPost = new Post(); when(userService.getCurrentUser()).thenReturn(user); postService.addPostToTopic(submittedPost, topic); assertSame(user, submittedPost.getUserCreated()); assertSame(submittedPost, topic.getLastPost()); assertSame(topic, submittedPost.getTopic()); }