PedFiles { public static Pedigree parsePedigree(Stream<String> lines) { Set<Individual> individuals = lines .filter(line -> !line.startsWith("#")) .map(toIndividual()) .collect(ImmutableSet.toImmutableSet()); return Pedigree.of(individuals); } private  PedFiles(); static Pedigree readPedigree(Path pedFile); static Pedigree parsePedigree(Stream<String> lines);  }
@Test public void canParsePedigreeWithSpaces() { Pedigree.Individual manuel = Pedigree.Individual.builder() .familyId("1") .id("Manuel") .sex(Sex.MALE) .status(Status.AFFECTED) .build(); Pedigree instance = PedFiles.parsePedigree(Stream.of("1\tManuel 0\t0 \t1\t2 words\t more words")); assertThat(instance, equalTo(Pedigree.of(manuel))); }
@Test public void parsePedigreeNotEnoughFields() { assertThrows(RuntimeException.class, () -> PedFiles.parsePedigree(Stream.of("1\tManuel\t0\t0\t1"))); }
@Test public void parsePedigreeEmptyId() { assertThrows(RuntimeException.class, () -> PedFiles.parsePedigree(Stream.of("1\t\t\t0\t1\t2"))); }
@Test public void parsePedigreeEmptyParentId() { assertThrows(RuntimeException.class, () -> PedFiles.parsePedigree(Stream.of("1\tManuel\t\t0\t1\t2"))); }
@Test public void parsePedigreeIllegalStatus() { assertThrows(RuntimeException.class, () -> PedFiles.parsePedigree(Stream.of("1\tManuel\t0\t0\t1\t7"))); }
@Test public void parsePedigreeUnknownStatus() { Pedigree.Individual zero = PedFiles.parsePedigree(Stream.of("1\tManuel\t0\t0\t1\t0")) .getIndividuals().stream().findFirst().orElse(Pedigree.Individual.builder().build()); assertThat(zero.getStatus(), equalTo(Status.UNKNOWN)); Pedigree.Individual minusNine = PedFiles.parsePedigree(Stream.of("1\tManuel\t0\t0\t1\t-9")) .getIndividuals().stream().findFirst().orElse(Pedigree.Individual.builder().build()); assertThat(minusNine.getStatus(), equalTo(Status.UNKNOWN)); }
@Test public void parsePedigreeUnknownSex() { Pedigree.Individual zero = PedFiles.parsePedigree(Stream.of("1\tManuel\t0\t0\t0\t0")) .getIndividuals().stream().findFirst().orElse(Pedigree.Individual.builder().build()); assertThat(zero.getSex(), equalTo(Sex.UNKNOWN)); Pedigree.Individual minusNine = PedFiles.parsePedigree(Stream.of("1\tManuel\t0\t0\t42\t0")) .getIndividuals().stream().findFirst().orElse(Pedigree.Individual.builder().build()); assertThat(minusNine.getSex(), equalTo(Sex.UNKNOWN)); }