TitleExtractor implements MetadataTransform { @Override public Track transform(Track track) { String title = null; String artist = null; for (String separator : SEPARATORS) { String[] components = track.track().split(Pattern.quote(separator)); if (components.length > 1) { String[] titleComponents = Arrays.copyOfRange(components, 1, components.length); artist = components[0]; title = Joiner.on(separator).join(titleComponents); break; } } if (title == null || artist == null) { return track; } title = title.trim(); artist = artist.trim(); return track.toBuilder().artist(artist).track(title).build(); }  @Override Track transform(Track track);  }
@Test public void transform_doesNotModifyWhenNoSeparator() { Track input = Track.builder().track("Some Title").artist("").build(); Track output = titleExtractor.transform(input); assertThat(output.track()).isEqualTo("Some Title"); }