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 84c6ceb647485b06715c5492bdd917aab34c0bd7 Author: Tran Tien Duc <[email protected]> AuthorDate: Thu Aug 22 15:25:41 2019 +0700 JAMES-2864 SMTPStatusCode contains all valid SMTP codes --- .../apache/james/mock/smtp/server/Response.java | 47 ++++++++++--------- .../mock/smtp/server/MockSMTPBehaviorTest.java | 3 +- .../james/mock/smtp/server/ResponseTest.java | 53 +++------------------- 3 files changed, 34 insertions(+), 69 deletions(-) diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java index 3156394..9adb043 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java @@ -24,37 +24,42 @@ import java.util.Objects; import com.google.common.base.Preconditions; class Response { - static class SMTPStatusCode { - public static SMTPStatusCode of(int code) { - return new SMTPStatusCode(code); - } + enum SMTPStatusCode { + OK_200(200), + SYSTEM_STATUS_211(211), + HELP_214(214), + SERVICE_READY(220), + SERVICE_CLOSING_CHANNEL_221(221), + ACTION_COMPLETE_250(250), + USER_NOT_LOCAL_251(251), + UNKNOW_USER_252(252), + START_MAIL_INPUT_354(354), + SERVICE_NOT_AVAILABLE_421(421), + REQUESTED_MAIL_ACTION_NOT_TAKEN_450(450), + REQUESTED_ACTION_ABORTED_451(451), + REQUESTED_ACTION_NOT_TAKEN_452(452), + SYNTAX_ERROR_500(500), + SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS_501(501), + COMMAND_NOT_IMPLEMENTED_502(502), + BAD_SEQUENCE_OF_COMMANDS_503(503), + COMMAND_PARAMETER_NOT_IMPLEMENTED_504(504), + DOES_NOT_ACCEPT_MAIL_521(521), + ACCESS_DENIED_530(530), + REQUESTED_ACTION_NOT_TAKEN_550(550), + USER_NOT_LOCAL_551(551), + REQUESTED_MAIL_ACTION_ABORTED_552(552), + REQUESTED_ACTION_NOT_TAKEN_553(553), + TRANSACTION_FAILED_554(554); private final int code; private SMTPStatusCode(int code) { - Preconditions.checkArgument(code >= 100 && code < 600, "statusCode needs to be within the 1xx - 5xx range"); - this.code = code; } public int getCode() { return code; } - - @Override - public final boolean equals(Object o) { - if (o instanceof SMTPStatusCode) { - SMTPStatusCode that = (SMTPStatusCode) o; - - return Objects.equals(this.code, that.code); - } - return false; - } - - @Override - public final int hashCode() { - return Objects.hash(code); - } } public static Response serverReject(SMTPStatusCode code, String message) { diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java index 68c3e27..57f16cd 100644 --- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java +++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java @@ -24,13 +24,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Optional; +import org.apache.james.mock.smtp.server.Response.SMTPStatusCode; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; class MockSMTPBehaviorTest { - private static final Response RESPONSE = Response.serverAccept(Response.SMTPStatusCode.of(250), "message"); + private static final Response RESPONSE = Response.serverAccept(SMTPStatusCode.ACTION_COMPLETE_250, "message"); @Nested class NumberOfAnswersPolicyTest { diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java index 512f2b3..cd5f39f 100644 --- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java +++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java @@ -22,53 +22,12 @@ package org.apache.james.mock.smtp.server; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.jupiter.api.Nested; +import org.apache.james.mock.smtp.server.Response.SMTPStatusCode; import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; class ResponseTest { - static final int OK_250_CODE = 250; - static final Response.SMTPStatusCode OK_250 = Response.SMTPStatusCode.of(OK_250_CODE); - - @Nested - class SMTPStatusCodeTest { - @Test - void shouldMatchBeanContract() { - EqualsVerifier.forClass(Response.SMTPStatusCode.class) - .verify(); - } - - @Test - void constructorShouldThrowWhenStatusCodeIsNegative() { - assertThatThrownBy(() -> Response.SMTPStatusCode.of(-1)) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void constructorShouldThrowWhenStatusCodeIsZero() { - assertThatThrownBy(() -> Response.SMTPStatusCode.of(0)) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void constructorShouldThrowWhenStatusCodeIsTooBig() { - assertThatThrownBy(() -> Response.SMTPStatusCode.of(600)) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void constructorShouldThrowWhenStatusCodeIsTooLittle() { - assertThatThrownBy(() -> Response.SMTPStatusCode.of(99)) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void getCodeShouldReturnInternalValue() { - assertThat(OK_250.getCode()) - .isEqualTo(OK_250_CODE); - } - } @Test void shouldMatchBeanContract() { @@ -78,7 +37,7 @@ class ResponseTest { @Test void constructorShouldThrowWhenMessageIsNull() { - assertThatThrownBy(() -> Response.serverReject(OK_250, null)) + assertThatThrownBy(() -> Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, null)) .isInstanceOf(NullPointerException.class); } @@ -90,25 +49,25 @@ class ResponseTest { @Test void asReplyStringShouldReturnASMTPResponseLine() { - assertThat(Response.serverReject(OK_250, "message").asReplyString()) + assertThat(Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, "message").asReplyString()) .isEqualTo("250 message"); } @Test void asReplyStringShouldReturnASMTPResponseLineWhenEmptyMessage() { - assertThat(Response.serverReject(OK_250, "").asReplyString()) + assertThat(Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, "").asReplyString()) .isEqualTo("250 "); } @Test void isServerRejectedShouldReturnTrueWhenServerReject() { - assertThat(Response.serverReject(OK_250, "message").isServerRejected()) + assertThat(Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, "message").isServerRejected()) .isTrue(); } @Test void isServerRejectedShouldReturnFalseWhenServerAccept() { - assertThat(Response.serverAccept(OK_250, "message").isServerRejected()) + assertThat(Response.serverAccept(SMTPStatusCode.ACTION_COMPLETE_250, "message").isServerRejected()) .isFalse(); } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
