This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 2b6c925ca951190612f24df98ff5e17fe4d94637 Author: Benoit Tellier <[email protected]> AuthorDate: Tue Dec 10 10:32:05 2019 +0700 [Refactoring] FetchData: Provide a builder This allows to have FetchData immutable --- .../apache/james/imap/api/message/FetchData.java | 188 ++++++++++----------- .../imap/decode/parser/FetchCommandParser.java | 58 ++++--- .../james/imap/message/request/FetchRequest.java | 3 - .../imap/processor/fetch/FetchDataConverter.java | 5 +- .../james/imap/processor/fetch/FetchProcessor.java | 23 ++- .../imap/processor/fetch/FetchResponseBuilder.java | 19 ++- .../parser/FetchCommandParserPartialFetchTest.java | 14 +- .../processor/fetch/FetchDataConverterTest.java | 43 ++--- 8 files changed, 173 insertions(+), 180 deletions(-) diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java index 3459a63..3a4b305 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.james.imap.api.message; +import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; import java.util.HashSet; @@ -28,137 +29,118 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; public class FetchData { - enum Item { - FLAGS, - UID, - INTERNAL_DATE, - SIZE, - ENVELOPE, - BODY, - BODY_STRUCTURE, - MODSEQ, - } - - private final EnumSet<Item> itemToFetch = EnumSet.noneOf(Item.class); - private final Set<BodyFetchElement> bodyElements = new HashSet<>(); - - private boolean setSeen = false; - private long changedSince = -1; - private boolean vanished; + public static class Builder { + public static Builder from(FetchData fetchData) { + return builder() + .fetch(fetchData.itemToFetch) + .vanished(fetchData.vanished) + .changedSince(fetchData.changedSince) + .addBodyElements(fetchData.bodyElements) + .seen(fetchData.setSeen); + } - public Collection<BodyFetchElement> getBodyElements() { - return bodyElements; - } + private EnumSet<Item> itemToFetch = EnumSet.noneOf(Item.class); + private Set<BodyFetchElement> bodyElements = new HashSet<>(); + private boolean setSeen = false; + private long changedSince = -1; + private boolean vanished; - public boolean isBody() { - return itemToFetch.contains(Item.BODY); - } + public Builder fetch(Item... item) { + return fetch(Arrays.asList(item)); + } - public FetchData fetchBody() { - itemToFetch.add(Item.BODY); - return this; - } + public Builder fetch(Collection<Item> items) { + itemToFetch.addAll(items); + return this; + } - public boolean isBodyStructure() { - return itemToFetch.contains(Item.BODY_STRUCTURE); - } + public Builder changedSince(long changedSince) { + this.changedSince = changedSince; + return fetch(Item.MODSEQ); + } - public FetchData fetchBodyStructure() { - itemToFetch.add(Item.BODY_STRUCTURE); - return this; - } + /** + * Set to true if the VANISHED FETCH modifier was used as stated in <code>QRESYNC</code> extension + */ + public Builder vanished(boolean vanished) { + this.vanished = vanished; + return this; + } - public boolean isEnvelope() { - return itemToFetch.contains(Item.ENVELOPE); - } + public Builder add(BodyFetchElement element, boolean peek) { + if (!peek) { + setSeen = true; + } + bodyElements.add(element); + return this; + } - public FetchData fetchEnvelope() { - itemToFetch.add(Item.ENVELOPE); - return this; - } + private Builder addBodyElements(Collection<BodyFetchElement> elements) { + bodyElements.addAll(elements); + return this; + } - public boolean isFlags() { - return itemToFetch.contains(Item.FLAGS); - } + private Builder seen(boolean setSeen) { + this.setSeen = setSeen; + return this; + } - public FetchData fetchFlags() { - itemToFetch.add(Item.FLAGS); - return this; + public FetchData build() { + return new FetchData(itemToFetch, bodyElements, setSeen, changedSince, vanished); + } } - public boolean isInternalDate() { - return itemToFetch.contains(Item.INTERNAL_DATE); + public enum Item { + FLAGS, + UID, + INTERNAL_DATE, + SIZE, + ENVELOPE, + BODY, + BODY_STRUCTURE, + MODSEQ, } - public FetchData fetchInternalDate() { - itemToFetch.add(Item.INTERNAL_DATE); - return this; + public static Builder builder() { + return new Builder(); } - public boolean isSize() { - return itemToFetch.contains(Item.SIZE); - } + private final EnumSet<Item> itemToFetch; + private final Set<BodyFetchElement> bodyElements; + private final boolean setSeen; + private final long changedSince; + private final boolean vanished; - public FetchData fetchSize() { - itemToFetch.add(Item.SIZE); - return this; + private FetchData(EnumSet<Item> itemToFetch, Set<BodyFetchElement> bodyElements, boolean setSeen, long changedSince, boolean vanished) { + this.itemToFetch = EnumSet.copyOf(itemToFetch); + this.bodyElements = ImmutableSet.copyOf(bodyElements); + this.setSeen = setSeen; + this.changedSince = changedSince; + this.vanished = vanished; } - public boolean isUid() { - return itemToFetch.contains(Item.UID); + public Collection<BodyFetchElement> getBodyElements() { + return bodyElements; } - public FetchData fetchUid() { - itemToFetch.add(Item.UID); - return this; + public boolean contains(Item item) { + return itemToFetch.contains(item); } public boolean isSetSeen() { return setSeen; } - - - public boolean isModSeq() { - return itemToFetch.contains(Item.MODSEQ); - } - - public FetchData fetchModSeq() { - itemToFetch.add(Item.MODSEQ); - return this; - } - - public FetchData setChangedSince(long changedSince) { - this.changedSince = changedSince; - itemToFetch.add(Item.MODSEQ); - return this; - } public long getChangedSince() { return changedSince; } /** - * Set to true if the VANISHED FETCH modifier was used as stated in <code>QRESYNC</code> extension - */ - public FetchData setVanished(boolean vanished) { - this.vanished = vanished; - return this; - } - - /** * Return true if the VANISHED FETCH modifier was used as stated in <code>QRESYNC<code> extension */ public boolean getVanished() { return vanished; } - - public FetchData add(BodyFetchElement element, boolean peek) { - if (!peek) { - setSeen = true; - } - bodyElements.add(element); - return this; - } @Override public final int hashCode() { @@ -181,16 +163,16 @@ public class FetchData { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("flags", isFlags()) - .add("uid", isUid()) - .add("internalDate", isInternalDate()) - .add("size", isSize()) - .add("envelope", isEnvelope()) - .add("body", isBody()) - .add("bodyStructure", isBodyStructure()) + .add("flags", contains(Item.FLAGS)) + .add("uid", contains(Item.UID)) + .add("internalDate", contains(Item.INTERNAL_DATE)) + .add("size", contains(Item.SIZE)) + .add("envelope", contains(Item.ENVELOPE)) + .add("body", contains(Item.BODY)) + .add("bodyStructure", contains(Item.BODY_STRUCTURE)) .add("setSeen", setSeen) .add("bodyElements", ImmutableSet.copyOf(bodyElements)) - .add("modSeq", isModSeq()) + .add("modSeq", contains(Item.MODSEQ)) .add("changedSince", changedSince) .add("vanished", vanished) .toString(); diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java index 698a819..d0573e3 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/FetchCommandParser.java @@ -18,6 +18,15 @@ ****************************************************************/ package org.apache.james.imap.decode.parser; +import static org.apache.james.imap.api.message.FetchData.Item.BODY; +import static org.apache.james.imap.api.message.FetchData.Item.BODY_STRUCTURE; +import static org.apache.james.imap.api.message.FetchData.Item.ENVELOPE; +import static org.apache.james.imap.api.message.FetchData.Item.FLAGS; +import static org.apache.james.imap.api.message.FetchData.Item.INTERNAL_DATE; +import static org.apache.james.imap.api.message.FetchData.Item.MODSEQ; +import static org.apache.james.imap.api.message.FetchData.Item.SIZE; +import static org.apache.james.imap.api.message.FetchData.Item.UID; + import java.util.List; import org.apache.james.imap.api.ImapCommand; @@ -53,8 +62,12 @@ public class FetchCommandParser extends AbstractUidCommandParser { * * @return fetchData */ - protected FetchData fetchRequest(ImapRequestLineReader request) throws DecodingException { - FetchData fetch = new FetchData(); + private FetchData fetchRequest(ImapRequestLineReader request, boolean useUid) throws DecodingException { + FetchData.Builder fetch = FetchData.builder(); + + if (useUid) { + fetch.fetch(UID); + } char next = nextNonSpaceChar(request); if (request.nextChar() == '(') { @@ -87,7 +100,7 @@ public class FetchCommandParser extends AbstractUidCommandParser { } } }); - fetch.setChangedSince(request.number(true)); + fetch.changedSince(request.number(true)); break; @@ -104,7 +117,7 @@ public class FetchCommandParser extends AbstractUidCommandParser { } } }); - fetch.setVanished(true); + fetch.vanished(true); break; default: break; @@ -119,44 +132,35 @@ public class FetchCommandParser extends AbstractUidCommandParser { } - return fetch; + return fetch.build(); } - private void addNextElement(ImapRequestLineReader reader, FetchData fetch) throws DecodingException { + private void addNextElement(ImapRequestLineReader reader, FetchData.Builder fetch) throws DecodingException { // String name = element.toString(); String name = readWord(reader, " [)\r\n"); char next = reader.nextChar(); // Simple elements with no '[]' parameters. if (next != '[') { if ("FAST".equalsIgnoreCase(name)) { - fetch.fetchFlags(); - fetch.fetchInternalDate(); - fetch.fetchSize(); + fetch.fetch(FLAGS, INTERNAL_DATE, SIZE); } else if ("FULL".equalsIgnoreCase(name)) { - fetch.fetchFlags(); - fetch.fetchInternalDate(); - fetch.fetchSize(); - fetch.fetchEnvelope(); - fetch.fetchBody(); + fetch.fetch(FLAGS, INTERNAL_DATE, SIZE, ENVELOPE, BODY); } else if ("ALL".equalsIgnoreCase(name)) { - fetch.fetchFlags(); - fetch.fetchInternalDate(); - fetch.fetchSize(); - fetch.fetchEnvelope(); + fetch.fetch(FLAGS, INTERNAL_DATE, SIZE, ENVELOPE); } else if ("FLAGS".equalsIgnoreCase(name)) { - fetch.fetchFlags(); + fetch.fetch(FLAGS); } else if ("RFC822.SIZE".equalsIgnoreCase(name)) { - fetch.fetchSize(); + fetch.fetch(SIZE); } else if ("ENVELOPE".equalsIgnoreCase(name)) { - fetch.fetchEnvelope(); + fetch.fetch(ENVELOPE); } else if ("INTERNALDATE".equalsIgnoreCase(name)) { - fetch.fetchInternalDate(); + fetch.fetch(INTERNAL_DATE); } else if ("BODY".equalsIgnoreCase(name)) { - fetch.fetchBody(); + fetch.fetch(BODY); } else if ("BODYSTRUCTURE".equalsIgnoreCase(name)) { - fetch.fetchBodyStructure(); + fetch.fetch(BODY_STRUCTURE); } else if ("UID".equalsIgnoreCase(name)) { - fetch.fetchUid(); + fetch.fetch(UID); } else if ("RFC822".equalsIgnoreCase(name)) { fetch.add(BodyFetchElement.createRFC822(), false); } else if ("RFC822.HEADER".equalsIgnoreCase(name)) { @@ -164,7 +168,7 @@ public class FetchCommandParser extends AbstractUidCommandParser { } else if ("RFC822.TEXT".equalsIgnoreCase(name)) { fetch.add(BodyFetchElement.createRFC822Text(), false); } else if ("MODSEQ".equalsIgnoreCase(name)) { - fetch.fetchModSeq(); + fetch.fetch(MODSEQ); } else { throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, "Invalid fetch attribute: " + name); } @@ -244,7 +248,7 @@ public class FetchCommandParser extends AbstractUidCommandParser { @Override protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, Tag tag, boolean useUids, ImapSession session) throws DecodingException { IdRange[] idSet = request.parseIdRange(session); - FetchData fetch = fetchRequest(request); + FetchData fetch = fetchRequest(request, useUids); // Check if we have VANISHED and and UID FETCH as its only allowed there // diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/FetchRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/FetchRequest.java index 6867bda..0619636 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/FetchRequest.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/FetchRequest.java @@ -35,9 +35,6 @@ public class FetchRequest extends AbstractImapRequest { this.useUids = useUids; this.idSet = idSet; this.fetch = fetch; - if (useUids) { - fetch.fetchUid(); - } } public final FetchData getFetch() { diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java index a6333e0..add60fe 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java @@ -23,6 +23,7 @@ import java.util.Collection; import org.apache.james.imap.api.message.BodyFetchElement; import org.apache.james.imap.api.message.FetchData; +import org.apache.james.imap.api.message.FetchData.Item; import org.apache.james.imap.api.message.SectionType; import org.apache.james.mailbox.model.FetchGroup; import org.apache.james.mailbox.model.MimePath; @@ -32,10 +33,10 @@ class FetchDataConverter { static FetchGroup getFetchGroup(FetchData fetch) { FetchGroup result = FetchGroup.MINIMAL; - if (fetch.isEnvelope()) { + if (fetch.contains(Item.ENVELOPE)) { result = result.with(FetchGroup.Profile.HEADERS); } - if (fetch.isBody() || fetch.isBodyStructure()) { + if (fetch.contains(Item.BODY) || fetch.contains(Item.BODY_STRUCTURE)) { result = result.with(FetchGroup.Profile.MIME_DESCRIPTOR); } diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java index 20517d3..a9677a3 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.james.imap.api.ImapConstants; import org.apache.james.imap.api.display.HumanReadableText; import org.apache.james.imap.api.message.FetchData; +import org.apache.james.imap.api.message.FetchData.Item; import org.apache.james.imap.api.message.IdRange; import org.apache.james.imap.api.message.response.StatusResponseFactory; import org.apache.james.imap.api.process.ImapProcessor; @@ -61,8 +62,8 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> { protected void processRequest(FetchRequest request, ImapSession session, Responder responder) { final boolean useUids = request.isUseUids(); final IdRange[] idSet = request.getIdSet(); - final FetchData fetch = request.getFetch(); - + final FetchData fetch = computeFetchData(request, session); + try { final long changedSince = fetch.getChangedSince(); @@ -85,7 +86,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> { final MailboxSession mailboxSession = session.getMailboxSession(); MetaData metaData = mailbox.getMetaData(false, mailboxSession, org.apache.james.mailbox.MessageManager.MetaData.FetchGroup.NO_COUNT); - if (fetch.getChangedSince() != -1 || fetch.isModSeq()) { + if (fetch.getChangedSince() != -1 || fetch.contains(Item.MODSEQ)) { // Enable CONDSTORE as this is a CONDSTORE enabling command condstoreEnablingCommand(session, responder, metaData, true); } @@ -106,10 +107,6 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> { // If we do so we could prolly save one mailbox access which should give use some more speed up respondVanished(mailboxSession, mailbox, ranges, changedSince, metaData, responder); } - // if QRESYNC is enable its necessary to also return the UID in all cases - if (EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC)) { - fetch.fetchUid(); - } processMessageRanges(session, mailbox, ranges, fetch, useUids, mailboxSession, responder); @@ -127,8 +124,16 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> { } } + private FetchData computeFetchData(FetchRequest request, ImapSession session) { + // if QRESYNC is enable its necessary to also return the UID in all cases + if (EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC)) { + return FetchData.Builder.from(request.getFetch()) + .fetch(Item.UID) + .build(); + } + return request.getFetch(); + } - /** * Process the given message ranges by fetch them and pass them to the * {@link org.apache.james.imap.api.process.ImapProcessor.Responder} @@ -143,7 +148,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> { final MessageResult result = messages.next(); //skip unchanged messages - this should be filtered at the mailbox level to take advantage of indexes - if (fetch.isModSeq() && result.getModSeq().asLong() <= fetch.getChangedSince()) { + if (fetch.contains(Item.MODSEQ) && result.getModSeq().asLong() <= fetch.getChangedSince()) { continue; } diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java index 16de9b3..8484b39 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java @@ -33,6 +33,7 @@ import javax.mail.Flags; import org.apache.james.imap.api.message.BodyFetchElement; import org.apache.james.imap.api.message.FetchData; +import org.apache.james.imap.api.message.FetchData.Item; import org.apache.james.imap.api.message.SectionType; import org.apache.james.imap.api.process.ImapSession; import org.apache.james.imap.api.process.SelectedMailbox; @@ -132,7 +133,7 @@ public final class FetchResponseBuilder { } // FLAGS response - if (fetch.isFlags() || ensureFlagsResponse) { + if (fetch.contains(Item.FLAGS) || ensureFlagsResponse) { if (selected.isRecent(resultUid)) { resultFlags.add(Flags.Flag.RECENT); } @@ -140,16 +141,16 @@ public final class FetchResponseBuilder { } // INTERNALDATE response - if (fetch.isInternalDate()) { + if (fetch.contains(Item.INTERNAL_DATE)) { setInternalDate(result.getInternalDate()); } // RFC822.SIZE response - if (fetch.isSize()) { + if (fetch.contains(Item.SIZE)) { setSize(result.getSize()); } - if (fetch.isEnvelope()) { + if (fetch.contains(Item.ENVELOPE)) { this.envelope = buildEnvelope(result); } @@ -165,29 +166,29 @@ public final class FetchResponseBuilder { } // Only create when needed - if (fetch.isBody() || fetch.isBodyStructure()) { + if (fetch.contains(Item.BODY) || fetch.contains(Item.BODY_STRUCTURE)) { // BODY response // // the STRUCTURE is only needed when no specific element is requested otherwise we don't need // to access it and may be able to not parse the message // // See IMAP-333 - if (fetch.isBody() && this.elements.isEmpty()) { + if (fetch.contains(Item.BODY) && this.elements.isEmpty()) { body = new MimeDescriptorStructure(false, result.getMimeDescriptor(), envelopeBuilder); } // BODYSTRUCTURE response - if (fetch.isBodyStructure()) { + if (fetch.contains(Item.BODY_STRUCTURE)) { bodystructure = new MimeDescriptorStructure(true, result.getMimeDescriptor(), envelopeBuilder); } } // UID response - if (fetch.isUid()) { + if (fetch.contains(Item.UID)) { setUid(resultUid); } - if (fetch.isModSeq()) { + if (fetch.contains(Item.MODSEQ)) { long changedSince = fetch.getChangedSince(); if (changedSince != -1) { // check if the modsequence if higher then the one specified by the CHANGEDSINCE option diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java index 8b4f8c8..160c2b5 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java @@ -56,18 +56,20 @@ public class FetchCommandParserPartialFetchTest { @Test public void testShouldParseZeroAndLength() throws Exception { IdRange[] ranges = { new IdRange(1) }; - FetchData data = new FetchData(); - data.add(new BodyFetchElement("BODY[]", SectionType.CONTENT, null, - null, 0L, 100L), false); + FetchData data = FetchData.builder() + .add(new BodyFetchElement("BODY[]", SectionType.CONTENT, null, + null, 0L, 100L), false) + .build(); check("1 (BODY[]<0.100>)\r\n", ranges, false, data, TAG); } @Test public void testShouldParseNonZeroAndLength() throws Exception { IdRange[] ranges = { new IdRange(1) }; - FetchData data = new FetchData(); - data.add(new BodyFetchElement("BODY[]", SectionType.CONTENT, null, - null, 20L, 12342348L), false); + FetchData data = FetchData.builder() + .add(new BodyFetchElement("BODY[]", SectionType.CONTENT, null, + null, 20L, 12342348L), false) + .build(); check("1 (BODY[]<20.12342348>)\r\n", ranges, false, data, TAG); } diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java index 84f06e7..9272343 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/FetchDataConverterTest.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import org.apache.james.imap.api.ImapConstants; import org.apache.james.imap.api.message.BodyFetchElement; import org.apache.james.imap.api.message.FetchData; +import org.apache.james.imap.api.message.FetchData.Item; import org.apache.james.mailbox.model.FetchGroup; import org.apache.james.mailbox.model.FetchGroup.Profile; import org.apache.james.mailbox.model.MimePath; @@ -43,37 +44,37 @@ class FetchDataConverterTest { static Stream<Arguments> getFetchGroupShouldReturnCorrectValue() { return Stream.of( - Arguments.arguments(new FetchData(), FetchGroup.MINIMAL), - Arguments.arguments(new FetchData().fetchBody(), FetchGroup.MINIMAL.with(Profile.MIME_DESCRIPTOR)), - Arguments.arguments(new FetchData().fetchBodyStructure(), FetchGroup.MINIMAL.with(Profile.MIME_DESCRIPTOR)), - Arguments.arguments(new FetchData().setChangedSince(0L), FetchGroup.MINIMAL), - Arguments.arguments(new FetchData().fetchEnvelope(), FetchGroup.HEADERS), - Arguments.arguments(new FetchData().fetchFlags(), FetchGroup.MINIMAL), - Arguments.arguments(new FetchData().fetchInternalDate(), FetchGroup.MINIMAL), - Arguments.arguments(new FetchData().fetchModSeq(), FetchGroup.MINIMAL), - Arguments.arguments(new FetchData().fetchUid(), FetchGroup.MINIMAL), - Arguments.arguments(new FetchData().setVanished(true), FetchGroup.MINIMAL), - Arguments.arguments(new FetchData().add(BodyFetchElement.createRFC822(), PEEK), FetchGroup.FULL_CONTENT), - Arguments.arguments(new FetchData().add(BodyFetchElement.createRFC822Header(), PEEK), FetchGroup.HEADERS), - Arguments.arguments(new FetchData().add(BodyFetchElement.createRFC822Text(), PEEK), FetchGroup.BODY_CONTENT), - Arguments.arguments(new FetchData().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_HEADER, HEADER, PATH, null, null, null), PEEK), + Arguments.arguments(FetchData.builder(), FetchGroup.MINIMAL), + Arguments.arguments(FetchData.builder().fetch(Item.BODY), FetchGroup.MINIMAL.with(Profile.MIME_DESCRIPTOR)), + Arguments.arguments(FetchData.builder().fetch(Item.BODY_STRUCTURE), FetchGroup.MINIMAL.with(Profile.MIME_DESCRIPTOR)), + Arguments.arguments(FetchData.builder().changedSince(0L), FetchGroup.MINIMAL), + Arguments.arguments(FetchData.builder().fetch(Item.ENVELOPE), FetchGroup.HEADERS), + Arguments.arguments(FetchData.builder().fetch(Item.FLAGS), FetchGroup.MINIMAL), + Arguments.arguments(FetchData.builder().fetch(Item.INTERNAL_DATE), FetchGroup.MINIMAL), + Arguments.arguments(FetchData.builder().fetch(Item.MODSEQ), FetchGroup.MINIMAL), + Arguments.arguments(FetchData.builder().fetch(Item.UID), FetchGroup.MINIMAL), + Arguments.arguments(FetchData.builder().vanished(true), FetchGroup.MINIMAL), + Arguments.arguments(FetchData.builder().add(BodyFetchElement.createRFC822(), PEEK), FetchGroup.FULL_CONTENT), + Arguments.arguments(FetchData.builder().add(BodyFetchElement.createRFC822Header(), PEEK), FetchGroup.HEADERS), + Arguments.arguments(FetchData.builder().add(BodyFetchElement.createRFC822Text(), PEEK), FetchGroup.BODY_CONTENT), + Arguments.arguments(FetchData.builder().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_HEADER, HEADER, PATH, null, null, null), PEEK), FetchGroup.MINIMAL.addPartContent(new MimePath(PATH), Profile.HEADERS)), - Arguments.arguments(new FetchData().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, HEADER, PATH, null, null, null), PEEK), + Arguments.arguments(FetchData.builder().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, HEADER, PATH, null, null, null), PEEK), FetchGroup.MINIMAL.addPartContent(new MimePath(PATH), Profile.BODY_CONTENT)), - Arguments.arguments(new FetchData().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, CONTENT, PATH, null, null, null), PEEK), + Arguments.arguments(FetchData.builder().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, CONTENT, PATH, null, null, null), PEEK), FetchGroup.MINIMAL.addPartContent(new MimePath(PATH), Profile.BODY_CONTENT)), - Arguments.arguments(new FetchData().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, CONTENT, PATH, null, null, null), PEEK), + Arguments.arguments(FetchData.builder().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, CONTENT, PATH, null, null, null), PEEK), FetchGroup.MINIMAL.addPartContent(new MimePath(PATH), Profile.MIME_CONTENT)), - Arguments.arguments(new FetchData().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, MIME, PATH, null, null, null), PEEK), + Arguments.arguments(FetchData.builder().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, MIME, PATH, null, null, null), PEEK), FetchGroup.MINIMAL.addPartContent(new MimePath(PATH), Profile.MIME_HEADERS)), - Arguments.arguments(new FetchData().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, TEXT, PATH, null, null, null), PEEK), + Arguments.arguments(FetchData.builder().add(new BodyFetchElement(ImapConstants.FETCH_RFC822_TEXT, TEXT, PATH, null, null, null), PEEK), FetchGroup.MINIMAL.addPartContent(new MimePath(PATH), Profile.BODY_CONTENT))); } @ParameterizedTest @MethodSource - void getFetchGroupShouldReturnCorrectValue(FetchData initial, FetchGroup expected) { - assertThat(FetchDataConverter.getFetchGroup(initial)) + void getFetchGroupShouldReturnCorrectValue(FetchData.Builder initial, FetchGroup expected) { + assertThat(FetchDataConverter.getFetchGroup(initial.build())) .isEqualTo(expected); } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
