### Question:
MetaDataGenerator { public void generate(String destination){ MetaData metadata = new MetaData(); for (MetaDataTrackInfo trackInfo : metaDataTrackInfos) { if(trackInfo.getTrackId().equalsIgnoreCase(stationTrack.getFile())) { if (trackInfo.getTrackType().contains("melodic")) { metadata.addTrack("0" + trackInfo.getTrackType()+"_"+(stationTrack.getSelectedMelody()-1) + ".mid"); } else { metadata.addTrack("0" + trackInfo.getTrackType() + ".mid"); } metadata.setVersion(trackInfo.getVersion()); } } for(MetaDataChordInfo chordInfo : metaDataChordInfos){ if(chordInfo.getTrackId().equalsIgnoreCase(stationTrack.getFile())){ String[] chords = chordInfo.getPartChords().split("-"); MetaDataChords metaDataChords = new MetaDataChords(); metaDataChords.setChords(Arrays.asList(chords)); metaDataChords.setPartKey(chordInfo.getPartKey()); metaDataChords.setTrackId(stationTrack.getFile()); metadata.addChords(chordInfo.getPartType(), metaDataChords); metadata.setKey(chordInfo.getTrackKey()); } } ObjectMapper mapper = new ObjectMapper(); try { String json = mapper.writeValueAsString(metadata); System.out.println(json); FileOutputStream fileOutputStream = new FileOutputStream(destination); mapper.writeValue(fileOutputStream, metadata); fileOutputStream.close(); } catch (Exception e) { e.printStackTrace(); } } MetaDataGenerator(AppConfigs appConfigs,
                             StationTrack stationTrack,
                             List<MetaDataTrackInfo> metaDataTrackInfos,
                             List<MetaDataChordInfo> metaDataChordInfos); void generate(String destination);  }### Answer:
@Test public void shouldGenerateMetadataFile() throws IOException { tempDir = Files.createTempDir(); Path metaDataDestination = Paths.get(tempDir.getAbsolutePath(), "metadata.json"); System.out.println("PATH: " + metaDataDestination.toString()); metaDataGenerator.generate(metaDataDestination.toString()); assertThat(metaDataDestination.toFile().exists()).isTrue(); MetaData metaData = new ObjectMapper().readValue(metaDataDestination.toFile(), MetaData.class); assertThat(metaData.getTracks()).hasSize(2); assertThat(metaData.getTracks()).contains("0melodic_0.mid"); MetaDataChords verse = metaData.getChords().get("verse"); MetaDataChords chorus = metaData.getChords().get("chorus"); assertThat(verse.getChords()).hasSize(4); assertThat(verse.getChords()).contains("cmaj","dmin","dmin","gmaj"); assertThat(verse.getPartKey()).isEqualToIgnoringCase("c"); assertThat(chorus.getChords()).hasSize(4); assertThat(chorus.getChords()).contains("g", "g", "dmin", "dmaj"); assertThat(chorus.getPartKey()).isEqualToIgnoringCase("d"); assertThat(metaData.getVersion()).isEqualToIgnoringCase("2.1"); assertThat(metaData.getKey()).isEqualToIgnoringCase("g"); }