### Question:
PhylipWriter extends AbstractSpectreWriter { @Override public void writeDistanceMatrix(File outFile, DistanceMatrix distanceMatrix) throws IOException { final int n = distanceMatrix.size(); StringBuilder fileContent = new StringBuilder(10 * n * n); fileContent.append(n); fileContent.append("\n"); IdentifierList nameSortedTaxa = distanceMatrix.getTaxa(new Identifier.NameComparator()); double[][] matrix = distanceMatrix.getMatrix(new Identifier.NameComparator()); for (int i = 0; i < n; i++) { fileContent.append(nameSortedTaxa.get(i).getName()); fileContent.append(" "); fileContent.append(CollectionUtils.doubleArrayToString(matrix[i], " ")); fileContent.append("\n"); } FileUtils.writeStringToFile(outFile, fileContent.toString(), "UTF-8"); }  @Override void writeDistanceMatrix(File outFile, DistanceMatrix distanceMatrix);  }### Answer:
@Test public void testSaveDistanceMatrix() throws IOException { File outputDir = temp.newFolder("dmTest"); File outputFile = new File(outputDir, "rdm10.phy"); DistanceMatrix rdm = new RandomDistanceGenerator().generateDistances(10); new PhylipWriter().writeDistanceMatrix(outputFile, rdm); List<String> lines = FileUtils.readLines(outputFile, "UTF-8"); assertTrue(lines.size() == 11); assertTrue(lines.get(1).split(" ").length == 11); }