### Question:
TweeterApplicationRunner implements ApplicationRunner { @Override @Transactional public void run(ApplicationArguments args) throws Exception { Tweeter tweeter = new Tweeter("making", "making@example.com", "password", Instant.now()); if (this.tweeterMapper.countByUsername(tweeter.getUsername()) == 0) { this.tweeterMapper.insert(tweeter); } this.tweetMapper .insert(new Tweet(UUID.randomUUID(), "Demo1", tweeter, Instant.now())); this.tweetMapper .insert(new Tweet(UUID.randomUUID(), "Demo2", tweeter, 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,
									TweeterMapper tweeterMapper); @Override @Transactional void run(ApplicationArguments args);  }### Answer:
@Test void contextLoads(CapturedOutput capture) throws Exception { TweetMapper tweetMapper = mock(TweetMapper.class); TweeterMapper tweeterMapper = mock(TweeterMapper.class); given(tweetMapper.count()).willReturn(2L); given(tweetMapper.insert(any())).willReturn(1); given(tweeterMapper.countByUsername("making")).willReturn(1L); Instant now = Instant.now(); UUID uuid1 = UUID.randomUUID(); UUID uuid2 = UUID.randomUUID(); given(tweetMapper.findAll()) .willReturn(Arrays.asList(new Tweet(uuid1, "Demo1", new Tweeter("making", "making@example.com", "password", now), now), new Tweet(uuid2, "Demo2", new Tweeter("making", "making@example.com", "password", now), now))); TweeterApplicationRunner tweeterApplicationRunner = new TweeterApplicationRunner( tweetMapper, tweeterMapper); tweeterApplicationRunner.run(new DefaultApplicationArguments(new String[]{})); String output = capture.toString(); assertThat(output).contains("Number of tweets: 2"); assertThat(output).contains( "Tweet{uuid=" + uuid1 + ", text='Demo1', tweeter=Tweeter{username='making', email='making@example.com'}, createdAt=" + now + "}"); assertThat(output).contains( "Tweet{uuid=" + uuid2 + ", text='Demo2', tweeter=Tweeter{username='making', email='making@example.com'}, createdAt=" + now + "}"); ; }