This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 8bf25037ebb0a309c45ca3d42b1d0ab82b88bee4 Author: Tran Tien Duc <[email protected]> AuthorDate: Tue Nov 26 11:24:42 2019 +0700 JAMES-2989 drop MessagePreviewGenerator --- .../apache/james/jmap/draft/JMAPCommonModule.java | 2 - .../jmap/draft/model/MessagePreviewGenerator.java | 41 ---------- .../draft/model/MessagePreviewGeneratorTest.java | 95 ---------------------- 3 files changed, 138 deletions(-) diff --git a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java b/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java index 3bf46e5..48a0af2 100644 --- a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java +++ b/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java @@ -34,7 +34,6 @@ import org.apache.james.jmap.draft.crypto.SignatureHandler; import org.apache.james.jmap.draft.crypto.SignedTokenFactory; import org.apache.james.jmap.draft.crypto.SignedTokenManager; import org.apache.james.jmap.draft.model.MailboxFactory; -import org.apache.james.jmap.draft.model.MessagePreviewGenerator; import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory; import org.apache.james.jmap.draft.send.MailSpool; import org.apache.james.jmap.draft.utils.HeadersAuthenticationExtractor; @@ -69,7 +68,6 @@ public class JMAPCommonModule extends AbstractModule { bind(AutomaticallySentMailDetectorImpl.class).in(Scopes.SINGLETON); bind(MailboxFactory.class).in(Scopes.SINGLETON); bind(MessageFullViewFactory.class).in(Scopes.SINGLETON); - bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON); bind(MessageContentExtractor.class).in(Scopes.SINGLETON); bind(HeadersAuthenticationExtractor.class).in(Scopes.SINGLETON); bind(SecurityKeyLoader.class).in(Scopes.SINGLETON); diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessagePreviewGenerator.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessagePreviewGenerator.java deleted file mode 100644 index 53ddcdb..0000000 --- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessagePreviewGenerator.java +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.jmap.draft.model; - -import java.util.Optional; - -import org.apache.commons.lang3.StringUtils; - -public class MessagePreviewGenerator { - - public static final String NO_BODY = "(Empty)"; - public static final int MAX_PREVIEW_LENGTH = 256; - - public String compute(Optional<String> textBody) { - return textBody.map(StringUtils::normalizeSpace) - .filter(text -> !text.isEmpty()) - .map(this::truncateToMaxLength) - .orElse(NO_BODY); - } - - private String truncateToMaxLength(String body) { - return StringUtils.left(body, MAX_PREVIEW_LENGTH); - } -} diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MessagePreviewGeneratorTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MessagePreviewGeneratorTest.java deleted file mode 100644 index 8fff51e..0000000 --- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MessagePreviewGeneratorTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.jmap.draft.model; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Optional; - -import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.Test; - -public class MessagePreviewGeneratorTest { - - private MessagePreviewGenerator testee; - - @Before - public void setUp() { - testee = new MessagePreviewGenerator(); - } - - @Test - public void computeShouldReturnStringEmptyWhenEmptyTextBody() throws Exception { - assertThat(testee.compute(Optional.empty())).isEqualTo(MessagePreviewGenerator.NO_BODY); - } - - @Test - public void computeShouldReturnStringEmptyWhenStringEmptyTextBody() throws Exception { - assertThat(testee.compute(Optional.of(""))).isEqualTo(MessagePreviewGenerator.NO_BODY); - } - - @Test - public void computeShouldReturnStringEmptyWhenOnlySpaceTabAndBreakLines() throws Exception { - assertThat(testee.compute(Optional.of(" \n\t "))).isEqualTo(MessagePreviewGenerator.NO_BODY); - } - - @Test - public void computeShouldReturnStringEmptyWhenOnlySpace() throws Exception { - assertThat(testee.compute(Optional.of(" "))).isEqualTo(MessagePreviewGenerator.NO_BODY); - } - - @Test - public void computeShouldReturnStringEmptyWhenOnlyTab() throws Exception { - assertThat(testee.compute(Optional.of("\t"))).isEqualTo(MessagePreviewGenerator.NO_BODY); - } - - @Test - public void computeShouldReturnStringEmptyWhenOnlyBreakLines() throws Exception { - assertThat(testee.compute(Optional.of("\n"))).isEqualTo(MessagePreviewGenerator.NO_BODY); - } - - @Test - public void computeShouldReturnStringWithoutTruncation() throws Exception { - String body = StringUtils.leftPad("a", 100, "b"); - - assertThat(testee.compute(Optional.of(body))) - .hasSize(100) - .isEqualTo(body); - } - - @Test - public void computeShouldReturnStringIsLimitedTo256Length() throws Exception { - String body = StringUtils.leftPad("a", 300, "b"); - String expected = StringUtils.leftPad("b", MessagePreviewGenerator.MAX_PREVIEW_LENGTH, "b"); - - assertThat(testee.compute(Optional.of(body))) - .hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH) - .isEqualTo(expected); - } - - @Test - public void computeShouldReturnNormalizeSpaceString() throws Exception { - String body = " this is\n the\r preview\t content\n\n "; - - assertThat(testee.compute(Optional.of(body))) - .isEqualTo("this is the preview content"); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
