FetchGroup extends Profiles<FetchGroup> { public FetchGroup addPartContent(MimePath path, EnumSet<Profile> profiles) { PartContentDescriptor newContent = retrieveUpdatedPartContentDescriptor(path, profiles); return new FetchGroup(profiles(), Stream.concat( partContentDescriptors.stream() .filter(descriptor -> !descriptor.path().equals(path)), Stream.of(newContent)) .collect(Guavate.toImmutableSet())); } @VisibleForTesting  FetchGroup(Collection<Profile> content); @VisibleForTesting  FetchGroup(Collection<Profile> content, ImmutableSet<PartContentDescriptor> partContentDescriptors); Set<PartContentDescriptor> getPartContentDescriptors(); FetchGroup addPartContent(MimePath path, EnumSet<Profile> profiles); FetchGroup addPartContent(MimePath path, Profile... profiles); @Override String toString(); @Override final boolean equals(Object o); @Override final int hashCode(); static final FetchGroup MINIMAL; static final FetchGroup HEADERS; static final FetchGroup FULL_CONTENT; static final FetchGroup BODY_CONTENT; }
@Test void addPartContentShouldAddPartContentWhenNotYetSpecified() { int[] path = {12}; assertThat( FetchGroup.MINIMAL .addPartContent(new MimePath(path), EnumSet.noneOf(Profile.class))) .isEqualTo(new FetchGroup(EnumSet.noneOf(Profile.class), ImmutableSet.of(new PartContentDescriptor(new MimePath(path))))); }
@Test void addPartContentShouldUnionDifferentPartContents() { int[] path = {12}; int[] path2 = {13}; assertThat( FetchGroup.MINIMAL .addPartContent(new MimePath(path), EnumSet.noneOf(Profile.class)) .addPartContent(new MimePath(path2), EnumSet.noneOf(Profile.class))) .isEqualTo(new FetchGroup(EnumSet.noneOf(Profile.class), ImmutableSet.of(new PartContentDescriptor(new MimePath(path)), new PartContentDescriptor(new MimePath(path2))))); }
@Test void addPartContentShouldModifyPartContentWhenAlreadySpecified() { int[] path = {12}; assertThat( FetchGroup.MINIMAL .addPartContent(new MimePath(path), EnumSet.noneOf(Profile.class)) .addPartContent(new MimePath(path), Profile.HEADERS)) .isEqualTo(new FetchGroup(EnumSet.noneOf(Profile.class), ImmutableSet.of(new PartContentDescriptor(EnumSet.of(Profile.HEADERS), new MimePath(path))))); }