### Question:
SongsRepository { public Optional<Song> getSong(final String songIdentifier) { DynamoDBSongItem songItem = dynamoDBMapper.load(DynamoDBSongItem.class, songIdentifier); if (songItem == null) { return Optional.empty(); } return Optional.of(songItem.toSong()); } SongsRepository(final DynamoDBMapper dynamoDBMapper); Optional<Song> getSong(final String songIdentifier); void storeSong(final Song song);  }### Answer:
@Test public void whenSongExistsInDynamo_RepositoryReturnsIt() { when(mockDynamoDBMapper.load(DynamoDBSongItem.class, SONG_ID)) .thenReturn(SONG_ITEM); Optional<Song> optionalSong = songsRepository.getSong(SONG_ID); assertTrue(optionalSong.isPresent()); Song song = optionalSong.get(); assertEquals(SONG_ID, song.getId()); assertEquals(AUTHOR_ID, song.getAuthorID()); assertEquals(SONG_RELEASE_DATE, song.getReleaseDate().toInstant().toEpochMilli()); assertEquals(SONG_DURATION_IN_SECONDS, song.getDurationInSeconds()); assertEquals(SONG_ARTIFACT_URI, song.getArtifactUri()); }
@Test public void whenSongDoesNotExistInDynamo_RepositoryReturnsEmptyOptional() { when(mockDynamoDBMapper.load(DynamoDBSongItem.class, SONG_ID)) .thenReturn(null); Optional<Song> optionalSong = songsRepository.getSong(SONG_ID); assertFalse(optionalSong.isPresent()); }