JAMES-2341 Introduce SpamAssassinConfiguration
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ae8652df Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ae8652df Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ae8652df Branch: refs/heads/master Commit: ae8652df1169224fc6258ad93c2156f8884a6457 Parents: 49c9ea4 Author: Antoine Duprat <[email protected]> Authored: Thu Feb 22 15:41:05 2018 +0100 Committer: Antoine Duprat <[email protected]> Committed: Wed Feb 28 13:29:31 2018 +0100 ---------------------------------------------------------------------- mailbox/plugin/spamassassin/pom.xml | 15 +++++ .../spamassassin/SpamAssassinConfiguration.java | 66 ++++++++++++++++++++ .../SpamAssassinConfigurationTest.java | 51 +++++++++++++++ 3 files changed, 132 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/ae8652df/mailbox/plugin/spamassassin/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/plugin/spamassassin/pom.xml b/mailbox/plugin/spamassassin/pom.xml index 87254bc..e88cc2d 100644 --- a/mailbox/plugin/spamassassin/pom.xml +++ b/mailbox/plugin/spamassassin/pom.xml @@ -36,6 +36,21 @@ <groupId>${project.groupId}</groupId> <artifactId>apache-james-mailbox-api</artifactId> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/james-project/blob/ae8652df/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfiguration.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfiguration.java b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfiguration.java new file mode 100644 index 0000000..bfc5f82 --- /dev/null +++ b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfiguration.java @@ -0,0 +1,66 @@ +/**************************************************************** + * 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.mailbox.spamassassin; + +import java.util.Objects; +import java.util.Optional; + +import org.apache.james.util.Host; + +import com.google.common.base.MoreObjects; + +public class SpamAssassinConfiguration { + + private final Optional<Host> host; + + public SpamAssassinConfiguration(Optional<Host> host) { + this.host = host; + } + + public boolean isEnable() { + return host.isPresent(); + } + + public Optional<Host> getHost() { + return host; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof SpamAssassinConfiguration) { + SpamAssassinConfiguration that = (SpamAssassinConfiguration) o; + + return Objects.equals(this.host, that.host); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(host); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("host", host) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/ae8652df/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java new file mode 100644 index 0000000..40f4423 --- /dev/null +++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java @@ -0,0 +1,51 @@ +/**************************************************************** + * 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.mailbox.spamassassin; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Optional; + +import org.apache.james.util.Host; +import org.junit.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class SpamAssassinConfigurationTest { + + @Test + public void spamAssassinConfigurationShouldRespectBeanContract() { + EqualsVerifier.forClass(SpamAssassinConfiguration.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void isEnableShouldReturnFalseWhenEmpty() { + SpamAssassinConfiguration configuration = new SpamAssassinConfiguration(Optional.empty()); + assertThat(configuration.isEnable()).isFalse(); + } + + @Test + public void isEnableShouldReturnTrueWhenConfigured() { + int port = 1; + SpamAssassinConfiguration configuration = new SpamAssassinConfiguration(Optional.of(Host.from("hostname", port))); + assertThat(configuration.isEnable()).isTrue(); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
