### Question:
TweeterApplicationRunner implements ApplicationRunner { @Override @Transactional public void run(ApplicationArguments args) throws Exception { this.tweetMapper .insert(new Tweet(UUID.randomUUID(), "Demo1", "making", Instant.now())); this.tweetMapper .insert(new Tweet(UUID.randomUUID(), "Demo2", "making", Instant.now())); long count = this.tweetMapper.count(); System.out.println("Number of tweets: " + count); List<Tweet> tweets = this.tweetMapper.findAll(); tweets.forEach(tweet -> System.out.println(tweet)); } TweeterApplicationRunner(TweetMapper tweetMapper); @Override @Transactional void run(ApplicationArguments args);  }### Answer:
@Test void contextLoads(CapturedOutput capture) throws Exception { TweetMapper tweetMapper = mock(TweetMapper.class); given(tweetMapper.count()).willReturn(2L); given(tweetMapper.insert(any())).willReturn(1); Instant now = Instant.now(); UUID uuid1 = UUID.randomUUID(); UUID uuid2 = UUID.randomUUID(); given(tweetMapper.findAll()) .willReturn(Arrays.asList(new Tweet(uuid1, "test1", "making", now), new Tweet(uuid2, "test2", "making", now))); TweeterApplicationRunner tweeterApplicationRunner = new TweeterApplicationRunner( tweetMapper); tweeterApplicationRunner.run(new DefaultApplicationArguments(new String[] {})); String output = capture.toString(); assertThat(output).contains("Number of tweets: 2"); assertThat(output).contains("Tweet{uuid=" + uuid1 + ", text='test1', username='making', createdAt=" + now + "}"); assertThat(output).contains("Tweet{uuid=" + uuid2 + ", text='test2', username='making', createdAt=" + now + "}"); }
@Test void contextLoads(CapturedOutput capture) throws Exception { TweetMapper tweetMapper = mock(TweetMapper.class); given(tweetMapper.count()).willReturn(2L); Instant now = Instant.now(); UUID uuid1 = UUID.randomUUID(); UUID uuid2 = UUID.randomUUID(); given(tweetMapper.findAll()) .willReturn(Arrays.asList(new Tweet(uuid1, "test1", "making", now), new Tweet(uuid2, "test2", "making", now))); TweeterApplicationRunner tweeterApplicationRunner = new TweeterApplicationRunner( tweetMapper); tweeterApplicationRunner.run(new DefaultApplicationArguments(new String[] {})); String output = capture.toString(); assertThat(output).contains("Number of tweets: 2"); assertThat(output).contains("Tweet{uuid=" + uuid1 + ", text='test1', username='making', createdAt=" + now + "}"); assertThat(output).contains("Tweet{uuid=" + uuid2 + ", text='test2', username='making', createdAt=" + now + "}"); }