@Test public void quotaStorageResponseShouldBeWellFormatted() throws Exception { QuotaResponse response = new QuotaResponse("STORAGE", "root", Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(231 * 1024)).computedLimit(QuotaSizeLimit.size(1024 * 1024)).build()); ByteImapResponseWriter byteImapResponseWriter = new ByteImapResponseWriter(); ImapResponseComposer composer = new ImapResponseComposerImpl(byteImapResponseWriter, 1024); QuotaResponseEncoder encoder = new QuotaResponseEncoder(); encoder.encode(response, composer); String responseString = byteImapResponseWriter.getString(); assertThat(responseString).isEqualTo("* QUOTA root (STORAGE 231 1024)\r\n"); }
@Override public void encode(QuotaResponse quotaResponse, ImapResponseComposer composer) throws IOException { String quotaRoot = quotaResponse.getQuotaRoot(); Quota<?, ?> quota = quotaResponse.getQuota(); composer.untagged(); composer.message(ImapConstants.QUOTA_RESPONSE_NAME); composer.message(quotaRoot == null ? "" : quotaRoot); composer.openParen(); composer.message(quotaResponse.getResourceName()); switch (quotaResponse.getResourceName().toUpperCase(Locale.US)) { case ImapConstants.STORAGE_QUOTA_RESOURCE: writeMessagesSize(composer, quota); break; case ImapConstants.MESSAGE_QUOTA_RESOURCE: writeMessagesCount(composer, quota); break; } composer.closeParen(); composer.end(); }
QuotaResponseEncoder implements ImapResponseEncoder<QuotaResponse> { @Override public void encode(QuotaResponse quotaResponse, ImapResponseComposer composer) throws IOException { String quotaRoot = quotaResponse.getQuotaRoot(); Quota<?, ?> quota = quotaResponse.getQuota(); composer.untagged(); composer.message(ImapConstants.QUOTA_RESPONSE_NAME); composer.message(quotaRoot == null ? "" : quotaRoot); composer.openParen(); composer.message(quotaResponse.getResourceName()); switch (quotaResponse.getResourceName().toUpperCase(Locale.US)) { case ImapConstants.STORAGE_QUOTA_RESOURCE: writeMessagesSize(composer, quota); break; case ImapConstants.MESSAGE_QUOTA_RESOURCE: writeMessagesCount(composer, quota); break; } composer.closeParen(); composer.end(); } }
QuotaResponseEncoder implements ImapResponseEncoder<QuotaResponse> { @Override public void encode(QuotaResponse quotaResponse, ImapResponseComposer composer) throws IOException { String quotaRoot = quotaResponse.getQuotaRoot(); Quota<?, ?> quota = quotaResponse.getQuota(); composer.untagged(); composer.message(ImapConstants.QUOTA_RESPONSE_NAME); composer.message(quotaRoot == null ? "" : quotaRoot); composer.openParen(); composer.message(quotaResponse.getResourceName()); switch (quotaResponse.getResourceName().toUpperCase(Locale.US)) { case ImapConstants.STORAGE_QUOTA_RESOURCE: writeMessagesSize(composer, quota); break; case ImapConstants.MESSAGE_QUOTA_RESOURCE: writeMessagesCount(composer, quota); break; } composer.closeParen(); composer.end(); }  }
QuotaResponseEncoder implements ImapResponseEncoder<QuotaResponse> { @Override public void encode(QuotaResponse quotaResponse, ImapResponseComposer composer) throws IOException { String quotaRoot = quotaResponse.getQuotaRoot(); Quota<?, ?> quota = quotaResponse.getQuota(); composer.untagged(); composer.message(ImapConstants.QUOTA_RESPONSE_NAME); composer.message(quotaRoot == null ? "" : quotaRoot); composer.openParen(); composer.message(quotaResponse.getResourceName()); switch (quotaResponse.getResourceName().toUpperCase(Locale.US)) { case ImapConstants.STORAGE_QUOTA_RESOURCE: writeMessagesSize(composer, quota); break; case ImapConstants.MESSAGE_QUOTA_RESOURCE: writeMessagesCount(composer, quota); break; } composer.closeParen(); composer.end(); }  @Override Class<QuotaResponse> acceptableMessages(); @Override void encode(QuotaResponse quotaResponse, ImapResponseComposer composer); }
QuotaResponseEncoder implements ImapResponseEncoder<QuotaResponse> { @Override public void encode(QuotaResponse quotaResponse, ImapResponseComposer composer) throws IOException { String quotaRoot = quotaResponse.getQuotaRoot(); Quota<?, ?> quota = quotaResponse.getQuota(); composer.untagged(); composer.message(ImapConstants.QUOTA_RESPONSE_NAME); composer.message(quotaRoot == null ? "" : quotaRoot); composer.openParen(); composer.message(quotaResponse.getResourceName()); switch (quotaResponse.getResourceName().toUpperCase(Locale.US)) { case ImapConstants.STORAGE_QUOTA_RESOURCE: writeMessagesSize(composer, quota); break; case ImapConstants.MESSAGE_QUOTA_RESOURCE: writeMessagesCount(composer, quota); break; } composer.closeParen(); composer.end(); }  @Override Class<QuotaResponse> acceptableMessages(); @Override void encode(QuotaResponse quotaResponse, ImapResponseComposer composer);  }