From 986458f8e9439c41ab0660831637593d0fcc445e Mon Sep 17 00:00:00 2001 From: Luc DUZAN Date: Mon, 11 Dec 2017 14:11:16 +0100 Subject: [PATCH] JAMES-2249 JMAP cucmber test: remove useless Exception declaration --- .../cucumber/DownloadStepdefs.java | 17 +++--- .../cucumber/GetMailboxesMethodStepdefs.java | 2 +- .../GetMessageListMethodStepdefs.java | 8 +-- .../cucumber/GetMessagesMethodStepdefs.java | 58 +++++++++---------- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java index c98c1300939..79f793ce5fa 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java @@ -35,7 +35,6 @@ import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpResponse; -import org.apache.http.client.ClientProtocolException; import org.apache.http.client.fluent.Request; import org.apache.http.client.fluent.Response; import org.apache.http.client.utils.URIBuilder; @@ -176,7 +175,7 @@ public void downloads(String username) throws Throwable { downLoad(username, getMessagesMethodStepdefs.getBlobId()); } - private void downLoad(String username, String blobId) throws IOException, ClientProtocolException, URISyntaxException { + private void downLoad(String username, String blobId) throws IOException, URISyntaxException { URIBuilder uriBuilder = mainStepdefs.baseUri().setPath("/download/" + blobId); response = authenticatedDownloadRequest(uriBuilder, blobId, username).execute().returnResponse(); } @@ -359,12 +358,12 @@ public void getDownloadWithExpiredToken(String username, String attachmentId) th } @When("^\"([^\"]*)\" delete mailbox \"([^\"]*)\"$") - public void deleteMailboxButNotAttachment(String username, String mailboxName) throws Exception { + public void deleteMailboxButNotAttachment(String username, String mailboxName) { mainStepdefs.mailboxProbe.deleteMailbox(MailboxConstants.USER_NAMESPACE, username, mailboxName); } @Then("^the user should be authorized$") - public void httpStatusDifferentFromUnauthorized() throws IOException { + public void httpStatusDifferentFromUnauthorized() { assertThat(response.getStatusLine().getStatusCode()).isIn(200, 404); } @@ -374,7 +373,7 @@ public void httpStatusDifferentFromUnauthorized(String username) throws Throwabl } @Then("^the user should not be authorized$") - public void httpUnauthorizedStatus() throws IOException { + public void httpUnauthorizedStatus() { assertThat(response.getStatusLine().getStatusCode()).isEqualTo(401); } @@ -384,7 +383,7 @@ public void httpUnauthorizedStatus(String username) throws Throwable { } @Then("^the user should receive a bad request response$") - public void httpBadRequestStatus() throws IOException { + public void httpBadRequestStatus() { assertThat(response.getStatusLine().getStatusCode()).isEqualTo(400); } @@ -400,7 +399,7 @@ public void httpOkStatusAndExpectedContent() throws IOException { } @Then("^the user should receive a not found response$") - public void httpNotFoundStatus() throws IOException { + public void httpNotFoundStatus() { assertThat(response.getStatusLine().getStatusCode()).isEqualTo(404); } @@ -422,7 +421,7 @@ public void accessTokenResponse(String username) throws Throwable { } @Then("^the attachment is named \"([^\"]*)\"$") - public void assertContentDisposition(String name) throws IOException { + public void assertContentDisposition(String name) { if (!CharMatcher.ASCII.matchesAllOf(name)) { assertEncodedFilenameMatches(name); } else { @@ -431,7 +430,7 @@ public void assertContentDisposition(String name) throws IOException { } @Then("^the blob size is (\\d+)$") - public void assertContentLength(int size) throws IOException { + public void assertContentLength(int size) { assertThat(response.getFirstHeader("Content-Length").getValue()).isEqualTo(String.valueOf(size)); } diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java index 3f94b853fcc..93cb8ca9048 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMailboxesMethodStepdefs.java @@ -59,7 +59,7 @@ public void getMailboxes(String user) throws Throwable { } @Then("^a mailboxes answer is returned without error$") - public void assertGetMailboxesOkStatus() throws Exception { + public void assertGetMailboxesOkStatus() { assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(httpClient.jsonPath.read(NAME)).isEqualTo("mailboxes"); } diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java index 3e97ab1a6a8..cd723257887 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java @@ -136,20 +136,20 @@ public void getMessageList(String flag) throws Exception { } @Then("^the message list is empty$") - public void assertEmpty() throws Exception { + public void assertEmpty() { assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(httpClient.jsonPath.>read(ARGUMENTS + ".messageIds")).isEmpty(); } @Then("^the message list has size (\\d+)") - public void assertSize(int size) throws Exception { + public void assertSize(int size) { assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(httpClient.jsonPath.>read(ARGUMENTS + ".messageIds")).hasSize(size); } @Then("^the message list contains \"([^\"]*)\"") - public void assertContains(String messsage) throws Exception { - MessageId messageId = messageIdStepdefs.getMessageId(messsage); + public void assertContains(String message) { + MessageId messageId = messageIdStepdefs.getMessageId(message); assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(httpClient.jsonPath.>read(ARGUMENTS + ".messageIds")).contains(messageId.serialize()); } diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java index c31f0103935..b9667207dd8 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java @@ -500,14 +500,14 @@ private String joinKeyValue(Pair pair) { } @Then("^an error \"([^\"]*)\" is returned$") - public void error(String type) throws Exception { + public void error(String type) { assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(httpClient.jsonPath.read(NAME)).isEqualTo("error"); assertThat(httpClient.jsonPath.read(ARGUMENTS + ".type")).isEqualTo(type); } @Then("^no error is returned$") - public void noError() throws Exception { + public void noError() { assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(httpClient.jsonPath.read(NAME)).isEqualTo("messages"); } @@ -523,36 +523,36 @@ public void assertListIsEmpty() { } @Then("^the description is \"(.*?)\"$") - public void assertDescription(String description) throws Exception { + public void assertDescription(String description) { assertThat(httpClient.jsonPath.read(ARGUMENTS + ".description")).isEqualTo(description); } @Then("^the notFound list should contain \"([^\"]*)\"$") - public void assertNotFoundListContains(String id) throws Exception { + public void assertNotFoundListContains(String id) { MessageId messageId = messageIdStepdefs.getMessageId(id); assertThat(httpClient.jsonPath.>read(ARGUMENTS + ".notFound")).contains(messageId.serialize()); } @Then("^the notFound list should contain the requested message id$") - public void assertNotFoundListContainsRequestedMessages() throws Exception { + public void assertNotFoundListContainsRequestedMessages() { ImmutableList elements = requestedMessageIds.stream().map(MessageId::serialize).collect(Guavate.toImmutableList()); assertThat(httpClient.jsonPath.>read(ARGUMENTS + ".notFound")).containsExactlyElementsOf(elements); } @Then("^the list should contain (\\d+) message$") - public void assertListContains(int numberOfMessages) throws Exception { + public void assertListContains(int numberOfMessages) { assertThat(httpClient.jsonPath.>read(ARGUMENTS + ".list")).hasSize(numberOfMessages); } @Then("^the id of the message is \"([^\"]*)\"$") - public void assertIdOfTheFirstMessage(String messageName) throws Exception { + public void assertIdOfTheFirstMessage(String messageName) { MessageId id = messageIdStepdefs.getMessageId(messageName); assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".id")).isEqualTo(id.serialize()); } @Then("^the message is in \"([^\"]*)\" mailboxes") - public void assertMailboxNamesOfTheFirstMessage(String mailboxNames) throws Exception { + public void assertMailboxNamesOfTheFirstMessage(String mailboxNames) { List values = Splitter.on(",") .splitToList(mailboxNames).stream() .map(Throwing.function(name -> mainStepdefs.jmapServer @@ -585,45 +585,45 @@ public void assertMailboxesOfMessage(String user, String messageId, DataTable us } @Then("^the threadId of the message is \"([^\"]*)\"$") - public void assertThreadIdOfTheFirstMessage(String threadId) throws Exception { + public void assertThreadIdOfTheFirstMessage(String threadId) { MessageId id = messageIdStepdefs.getMessageId(threadId); assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".threadId")).isEqualTo(id.serialize()); } @Then("^the subject of the message is \"([^\"]*)\"$") - public void assertSubjectOfTheFirstMessage(String subject) throws Exception { + public void assertSubjectOfTheFirstMessage(String subject) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".subject")).isEqualTo(subject); } @Then("^the textBody of the message is \"([^\"]*)\"$") - public void assertTextBodyOfTheFirstMessage(String textBody) throws Exception { + public void assertTextBodyOfTheFirstMessage(String textBody) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".textBody")).isEqualTo(StringEscapeUtils.unescapeJava(textBody)); } @Then("^the htmlBody of the message is \"([^\"]*)\"$") - public void assertHtmlBodyOfTheFirstMessage(String htmlBody) throws Exception { + public void assertHtmlBodyOfTheFirstMessage(String htmlBody) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".htmlBody")).isEqualTo(StringEscapeUtils.unescapeJava(htmlBody)); } @Then("^the isUnread of the message is \"([^\"]*)\"$") - public void assertIsUnreadOfTheFirstMessage(String isUnread) throws Exception { + public void assertIsUnreadOfTheFirstMessage(String isUnread) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".isUnread")).isEqualTo(Boolean.valueOf(isUnread)); } @Then("^the preview of the message is \"([^\"]*)\"$") - public void assertPreviewOfTheFirstMessage(String preview) throws Exception { + public void assertPreviewOfTheFirstMessage(String preview) { String actual = httpClient.jsonPath.read(FIRST_MESSAGE + ".preview").replace("\n", " "); assertThat(actual).isEqualToIgnoringWhitespace(StringEscapeUtils.unescapeJava(preview)); } @Then("^the preview of the message is not empty$") - public void assertPreviewOfTheFirstMessageIsNotEmpty() throws Exception { + public void assertPreviewOfTheFirstMessageIsNotEmpty() { String actual = httpClient.jsonPath.read(FIRST_MESSAGE + ".preview"); assertThat(actual).isNotEmpty(); } @Then("^the preview should not contain consecutive spaces or blank characters$") - public void assertPreviewShouldBeNormalized() throws Exception { + public void assertPreviewShouldBeNormalized() { String actual = httpClient.jsonPath.read(FIRST_MESSAGE + ".preview"); assertThat(actual).hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH) .doesNotMatch(" ") @@ -632,69 +632,69 @@ public void assertPreviewShouldBeNormalized() throws Exception { } @Then("^the headers of the message contains:$") - public void assertHeadersOfTheFirstMessage(DataTable headers) throws Exception { + public void assertHeadersOfTheFirstMessage(DataTable headers) { assertThat(httpClient.jsonPath.>read(FIRST_MESSAGE + ".headers")).containsAllEntriesOf(headers.asMap(String.class, String.class)); } @Then("^the date of the message is \"([^\"]*)\"$") - public void assertDateOfTheFirstMessage(String date) throws Exception { + public void assertDateOfTheFirstMessage(String date) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".date")).isEqualTo(date); } @Then("^the hasAttachment of the message is \"([^\"]*)\"$") - public void assertHasAttachmentOfTheFirstMessage(String hasAttachment) throws Exception { + public void assertHasAttachmentOfTheFirstMessage(String hasAttachment) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".hasAttachment")).isEqualTo(Boolean.valueOf(hasAttachment)); } @Then("^the isForwarded property of the message is \"([^\"]*)\"$") - public void assertIsForwardedOfTheFirstMessage(String isForwarded) throws Exception { + public void assertIsForwardedOfTheFirstMessage(String isForwarded) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + ".isForwarded")).isEqualTo(Boolean.valueOf(isForwarded)); } @Then("^the list of attachments of the message is empty$") - public void assertAttachmentsOfTheFirstMessageIsEmpty() throws Exception { + public void assertAttachmentsOfTheFirstMessageIsEmpty() { assertThat(httpClient.jsonPath.>read(ATTACHMENTS)).isEmpty(); } @Then("^the property \"([^\"]*)\" of the message is null$") - public void assertPropertyIsNull(String property) throws Exception { + public void assertPropertyIsNull(String property) { assertThat(httpClient.jsonPath.read(FIRST_MESSAGE + "." + property + ".date")).isNull(); } @Then("^the list of attachments of the message contains (\\d+) attachments?$") - public void assertAttachmentsHasSize(int numberOfAttachments) throws Exception { + public void assertAttachmentsHasSize(int numberOfAttachments) { assertThat(httpClient.jsonPath.>read(ATTACHMENTS)).hasSize(numberOfAttachments); } @Then("^the list of attachments of the message contains only one attachment with cid \"([^\"]*)\"?$") - public void assertAttachmentsAndItsCid(String cid) throws Exception { + public void assertAttachmentsAndItsCid(String cid) { assertThat(httpClient.jsonPath.read(FIRST_ATTACHMENT + ".cid")).isEqualTo(cid); } @Then("^the first attachment is:$") - public void assertFirstAttachment(DataTable attachmentProperties) throws Exception { + public void assertFirstAttachment(DataTable attachmentProperties) { assertAttachment(FIRST_ATTACHMENT, attachmentProperties); } @Then("^the second attachment is:$") - public void assertSecondAttachment(DataTable attachmentProperties) throws Exception { + public void assertSecondAttachment(DataTable attachmentProperties) { assertAttachment(SECOND_ATTACHMENT, attachmentProperties); } @Then("^the preview of the message contains: (.*)$") - public void assertPreviewOfMessageShouldBePrintedWithEncoding(List preview) throws Exception { + public void assertPreviewOfMessageShouldBePrintedWithEncoding(List preview) { String actual = httpClient.jsonPath.read(FIRST_MESSAGE + ".preview"); assertThat(actual).contains(preview); } @Then("^the keywords of the message is (.*)$") - public void assertKeywordsOfMessageShouldDisplay(List keywords) throws Exception { + public void assertKeywordsOfMessageShouldDisplay(List keywords) { assertThat(httpClient.jsonPath.>read(FIRST_MESSAGE + ".keywords").keySet()) .containsOnlyElementsOf(keywords); } @Then("^the message has no keyword$") - public void assertMessageHasNoKeyword() throws Exception { + public void assertMessageHasNoKeyword() { assertThat(httpClient.jsonPath.>read(FIRST_MESSAGE + ".keywords")) .isNullOrEmpty(); }