public static MusicProtocol.MusicTrack.Builder convertMusicRecordingToTrackBuilder(MusicRecording recording) {
        MusicProtocol.MusicTrack.Builder trackBuilder = MusicProtocol.MusicTrack.newBuilder();

        if (recording == null) {
            // Return an empty track
            // Tracks without metadata will be ignored by importing system.
            return trackBuilder;
        }

        if (!StringUtils.isBlank(recording.getTitle())) {
            trackBuilder.setTitle(recording.getTitle());
        }

        if (!StringUtils.isBlank(recording.getIsrcCode())) {
            trackBuilder.setIsrcCode(recording.getIsrcCode());
        }

        trackBuilder.setDurationMillis(recording.getDurationMillis());

        if (recording.getByArtists() != null && !recording.getByArtists().isEmpty()) {
            List<MusicProtocol.MusicArtist> trackArtists = convertMusicGroupsToMusicArtists(recording.getByArtists());
            if (!trackArtists.isEmpty()) {
                trackBuilder.addAllTrackArtist(trackArtists);
            }
        }

        if (recording.getMusicRelease() != null) {
            trackBuilder.setMusicAlbum(convertMusicReleaseToMusicAlbum(recording.getMusicRelease()));
        }

        trackBuilder.setIsExplicit(recording.getIsExplicit());

        return trackBuilder;
    }
@Test
    public void testConvertMusicRecordingToTrackBuilder() {
        String expectedISRC = "1234567890ab";
        String expectedTitle = "Expected Track Title";
        long expectedDurationMillis = RandomUtils.nextLong();
        String expectedArtistName = "Expected Artist Name";
        MusicGroup musicGroup = new MusicGroup(expectedArtistName);
        String expectedICPN = "1234567890abcdefg";
        String expectedAlbumTitle = "Expected Album Title";
        MusicRelease musicRelease = new MusicRelease(expectedICPN, expectedAlbumTitle, List.of(musicGroup));
        boolean expectedIsExplicit = true;

        // It isn't expected that we would get a null MusicRecording, but we should handle it gracefully if we do.
        MusicProtocol.MusicTrack nullMusicRecordingMusicTrack = AppleMusicPlaylistConverter.convertMusicRecordingToTrackBuilder(null).build();
        Assertions.assertNotNull(nullMusicRecordingMusicTrack);
        Assertions.assertFalse(nullMusicRecordingMusicTrack.hasPlaylistId()); // Base builder has no playlist id
        Assertions.assertFalse(nullMusicRecordingMusicTrack.hasPlaylistPosition()); // Base builder has no playlist position
        Assertions.assertFalse(nullMusicRecordingMusicTrack.hasIsrcCode());
        Assertions.assertFalse(nullMusicRecordingMusicTrack.hasTitle());
        Assertions.assertFalse(nullMusicRecordingMusicTrack.hasDurationMillis());
        Assertions.assertFalse(nullMusicRecordingMusicTrack.hasMusicAlbum());
        Assertions.assertEquals(nullMusicRecordingMusicTrack.getTrackArtistCount(), 0);
        Assertions.assertEquals(nullMusicRecordingMusicTrack.getIsExplicit(), false);


        MusicRecording emptyISRCMusicRecording = new MusicRecording(null, expectedTitle, expectedDurationMillis, musicRelease, List.of(musicGroup), false);
        MusicProtocol.MusicTrack emptyISRCMusicTrack = AppleMusicPlaylistConverter.convertMusicRecordingToTrackBuilder(emptyISRCMusicRecording).build();
        Assertions.assertNotNull(emptyISRCMusicTrack);
        Assertions.assertFalse(emptyISRCMusicTrack.hasPlaylistId()); // Base builder has no playlist id
        Assertions.assertFalse(emptyISRCMusicTrack.hasPlaylistPosition()); // Base builder has no playlist position
        Assertions.assertFalse(emptyISRCMusicTrack.hasIsrcCode());
        Assertions.assertTrue(emptyISRCMusicTrack.hasTitle());
        Assertions.assertEquals(emptyISRCMusicTrack.getTitle(), expectedTitle);
        Assertions.assertTrue(emptyISRCMusicTrack.hasDurationMillis());
        Assertions.assertEquals(emptyISRCMusicTrack.getDurationMillis(), expectedDurationMillis);
        Assertions.assertTrue(emptyISRCMusicTrack.hasMusicAlbum());
        Assertions.assertEquals(emptyISRCMusicTrack.getMusicAlbum().getTitle(), expectedAlbumTitle);
        Assertions.assertEquals(emptyISRCMusicTrack.getTrackArtistCount(), 1);
        Assertions.assertEquals(emptyISRCMusicTrack.getIsExplicit(), false);


        MusicRecording emptyTitleMusicRecording = new MusicRecording(expectedISRC, null, expectedDurationMillis, musicRelease, List.of(musicGroup), false);
        MusicProtocol.MusicTrack emptyTitleMusicTrack = AppleMusicPlaylistConverter.convertMusicRecordingToTrackBuilder(emptyTitleMusicRecording).build();
        Assertions.assertNotNull(emptyTitleMusicTrack);
        Assertions.assertFalse(emptyTitleMusicTrack.hasPlaylistId()); // Base builder has no playlist id
        Assertions.assertFalse(emptyTitleMusicTrack.hasPlaylistPosition()); // Base builder has no playlist position
        Assertions.assertTrue(emptyTitleMusicTrack.hasIsrcCode());
        Assertions.assertEquals(emptyTitleMusicTrack.getIsrcCode(), expectedISRC);
        Assertions.assertFalse(emptyTitleMusicTrack.hasTitle());
        Assertions.assertTrue(emptyTitleMusicTrack.hasDurationMillis());
        Assertions.assertEquals(emptyTitleMusicTrack.getDurationMillis(), expectedDurationMillis);
        Assertions.assertTrue(emptyTitleMusicTrack.hasMusicAlbum());
        Assertions.assertEquals(emptyTitleMusicTrack.getMusicAlbum().getTitle(), expectedAlbumTitle);
        Assertions.assertEquals(emptyTitleMusicTrack.getTrackArtistCount(), 1);
        Assertions.assertEquals(emptyTitleMusicTrack.getIsExplicit(), false);

        MusicRecording emptyMusicReleaseMusicRecording = new MusicRecording(expectedISRC, expectedTitle, expectedDurationMillis, null, List.of(musicGroup), false);
        MusicProtocol.MusicTrack emptyMusicReleaseMusicTrack = AppleMusicPlaylistConverter.convertMusicRecordingToTrackBuilder(emptyMusicReleaseMusicRecording).build();
        Assertions.assertNotNull(emptyMusicReleaseMusicTrack);
        Assertions.assertFalse(emptyMusicReleaseMusicTrack.hasPlaylistId()); // Base builder has no playlist id
        Assertions.assertFalse(emptyMusicReleaseMusicTrack.hasPlaylistPosition()); // Base builder has no playlist position
        Assertions.assertTrue(emptyMusicReleaseMusicTrack.hasIsrcCode());
        Assertions.assertEquals(emptyMusicReleaseMusicTrack.getIsrcCode(), expectedISRC);
        Assertions.assertTrue(emptyMusicReleaseMusicTrack.hasTitle());
        Assertions.assertEquals(emptyMusicReleaseMusicTrack.getTitle(), expectedTitle);
        Assertions.assertTrue(emptyMusicReleaseMusicTrack.hasDurationMillis());
        Assertions.assertEquals(emptyMusicReleaseMusicTrack.getDurationMillis(), expectedDurationMillis);
        Assertions.assertFalse(emptyMusicReleaseMusicTrack.hasMusicAlbum());
        Assertions.assertEquals(emptyMusicReleaseMusicTrack.getTrackArtistCount(), 1);
        Assertions.assertEquals(emptyMusicReleaseMusicTrack.getIsExplicit(), false);

        MusicRecording emptyMusicGroupsMusicRecording = new MusicRecording(expectedISRC, expectedTitle, expectedDurationMillis, musicRelease, List.of(), false);
        MusicProtocol.MusicTrack emptyMusicGroupsMusicTrack = AppleMusicPlaylistConverter.convertMusicRecordingToTrackBuilder(emptyMusicGroupsMusicRecording).build();
        Assertions.assertNotNull(emptyMusicGroupsMusicTrack);
        Assertions.assertFalse(emptyMusicGroupsMusicTrack.hasPlaylistId()); // Base builder has no playlist id
        Assertions.assertFalse(emptyMusicGroupsMusicTrack.hasPlaylistPosition()); // Base builder has no playlist position
        Assertions.assertTrue(emptyMusicGroupsMusicTrack.hasIsrcCode());
        Assertions.assertEquals(emptyMusicGroupsMusicTrack.getIsrcCode(), expectedISRC);
        Assertions.assertTrue(emptyMusicGroupsMusicTrack.hasTitle());
        Assertions.assertEquals(emptyMusicGroupsMusicTrack.getTitle(), expectedTitle);
        Assertions.assertTrue(emptyMusicGroupsMusicTrack.hasDurationMillis());
        Assertions.assertEquals(emptyMusicGroupsMusicTrack.getDurationMillis(), expectedDurationMillis);
        Assertions.assertTrue(emptyMusicGroupsMusicTrack.hasMusicAlbum());
        Assertions.assertEquals(emptyMusicGroupsMusicTrack.getMusicAlbum().getTitle(), expectedAlbumTitle);
        Assertions.assertEquals(emptyMusicGroupsMusicTrack.getTrackArtistCount(), 0);
        Assertions.assertEquals(emptyMusicGroupsMusicTrack.getIsExplicit(), false);

        MusicRecording musicRecording = new MusicRecording(expectedISRC, expectedTitle, expectedDurationMillis, musicRelease, List.of(musicGroup), expectedIsExplicit);
        MusicProtocol.MusicTrack musicTrack = AppleMusicPlaylistConverter.convertMusicRecordingToTrackBuilder(musicRecording).build();
        Assertions.assertNotNull(musicTrack);
        Assertions.assertFalse(musicTrack.hasPlaylistId()); // Base builder has no playlist id
        Assertions.assertFalse(musicTrack.hasPlaylistPosition()); // Base builder has no playlist position
        Assertions.assertTrue(musicTrack.hasIsrcCode());
        Assertions.assertEquals(musicTrack.getIsrcCode(), expectedISRC);
        Assertions.assertTrue(musicTrack.hasTitle());
        Assertions.assertEquals(musicTrack.getTitle(), expectedTitle);
        Assertions.assertTrue(musicTrack.hasDurationMillis());
        Assertions.assertEquals(musicTrack.getDurationMillis(), expectedDurationMillis);
        Assertions.assertTrue(musicTrack.hasMusicAlbum());
        Assertions.assertEquals(musicTrack.getMusicAlbum().getTitle(), expectedAlbumTitle);
        Assertions.assertEquals(musicTrack.getTrackArtistCount(), 1);
        Assertions.assertEquals(musicTrack.getIsExplicit(), expectedIsExplicit);
    }