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 70265a4932ccd15cf22f0a02948442551840ad61 Author: Rene Cordier <rcord...@linagora.com> AuthorDate: Mon Nov 11 16:23:16 2019 +0700 [Refactoring] Moving tests in mailbox.model to JUnit 5 --- .../james/mailbox/model/AttachmentIdTest.java | 18 +- .../apache/james/mailbox/model/AttachmentTest.java | 83 +++--- .../org/apache/james/mailbox/model/BlobIdTest.java | 16 +- .../org/apache/james/mailbox/model/BlobTest.java | 14 +- .../org/apache/james/mailbox/model/CidTest.java | 130 +++++---- .../model/ComposedMessageIdWithMetaDataTest.java | 52 ++-- .../mailbox/model/MailboxACLEntryKeyTest.java | 45 ++- .../apache/james/mailbox/model/MailboxACLTest.java | 46 +-- .../mailbox/model/MailboxAnnotationKeyTest.java | 128 +++++---- .../james/mailbox/model/MailboxAnnotationTest.java | 36 ++- .../james/mailbox/model/MailboxAssertTests.java | 49 ++-- .../james/mailbox/model/MailboxCountersTest.java | 6 +- .../james/mailbox/model/MailboxPathTest.java | 50 ++-- .../james/mailbox/model/MessageAttachmentTest.java | 35 +-- .../james/mailbox/model/MessageIdDtoTest.java | 17 +- .../james/mailbox/model/MessageRangeTest.java | 309 ++++++++++----------- .../model/MultimailboxesSearchQueryTest.java | 30 +- .../org/apache/james/mailbox/model/QuotaTest.java | 28 +- .../james/mailbox/model/Rfc4314RightsTest.java | 83 +++--- .../james/mailbox/model/SearchQueryTest.java | 8 +- .../james/mailbox/model/UpdatedFlagsTest.java | 30 +- 21 files changed, 628 insertions(+), 585 deletions(-) diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java index c69e9ce..d6f4565 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java @@ -24,50 +24,50 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class AttachmentIdTest { +class AttachmentIdTest { @Test - public void randomShouldGenerateDifferentIds() { + void randomShouldGenerateDifferentIds() { AttachmentId attachmentId = AttachmentId.random(); AttachmentId attachmentId2 = AttachmentId.random(); assertThat(attachmentId.getId()).isNotEqualTo(attachmentId2.getId()); } @Test - public void fromShouldThrowWhenIdIsNull() { + void fromShouldThrowWhenIdIsNull() { String value = null; assertThatThrownBy(() -> AttachmentId.from(value)).isInstanceOf(NullPointerException.class); } @Test - public void fromShouldThrowWhenBlobIdIsNull() { + void fromShouldThrowWhenBlobIdIsNull() { BlobId value = null; assertThatThrownBy(() -> AttachmentId.from(value)).isInstanceOf(NullPointerException.class); } @Test - public void fromShouldThrowWhenIdIsEmpty() { + void fromShouldThrowWhenIdIsEmpty() { assertThatThrownBy(() -> AttachmentId.from("")).isInstanceOf(IllegalArgumentException.class); } @Test - public void fromStringShouldWork() { + void fromStringShouldWork() { String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df"; AttachmentId attachmentId = AttachmentId.from(expectedId); assertThat(attachmentId.getId()).isEqualTo(expectedId); } @Test - public void fromBlobIdShouldWork() { + void fromBlobIdShouldWork() { String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df"; AttachmentId attachmentId = AttachmentId.from(BlobId.fromString(expectedId)); assertThat(attachmentId.getId()).isEqualTo(expectedId); } @Test - public void asUUIDShouldReturnAValidUUID() { + void asUUIDShouldReturnAValidUUID() { AttachmentId attachmentId = AttachmentId.from("magic"); assertThat(attachmentId.asUUID()) diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java index d73e073..69c5636 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java @@ -21,20 +21,21 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class AttachmentTest { +class AttachmentTest { private static Charset CHARSET = StandardCharsets.UTF_8; @Test - public void streamShouldBeConsumedOneTime() throws Exception { + void streamShouldBeConsumedOneTime() throws Exception { String input = "mystream"; Attachment attachment = Attachment.builder() .bytes(input.getBytes(CHARSET)) @@ -47,7 +48,7 @@ public class AttachmentTest { } @Test - public void getByteShouldReturnByteArrayRepresentingTheAttachment() { + void getByteShouldReturnByteArrayRepresentingTheAttachment() { String input = "mystream"; Attachment attachment = Attachment.builder() .bytes(input.getBytes(CHARSET)) @@ -59,7 +60,7 @@ public class AttachmentTest { } @Test - public void streamShouldBeConsumedMoreThanOneTime() throws Exception { + void streamShouldBeConsumedMoreThanOneTime() throws Exception { String input = "mystream"; Attachment attachment = Attachment.builder() .bytes(input.getBytes(CHARSET)) @@ -72,52 +73,60 @@ public class AttachmentTest { assertThat(IOUtils.toString(stream, CHARSET)).isEqualTo(input); } - @Test (expected = IllegalArgumentException.class) - public void builderShouldThrowWhenAttachmentIdIsNull() { - Attachment.builder() - .attachmentId(null); + @Test + void builderShouldThrowWhenAttachmentIdIsNull() { + assertThatThrownBy(() -> Attachment.builder() + .attachmentId(null)) + .isInstanceOf(IllegalArgumentException.class); } - @Test (expected = IllegalArgumentException.class) - public void builderShouldThrowWhenBytesIsNull() { - Attachment.builder() - .bytes(null); + @Test + void builderShouldThrowWhenBytesIsNull() { + assertThatThrownBy(() -> Attachment.builder() + .bytes(null)) + .isInstanceOf(IllegalArgumentException.class); } - @Test (expected = IllegalArgumentException.class) - public void builderShouldThrowWhenTypeIsNull() { - Attachment.builder() - .type(null); + @Test + void builderShouldThrowWhenTypeIsNull() { + assertThatThrownBy(() -> Attachment.builder() + .type(null)) + .isInstanceOf(IllegalArgumentException.class); } - @Test (expected = IllegalArgumentException.class) - public void builderShouldThrowWhenTypeIsEmpty() { - Attachment.builder() - .type(""); + @Test + void builderShouldThrowWhenTypeIsEmpty() { + assertThatThrownBy(() -> Attachment.builder() + .type("")) + .isInstanceOf(IllegalArgumentException.class); } - @Test (expected = IllegalStateException.class) - public void buildShouldThrowWhenAttachmentIdIsNotProvided() { - Attachment.builder().build(); + @Test + void buildShouldThrowWhenAttachmentIdIsNotProvided() { + assertThatThrownBy(() -> Attachment.builder() + .build()) + .isInstanceOf(IllegalStateException.class); } - @Test (expected = IllegalStateException.class) - public void buildShouldThrowWhenBytesIsNotProvided() { - Attachment.builder() - .attachmentId(AttachmentId.random()) - .build(); + @Test + void buildShouldThrowWhenBytesIsNotProvided() { + assertThatThrownBy(() -> Attachment.builder() + .attachmentId(AttachmentId.random()) + .build()) + .isInstanceOf(IllegalStateException.class); } - @Test (expected = IllegalStateException.class) - public void buildShouldThrowWhenTypeIsNotProvided() { - Attachment.builder() - .attachmentId(AttachmentId.random()) - .bytes("mystream".getBytes(CHARSET)) - .build(); + @Test + void buildShouldThrowWhenTypeIsNotProvided() { + assertThatThrownBy(() -> Attachment.builder() + .attachmentId(AttachmentId.random()) + .bytes("mystream".getBytes(CHARSET)) + .build()) + .isInstanceOf(IllegalStateException.class); } @Test - public void buildShouldSetTheSize() { + void buildShouldSetTheSize() { String input = "mystream"; Attachment attachment = Attachment.builder() .bytes(input.getBytes(CHARSET)) @@ -128,7 +137,7 @@ public class AttachmentTest { } @Test - public void toBlobShouldGenerateTheAttachmentBlob() { + void toBlobShouldGenerateTheAttachmentBlob() { byte[] bytes = "mystream".getBytes(CHARSET); String content = "content"; Attachment attachment = Attachment.builder() diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java index f91b9c7..1d4e3b2 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java @@ -24,44 +24,44 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class BlobIdTest { +class BlobIdTest { @Test - public void shouldMatchBeanContact() { + void shouldMatchBeanContact() { EqualsVerifier.forClass(BlobId.class) .verify(); } @Test - public void fromStringShouldThrowOnNull() { + void fromStringShouldThrowOnNull() { assertThatThrownBy(() -> BlobId.fromString(null)) .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromStringShouldThrowOnEmpty() { + void fromStringShouldThrowOnEmpty() { assertThatThrownBy(() -> BlobId.fromString("")) .isInstanceOf(IllegalArgumentException.class); } @Test - public void asStringShouldReturnUnderlyingId() { + void asStringShouldReturnUnderlyingId() { assertThat(BlobId.fromString("abc").asString()) .isEqualTo("abc"); } @Test - public void fromBytesShouldProduceASHA256() { + void fromBytesShouldProduceASHA256() { assertThat(BlobId.fromBytes("abc".getBytes(StandardCharsets.UTF_8)).asString()) .isEqualTo("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); } @Test - public void fromBytesShouldCalculateSameSha256() { + void fromBytesShouldCalculateSameSha256() { byte[] bytes = "abc".getBytes(StandardCharsets.UTF_8); assertThat(BlobId.fromBytes(bytes)) diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java index 0c306d4..b19219d 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java @@ -24,25 +24,25 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class BlobTest { +class BlobTest { public static final BlobId ID = BlobId.fromString("123"); public static final String CONTENT_TYPE = "text/plain"; public static final byte[] PAYLOAD = "abc".getBytes(StandardCharsets.UTF_8); @Test - public void shouldMatchBeanContract() { + void shouldMatchBeanContract() { EqualsVerifier.forClass(Blob.class) .withIgnoredFields("payload", "size") .verify(); } @Test - public void buildShouldConstructValidBlob() { + void buildShouldConstructValidBlob() { assertThat( Blob.builder() .id(ID) @@ -54,7 +54,7 @@ public class BlobTest { } @Test - public void buildShouldThrowOnMissingBlobId() { + void buildShouldThrowOnMissingBlobId() { assertThatThrownBy(() -> Blob.builder() .contentType(CONTENT_TYPE) @@ -64,7 +64,7 @@ public class BlobTest { } @Test - public void buildShouldThrowOnMissingContentType() { + void buildShouldThrowOnMissingContentType() { assertThatThrownBy(() -> Blob.builder() .id(ID) @@ -74,7 +74,7 @@ public class BlobTest { } @Test - public void buildShouldThrowOnMissingPayload() { + void buildShouldThrowOnMissingPayload() { assertThatThrownBy(() -> Blob.builder() .id(ID) diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java index 3939a39..1e1c59b 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java @@ -20,75 +20,72 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Optional; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class CidTest { - - @Rule public ExpectedException expectedException = ExpectedException.none(); +class CidTest { @Test - public void fromShouldThrowWhenNull() { - expectedException.expect(IllegalArgumentException.class); - Cid.from(null); + void fromShouldThrowWhenNull() { + assertThatThrownBy(() -> Cid.from(null)) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromShouldThrowWhenEmpty() { - expectedException.expect(IllegalArgumentException.class); - Cid.from(""); + void fromShouldThrowWhenEmpty() { + assertThatThrownBy(() -> Cid.from("")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromShouldThrowWhenBlank() { - expectedException.expect(IllegalArgumentException.class); - Cid.from(" "); + void fromShouldThrowWhenBlank() { + assertThatThrownBy(() -> Cid.from(" ")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromShouldThrowWhenEmptyAfterRemoveTags() { - expectedException.expect(IllegalArgumentException.class); - Cid.from("<>"); + void fromShouldThrowWhenEmptyAfterRemoveTags() { + assertThatThrownBy(() -> Cid.from("<>")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromShouldThrowWhenBlankAfterRemoveTags() { - expectedException.expect(IllegalArgumentException.class); - Cid.from("< >"); + void fromShouldThrowWhenBlankAfterRemoveTags() { + assertThatThrownBy(() -> Cid.from("< >")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromShouldRemoveTagsWhenExists() { + void fromShouldRemoveTagsWhenExists() { Cid cid = Cid.from("<123>"); assertThat(cid.getValue()).isEqualTo("123"); } @Test - public void fromShouldNotRemoveTagsWhenNone() { + void fromShouldNotRemoveTagsWhenNone() { Cid cid = Cid.from("123"); assertThat(cid.getValue()).isEqualTo("123"); } @Test - public void fromShouldNotRemoveTagsWhenNotEndTag() { + void fromShouldNotRemoveTagsWhenNotEndTag() { Cid cid = Cid.from("<123"); assertThat(cid.getValue()).isEqualTo("<123"); } @Test - public void fromShouldNotRemoveTagsWhenNotStartTag() { + void fromShouldNotRemoveTagsWhenNotStartTag() { Cid cid = Cid.from("123>"); assertThat(cid.getValue()).isEqualTo("123>"); } @Test - public void fromRelaxedNoUnwrapShouldReturnAbsentWhenNull() { + void fromRelaxedNoUnwrapShouldReturnAbsentWhenNull() { assertThat(Cid.parser() .relaxed() .parse(null)) @@ -96,7 +93,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldReturnAbsentWhenEmpty() { + void fromRelaxedNoUnwrapShouldReturnAbsentWhenEmpty() { assertThat(Cid.parser() .relaxed() .parse("")) @@ -104,7 +101,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldReturnAbsentWhenBlank() { + void fromRelaxedNoUnwrapShouldReturnAbsentWhenBlank() { assertThat(Cid.parser() .relaxed() .parse(" ")) @@ -112,7 +109,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldReturnCidWhenEmptyAfterRemoveTags() { + void fromRelaxedNoUnwrapShouldReturnCidWhenEmptyAfterRemoveTags() { Optional<Cid> actual = Cid.parser() .relaxed() .parse("<>"); @@ -121,7 +118,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldReturnCidWhenBlankAfterRemoveTags() { + void fromRelaxedNoUnwrapShouldReturnCidWhenBlankAfterRemoveTags() { Optional<Cid> actual = Cid.parser() .relaxed() .parse("< >"); @@ -130,7 +127,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenExists() { + void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenExists() { Optional<Cid> actual = Cid.parser() .relaxed() .parse("<123>"); @@ -139,7 +136,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenNone() { + void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenNone() { assertThat(Cid.parser() .relaxed() .parse("123")) @@ -147,7 +144,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenNotEndTag() { + void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenNotEndTag() { assertThat(Cid.parser() .relaxed() .parse("<123")) @@ -155,7 +152,7 @@ public class CidTest { } @Test - public void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenNotStartTag() { + void fromRelaxedNoUnwrapShouldNotRemoveTagsWhenNotStartTag() { assertThat(Cid.parser() .relaxed() .parse("123>")) @@ -164,7 +161,7 @@ public class CidTest { @Test - public void fromRelaxedUnwrapShouldReturnAbsentWhenNull() { + void fromRelaxedUnwrapShouldReturnAbsentWhenNull() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -173,7 +170,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldReturnAbsentWhenEmpty() { + void fromRelaxedUnwrapShouldReturnAbsentWhenEmpty() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -182,7 +179,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldReturnAbsentWhenBlank() { + void fromRelaxedUnwrapShouldReturnAbsentWhenBlank() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -191,7 +188,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldReturnAbsentWhenEmptyAfterRemoveTags() { + void fromRelaxedUnwrapShouldReturnAbsentWhenEmptyAfterRemoveTags() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -200,7 +197,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldReturnAbsentWhenBlankAfterRemoveTags() { + void fromRelaxedUnwrapShouldReturnAbsentWhenBlankAfterRemoveTags() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -209,7 +206,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldRemoveTagsWhenExists() { + void fromRelaxedUnwrapShouldRemoveTagsWhenExists() { Optional<Cid> actual = Cid.parser() .relaxed() .unwrap() @@ -219,7 +216,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldNotRemoveTagsWhenNone() { + void fromRelaxedUnwrapShouldNotRemoveTagsWhenNone() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -228,7 +225,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldNotRemoveTagsWhenNotEndTag() { + void fromRelaxedUnwrapShouldNotRemoveTagsWhenNotEndTag() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -237,7 +234,7 @@ public class CidTest { } @Test - public void fromRelaxedUnwrapShouldNotRemoveTagsWhenNotStartTag() { + void fromRelaxedUnwrapShouldNotRemoveTagsWhenNotStartTag() { assertThat(Cid.parser() .relaxed() .unwrap() @@ -246,34 +243,31 @@ public class CidTest { } @Test - public void fromStrictNoUnwrapShouldThrowWhenNull() { - expectedException.expect(IllegalArgumentException.class); - - Cid.parser() - .strict() - .parse(null); + void fromStrictNoUnwrapShouldThrowWhenNull() { + assertThatThrownBy(() -> Cid.parser() + .strict() + .parse(null)) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromStrictNoUnwrapShouldThrowWhenEmpty() { - expectedException.expect(IllegalArgumentException.class); - - Cid.parser() - .strict() - .parse(""); + void fromStrictNoUnwrapShouldThrowWhenEmpty() { + assertThatThrownBy(() -> Cid.parser() + .strict() + .parse("")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromStrinctNoUnwrapShouldThrowWhenBlank() { - expectedException.expect(IllegalArgumentException.class); - - Cid.parser() - .strict() - .parse(" "); + void fromStrinctNoUnwrapShouldThrowWhenBlank() { + assertThatThrownBy(() -> Cid.parser() + .strict() + .parse(" ")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void fromStrictNoUnwrapShouldNotRemoveTagWhenEmptyAfterRemoveTags() { + void fromStrictNoUnwrapShouldNotRemoveTagWhenEmptyAfterRemoveTags() { Optional<Cid> actual = Cid.parser() .strict() .parse("<>"); @@ -282,7 +276,7 @@ public class CidTest { } @Test - public void fromStrictNoUnwrapShouldNotRemoveTagWhenBlankAfterRemoveTags() { + void fromStrictNoUnwrapShouldNotRemoveTagWhenBlankAfterRemoveTags() { Optional<Cid> actual = Cid.parser() .strict() .parse("< >"); @@ -291,7 +285,7 @@ public class CidTest { } @Test - public void fromStrictNoUnwrapShouldNotRemoveTagsWhenExists() { + void fromStrictNoUnwrapShouldNotRemoveTagsWhenExists() { Optional<Cid> actual = Cid.parser() .strict() .parse("<123>"); @@ -300,7 +294,7 @@ public class CidTest { } @Test - public void fromStrictNoUnwrapShouldNotRemoveTagsWhenNone() { + void fromStrictNoUnwrapShouldNotRemoveTagsWhenNone() { assertThat(Cid.parser() .strict() .parse("123")) @@ -308,7 +302,7 @@ public class CidTest { } @Test - public void fromStrictNoUnwrapShouldNotRemoveTagsWhenNotEndTag() { + void fromStrictNoUnwrapShouldNotRemoveTagsWhenNotEndTag() { assertThat(Cid.parser() .strict() .parse("<123")) @@ -316,7 +310,7 @@ public class CidTest { } @Test - public void fromStrictNoUnwrapShouldNotRemoveTagsWhenNotStartTag() { + void fromStrictNoUnwrapShouldNotRemoveTagsWhenNotStartTag() { assertThat(Cid.parser() .strict() .parse("123>")) @@ -324,7 +318,7 @@ public class CidTest { } @Test - public void shouldRespectJavaBeanContract() { + void shouldRespectJavaBeanContract() { EqualsVerifier.forClass(Cid.class).verify(); } } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/ComposedMessageIdWithMetaDataTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/ComposedMessageIdWithMetaDataTest.java index 8df2ba4..b120c87 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/ComposedMessageIdWithMetaDataTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/ComposedMessageIdWithMetaDataTest.java @@ -19,44 +19,48 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import javax.mail.Flags; import javax.mail.Flags.Flag; import org.apache.james.mailbox.MessageUid; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class ComposedMessageIdWithMetaDataTest { +class ComposedMessageIdWithMetaDataTest { - public static final TestId TEST_ID = TestId.of(1L); - public static final TestMessageId TEST_MESSAGE_ID = new TestMessageId("2"); - public static final MessageUid MESSAGE_UID = MessageUid.of(3); - public static final ComposedMessageId COMPOSED_MESSAGE_ID = new ComposedMessageId(TEST_ID, TEST_MESSAGE_ID, MESSAGE_UID); + private static final TestId TEST_ID = TestId.of(1L); + private static final TestMessageId TEST_MESSAGE_ID = new TestMessageId("2"); + private static final MessageUid MESSAGE_UID = MessageUid.of(3); + private static final ComposedMessageId COMPOSED_MESSAGE_ID = new ComposedMessageId(TEST_ID, TEST_MESSAGE_ID, MESSAGE_UID); - @Test(expected = NullPointerException.class) - public void buildShoudThrownWhenComposedMessageIdIsNull() { - ComposedMessageIdWithMetaData.builder().build(); + @Test + void buildShoudThrownWhenComposedMessageIdIsNull() { + assertThatThrownBy(() -> ComposedMessageIdWithMetaData.builder().build()) + .isInstanceOf(NullPointerException.class); } - @Test(expected = NullPointerException.class) - public void buildShoudThrownWhenFlagsIsNull() { - ComposedMessageIdWithMetaData.builder() - .composedMessageId(COMPOSED_MESSAGE_ID) - .build(); + @Test + void buildShoudThrownWhenFlagsIsNull() { + assertThatThrownBy(() -> ComposedMessageIdWithMetaData.builder() + .composedMessageId(COMPOSED_MESSAGE_ID) + .build()) + .isInstanceOf(NullPointerException.class); } - @Test(expected = NullPointerException.class) - public void buildShoudThrownWhenModSeqIsNull() { - ComposedMessageIdWithMetaData.builder() - .composedMessageId(COMPOSED_MESSAGE_ID) - .flags(new Flags()) - .build(); + @Test + void buildShoudThrownWhenModSeqIsNull() { + assertThatThrownBy(() -> ComposedMessageIdWithMetaData.builder() + .composedMessageId(COMPOSED_MESSAGE_ID) + .flags(new Flags()) + .build()) + .isInstanceOf(NullPointerException.class); } @Test - public void buildShoudWork() { + void buildShoudWork() { Flags flags = new Flags(Flag.RECENT); long modSeq = 1; @@ -72,7 +76,7 @@ public class ComposedMessageIdWithMetaDataTest { } @Test - public void isMatchingShouldReturnTrueWhenSameMessageId() { + void isMatchingShouldReturnTrueWhenSameMessageId() { ComposedMessageIdWithMetaData composedMessageIdWithMetaData = ComposedMessageIdWithMetaData.builder() .composedMessageId(new ComposedMessageId(TEST_ID, TEST_MESSAGE_ID, MESSAGE_UID)) .flags(new Flags(Flag.RECENT)) @@ -83,7 +87,7 @@ public class ComposedMessageIdWithMetaDataTest { } @Test - public void isMatchingShouldReturnFalseWhenOtherMessageId() { + void isMatchingShouldReturnFalseWhenOtherMessageId() { ComposedMessageIdWithMetaData composedMessageIdWithMetaData = ComposedMessageIdWithMetaData.builder() .composedMessageId(COMPOSED_MESSAGE_ID) .flags(new Flags(Flag.RECENT)) @@ -94,7 +98,7 @@ public class ComposedMessageIdWithMetaDataTest { } @Test - public void shouldRespectJavaBeanContract() { + void shouldRespectJavaBeanContract() { EqualsVerifier.forClass(ComposedMessageIdWithMetaData.class) .verify(); } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLEntryKeyTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLEntryKeyTest.java index 8617f55..0e0307b 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLEntryKeyTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLEntryKeyTest.java @@ -22,132 +22,131 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; -import org.apache.james.mailbox.exception.UnsupportedRightException; import org.apache.james.mailbox.model.MailboxACL.EntryKey; import org.apache.james.mailbox.model.MailboxACL.NameType; import org.apache.james.mailbox.model.MailboxACL.SpecialName; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class MailboxACLEntryKeyTest { +class MailboxACLEntryKeyTest { private static final String GROUP_1 = "group1"; private static final String USER_1 = "user1"; @Test - public void testUser() throws UnsupportedRightException { + void testUser() { assertThat(EntryKey.deserialize(USER_1)) .isEqualTo(new EntryKey(USER_1, NameType.user, false)); } @Test - public void testNegativeUser() throws UnsupportedRightException { + void testNegativeUser() { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_1)) .isEqualTo(new EntryKey(USER_1, NameType.user, true)); } @Test - public void testGroup() throws UnsupportedRightException { + void testGroup() { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1)) .isEqualTo(new EntryKey(GROUP_1, NameType.group, false)); } @Test - public void testNegativeGroup() throws UnsupportedRightException { + void testNegativeGroup() { assertThat(EntryKey.deserialize(String.valueOf(MailboxACL.DEFAULT_NEGATIVE_MARKER) + MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1)) .isEqualTo(new EntryKey(GROUP_1, NameType.group, true)); } @Test - public void testOwner() throws UnsupportedRightException { + void testOwner() { assertThat(EntryKey.deserialize(SpecialName.owner.toString())) .isEqualTo(new EntryKey(SpecialName.owner.toString(), NameType.special, false)); } @Test - public void testNegativeOwner() throws UnsupportedRightException { + void testNegativeOwner() { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.owner.toString())) .isEqualTo(new EntryKey(SpecialName.owner.toString(), NameType.special, true)); } @Test - public void testAnybody() throws UnsupportedRightException { + void testAnybody() { assertThat(EntryKey.deserialize(SpecialName.anybody.toString())) .isEqualTo(new EntryKey(SpecialName.anybody.toString(), NameType.special, false)); } @Test - public void testNegativeAnybody() throws UnsupportedRightException { + void testNegativeAnybody() { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.anybody.toString())) .isEqualTo(new EntryKey(SpecialName.anybody.toString(), NameType.special, true)); } @Test - public void testAuthenticated() throws UnsupportedRightException { + void testAuthenticated() { assertThat(EntryKey.deserialize(SpecialName.authenticated.toString())) .isEqualTo(new EntryKey(SpecialName.authenticated.toString(), NameType.special, false)); } @Test - public void testNegativeAuthenticated() throws UnsupportedRightException { + void testNegativeAuthenticated() { assertThat(EntryKey.deserialize(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.authenticated.toString())) .isEqualTo(new EntryKey(SpecialName.authenticated.toString(), NameType.special, true)); } @Test - public void testSerializeUser() throws UnsupportedRightException { + void testSerializeUser() { assertThat(new EntryKey(USER_1, NameType.user, false).serialize()) .isEqualTo(USER_1); } @Test - public void testSerializeNegativeUser() throws UnsupportedRightException { + void testSerializeNegativeUser() { assertThat(new EntryKey(USER_1, NameType.user, true).serialize()) .isEqualTo(MailboxACL.DEFAULT_NEGATIVE_MARKER + USER_1); } @Test - public void testSerializeGroup() throws UnsupportedRightException { + void testSerializeGroup() { assertThat(new EntryKey(GROUP_1, NameType.group, false).serialize()) .isEqualTo(MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1); } @Test - public void testSerializeNegativeGroup() throws UnsupportedRightException { + void testSerializeNegativeGroup() { assertThat(new EntryKey(GROUP_1, NameType.group, true).serialize()) .isEqualTo(String.valueOf(MailboxACL.DEFAULT_NEGATIVE_MARKER) + MailboxACL.DEFAULT_GROUP_MARKER + GROUP_1); } @Test - public void testSerializeOwner() throws UnsupportedRightException { + void testSerializeOwner() { assertThat(new EntryKey(SpecialName.owner.toString(), NameType.special, false).serialize()) .isEqualTo(SpecialName.owner.toString()); } @Test - public void testSerializeNegativeOwner() throws UnsupportedRightException { + void testSerializeNegativeOwner() { assertThat(new EntryKey(SpecialName.owner.toString(), NameType.special, true).serialize()) .isEqualTo(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.owner.toString()); } @Test - public void testSerializeAnybody() throws UnsupportedRightException { + void testSerializeAnybody() { assertThat(new EntryKey(SpecialName.anybody.toString(), NameType.special, false).serialize()) .isEqualTo(SpecialName.anybody.toString()); } @Test - public void testSerializeNegativeAnybody() throws UnsupportedRightException { + void testSerializeNegativeAnybody() { assertThat(new EntryKey(SpecialName.anybody.toString(), NameType.special, true).serialize()) .isEqualTo(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.anybody.toString()); } @Test - public void testSerializeAuthenticated() throws UnsupportedRightException { + void testSerializeAuthenticated() { assertThat(new EntryKey(SpecialName.authenticated.toString(), NameType.special, false).serialize()) .isEqualTo(SpecialName.authenticated.toString()); } @Test - public void testSerializeNegativeAuthenticated() throws UnsupportedRightException { + void testSerializeNegativeAuthenticated() { assertThat(new EntryKey(SpecialName.authenticated.toString(), NameType.special, true).serialize()) .isEqualTo(MailboxACL.DEFAULT_NEGATIVE_MARKER + SpecialName.authenticated.toString()); } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java index fd0e05d..8282c9d 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxACLTest.java @@ -32,12 +32,12 @@ import org.apache.james.mailbox.model.MailboxACL.EntryKey; import org.apache.james.mailbox.model.MailboxACL.NameType; import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights; import org.assertj.core.data.MapEntry; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableMap; -public class MailboxACLTest { +class MailboxACLTest { private static final String USER_1 = "user1"; private static final String USER_2 = "user2"; @@ -53,8 +53,8 @@ public class MailboxACLTest { private MailboxACL u1u2g1g2ACL; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { u1u2g1g2Properties = new Properties(); @@ -68,7 +68,7 @@ public class MailboxACLTest { } @Test - public void testUnionACLNew() throws UnsupportedRightException { + void testUnionACLNew() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(MailboxACL.OWNER_KEY, MailboxACL.FULL_RIGHTS); @@ -82,7 +82,7 @@ public class MailboxACLTest { } @Test - public void testUnionEntryNew() throws UnsupportedRightException { + void testUnionEntryNew() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(MailboxACL.OWNER_KEY, MailboxACL.FULL_RIGHTS); @@ -95,7 +95,7 @@ public class MailboxACLTest { } @Test - public void testUnionACLExisting() throws UnsupportedRightException { + void testUnionACLExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(aeik + lprs)); @@ -109,7 +109,7 @@ public class MailboxACLTest { } @Test - public void testUnionEntryExisting() throws UnsupportedRightException { + void testUnionEntryExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(aeik + lprs)); @@ -122,17 +122,17 @@ public class MailboxACLTest { } @Test - public void testUnionACLZero() throws UnsupportedRightException { + void testUnionACLZero() throws UnsupportedRightException { } @Test - public void testUnionEntryZero() throws UnsupportedRightException { + void testUnionEntryZero() throws UnsupportedRightException { } @Test - public void testExceptACLNew() throws UnsupportedRightException { + void testExceptACLNew() throws UnsupportedRightException { /* actually no change expected */ Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); @@ -146,7 +146,7 @@ public class MailboxACLTest { } @Test - public void testExceptEntryNew() throws UnsupportedRightException { + void testExceptEntryNew() throws UnsupportedRightException { /* actually no change expected */ Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); @@ -159,7 +159,7 @@ public class MailboxACLTest { } @Test - public void testExceptACLExisting() throws UnsupportedRightException { + void testExceptACLExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ik)); @@ -173,7 +173,7 @@ public class MailboxACLTest { } @Test - public void testExceptEntryExisting() throws UnsupportedRightException { + void testExceptEntryExisting() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.put(EntryKey.deserialize(USER_1), Rfc4314Rights.fromSerializedRfc4314Rights(ik)); @@ -186,7 +186,7 @@ public class MailboxACLTest { } @Test - public void testExceptACLFull() throws UnsupportedRightException { + void testExceptACLFull() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.remove(EntryKey.deserialize(USER_1)); @@ -200,7 +200,7 @@ public class MailboxACLTest { } @Test - public void testExceptEntryFull() throws UnsupportedRightException { + void testExceptEntryFull() throws UnsupportedRightException { Map<EntryKey, Rfc4314Rights> expectedEntries = new HashMap<>(u1u2g1g2ACL.getEntries()); expectedEntries.remove(EntryKey.deserialize(USER_1)); @@ -213,26 +213,26 @@ public class MailboxACLTest { } @Test - public void propertiesConstructorShouldAcceptNullValues() throws Exception { + void propertiesConstructorShouldAcceptNullValues() throws Exception { assertThat(new MailboxACL((Properties) null)) .isEqualTo(MailboxACL.EMPTY); } @Test - public void applyShouldNotThrowWhenRemovingANonExistingEntry() throws Exception { + void applyShouldNotThrowWhenRemovingANonExistingEntry() throws Exception { assertThat(MailboxACL.EMPTY .apply(MailboxACL.command().forUser("bob").noRights().asReplacement())) .isEqualTo(MailboxACL.EMPTY); } @Test - public void usersACLShouldReturnEmptyMapWhenEmpty() { + void usersACLShouldReturnEmptyMapWhenEmpty() { assertThat(MailboxACL.EMPTY.ofPositiveNameType(NameType.user)) .isEmpty(); } @Test - public void usersACLShouldReturnEmptyMapWhenNoUserEntry() { + void usersACLShouldReturnEmptyMapWhenNoUserEntry() { MailboxACL mailboxACL = new MailboxACL( ImmutableMap.of(EntryKey.createGroupEntryKey("group"), MailboxACL.FULL_RIGHTS, EntryKey.createGroupEntryKey("group2"), MailboxACL.NO_RIGHTS)); @@ -241,7 +241,7 @@ public class MailboxACLTest { } @Test - public void usersACLShouldReturnOnlyUsersMapWhenSomeUserEntries() throws Exception { + void usersACLShouldReturnOnlyUsersMapWhenSomeUserEntries() throws Exception { MailboxACL.Rfc4314Rights rights = MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights("aei"); MailboxACL mailboxACL = new MailboxACL( ImmutableMap.of(EntryKey.createUserEntryKey("user1"), MailboxACL.FULL_RIGHTS, @@ -255,7 +255,7 @@ public class MailboxACLTest { } @Test - public void ofPositiveNameTypeShouldFilterOutNegativeEntries() throws Exception { + void ofPositiveNameTypeShouldFilterOutNegativeEntries() throws Exception { MailboxACL mailboxACL = new MailboxACL( ImmutableMap.of(EntryKey.createUserEntryKey("user1", NEGATIVE), MailboxACL.FULL_RIGHTS)); assertThat(mailboxACL.ofPositiveNameType(NameType.user)) diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationKeyTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationKeyTest.java index 4b5986e..d9dfd82 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationKeyTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationKeyTest.java @@ -20,109 +20,123 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class MailboxAnnotationKeyTest { - @Test(expected = IllegalArgumentException.class) - public void newInstanceShouldThrowsExceptionWhenKeyDoesNotStartWithSlash() throws Exception { - new MailboxAnnotationKey("shared"); +class MailboxAnnotationKeyTest { + @Test + void newInstanceShouldThrowsExceptionWhenKeyDoesNotStartWithSlash() { + assertThatThrownBy(() -> new MailboxAnnotationKey("shared")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void newInstanceShouldThrowsExceptionWhenKeyContainsAsterisk() throws Exception { - new MailboxAnnotationKey("/private/key*comment"); + @Test + void newInstanceShouldThrowsExceptionWhenKeyContainsAsterisk() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private/key*comment")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void newInstanceShouldThrowsExceptionWhenKeyContainsPercent() throws Exception { - new MailboxAnnotationKey("/private/key%comment"); + @Test + void newInstanceShouldThrowsExceptionWhenKeyContainsPercent() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private/key%comment")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void validKeyShouldThrowsExceptionWhenKeyContainsTwoConsecutiveSlash() throws Exception { - new MailboxAnnotationKey("/private//keycomment"); + @Test + void validKeyShouldThrowsExceptionWhenKeyContainsTwoConsecutiveSlash() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private//keycomment")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void validKeyShouldThrowsExceptionWhenKeyEndsWithSlash() throws Exception { - new MailboxAnnotationKey("/private/keycomment/"); + @Test + void validKeyShouldThrowsExceptionWhenKeyEndsWithSlash() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private/keycomment/")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void validKeyShouldThrowsExceptionWhenKeyContainsNonASCII() throws Exception { - new MailboxAnnotationKey("/private/key comment"); + @Test + void validKeyShouldThrowsExceptionWhenKeyContainsNonASCII() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private/key comment")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void validKeyShouldThrowsExceptionWhenKeyContainsTabCharacter() throws Exception { - new MailboxAnnotationKey("/private/key\tcomment"); + @Test + void validKeyShouldThrowsExceptionWhenKeyContainsTabCharacter() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private/key\tcomment")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void newInstanceShouldThrowsExceptionWithEmptyKey() throws Exception { - new MailboxAnnotationKey(""); + @Test + void newInstanceShouldThrowsExceptionWithEmptyKey() { + assertThatThrownBy(() -> new MailboxAnnotationKey("")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void newInstanceShouldThrowsExceptionWithBlankKey() throws Exception { - new MailboxAnnotationKey(" "); + @Test + void newInstanceShouldThrowsExceptionWithBlankKey() { + assertThatThrownBy(() -> new MailboxAnnotationKey(" ")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void newInstanceShouldReturnRightKeyValue() throws Exception { + void newInstanceShouldReturnRightKeyValue() { MailboxAnnotationKey annotationKey = new MailboxAnnotationKey("/private/comment"); assertThat(annotationKey.asString()).isEqualTo("/private/comment"); } @Test - public void keyValueShouldBeCaseInsensitive() throws Exception { + void keyValueShouldBeCaseInsensitive() { MailboxAnnotationKey annotationKey = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey anotherAnnotationKey = new MailboxAnnotationKey("/PRIVATE/COMMENT"); assertThat(annotationKey).isEqualTo(anotherAnnotationKey); } - @Test(expected = IllegalArgumentException.class) - public void newInstanceShouldThrowsExceptionWhenKeyContainsPunctuationCharacters() throws Exception { - new MailboxAnnotationKey("/private/+comment"); + @Test + void newInstanceShouldThrowsExceptionWhenKeyContainsPunctuationCharacters() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private/+comment")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void countSlashShouldReturnRightNumberOfSlash() throws Exception { + void countSlashShouldReturnRightNumberOfSlash() { MailboxAnnotationKey annotationKey = new MailboxAnnotationKey("/private/comment/user/name"); assertThat(annotationKey.countComponents()).isEqualTo(4); } - @Test(expected = IllegalArgumentException.class) - public void keyMustContainAtLeastTwoComponents() throws Exception { - new MailboxAnnotationKey("/private"); + @Test + void keyMustContainAtLeastTwoComponents() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void keyVendorShouldThrowsExceptionWithTwoComponents() throws Exception { - new MailboxAnnotationKey("/private/vendor"); + @Test + void keyVendorShouldThrowsExceptionWithTwoComponents() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/private/vendor")) + .isInstanceOf(IllegalArgumentException.class); } - @Test(expected = IllegalArgumentException.class) - public void keyVendorShouldThrowsExceptionWithThreeComponents() throws Exception { - new MailboxAnnotationKey("/shared/vendor/token"); + @Test + void keyVendorShouldThrowsExceptionWithThreeComponents() { + assertThatThrownBy(() -> new MailboxAnnotationKey("/shared/vendor/token")) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void keyVendorShouldOKWithFourComponents() throws Exception { + void keyVendorShouldOKWithFourComponents() { new MailboxAnnotationKey("/shared/vendor/token/comment"); } @Test - public void isParentOrIsEqualShouldReturnTrueWhenSameKey() { + void isParentOrIsEqualShouldReturnTrueWhenSameKey() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); assertThat(key1.isParentOrIsEqual(key1)).isTrue(); } @Test - public void isParentOrIsEqualShouldReturnTrueWhenParent() { + void isParentOrIsEqualShouldReturnTrueWhenParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); @@ -130,7 +144,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isParentOrIsEqualShouldReturnFalseWhenChild() { + void isParentOrIsEqualShouldReturnFalseWhenChild() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); @@ -138,7 +152,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isParentOrIsEqualShouldReturnFalseWhenGrandParent() { + void isParentOrIsEqualShouldReturnFalseWhenGrandParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); @@ -146,7 +160,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isParentOrIsEqualShouldReturnFalseWhenCousin() { + void isParentOrIsEqualShouldReturnFalseWhenCousin() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); @@ -155,14 +169,14 @@ public class MailboxAnnotationKeyTest { @Test - public void isAncestorOrIsEqualShouldReturnTrueWhenSameKey() { + void isAncestorOrIsEqualShouldReturnTrueWhenSameKey() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); assertThat(key1.isAncestorOrIsEqual(key1)).isTrue(); } @Test - public void isAncestorOrIsEqualShouldReturnTrueWhenParent() { + void isAncestorOrIsEqualShouldReturnTrueWhenParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); @@ -170,7 +184,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isAncestorOrIsEqualShouldReturnFalseWhenChild() { + void isAncestorOrIsEqualShouldReturnFalseWhenChild() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto"); @@ -178,7 +192,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isAncestorOrIsEqualShouldReturnTrueWhenGrandParent() { + void isAncestorOrIsEqualShouldReturnTrueWhenGrandParent() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); @@ -186,7 +200,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isAncestorOrIsEqualShouldReturnFalseWhenCousin() { + void isAncestorOrIsEqualShouldReturnFalseWhenCousin() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/toto/tata"); @@ -194,7 +208,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isAncestorOrIsEqualShouldWorkOnCousinKeyUsingKeyAsAPrefix() { + void isAncestorOrIsEqualShouldWorkOnCousinKeyUsingKeyAsAPrefix() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/tututata"); @@ -202,7 +216,7 @@ public class MailboxAnnotationKeyTest { } @Test - public void isParentOrIsEqualShouldWorkOnCousinKeyUsingKeyAsAPrefix() { + void isParentOrIsEqualShouldWorkOnCousinKeyUsingKeyAsAPrefix() { MailboxAnnotationKey key1 = new MailboxAnnotationKey("/private/comment/tutu"); MailboxAnnotationKey key2 = new MailboxAnnotationKey("/private/comment/tututata"); diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java index 583f960..b1d2a81 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java @@ -20,63 +20,61 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class MailboxAnnotationTest { +class MailboxAnnotationTest { private static final MailboxAnnotationKey ANNOTATION_KEY = new MailboxAnnotationKey("/private/comment"); private static final String ANNOTATION_VALUE = "anyValue"; @Test - public void sizeOfAnnotationShouldBeReturnLengthOfValue() throws Exception { + void sizeOfAnnotationShouldBeReturnLengthOfValue() { MailboxAnnotation mailboxAnnotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE); assertThat(mailboxAnnotation.size()).isEqualTo(8); } @Test - public void sizeOfNilAnnotationShouldBeZero() throws Exception { + void sizeOfNilAnnotationShouldBeZero() { MailboxAnnotation mailboxAnnotation = MailboxAnnotation.nil(ANNOTATION_KEY); assertThat(mailboxAnnotation.size()).isEqualTo(0); } - @Test(expected = NullPointerException.class) - public void newInstanceShouldThrowsExceptionWithNullKey() throws Exception { - MailboxAnnotation.newInstance(null, null); + @Test + void newInstanceShouldThrowsExceptionWithNullKey() { + assertThatThrownBy(() -> MailboxAnnotation.newInstance(null, null)) + .isInstanceOf(NullPointerException.class); } - @Test(expected = NullPointerException.class) - public void newInstanceShouldThrowsExceptionWithNullValue() throws Exception { - MailboxAnnotation.newInstance(ANNOTATION_KEY, null); + @Test + void newInstanceShouldThrowsExceptionWithNullValue() { + assertThatThrownBy(() -> MailboxAnnotation.newInstance(ANNOTATION_KEY, null)) + .isInstanceOf(NullPointerException.class); } @Test - public void nilInstanceShouldReturnAbsentValue() throws Exception { + void nilInstanceShouldReturnAbsentValue() { MailboxAnnotation annotation = MailboxAnnotation.nil(ANNOTATION_KEY); assertThat(annotation.getValue()).isEmpty(); } @Test - public void isNilShouldReturnTrueForNilObject() throws Exception { + void isNilShouldReturnTrueForNilObject() { MailboxAnnotation nilAnnotation = MailboxAnnotation.nil(ANNOTATION_KEY); assertThat(nilAnnotation.isNil()).isTrue(); } @Test - public void isNilShouldReturnFalseForNotNilObject() throws Exception { + void isNilShouldReturnFalseForNotNilObject() { MailboxAnnotation nilAnnotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE); assertThat(nilAnnotation.isNil()).isFalse(); } - @Test(expected = NullPointerException.class) - public void newInstanceMailboxAnnotationShouldThrowExceptionWithNullValue() throws Exception { - MailboxAnnotation.newInstance(ANNOTATION_KEY, null); - } - @Test - public void newInstanceMailboxAnnotationShouldCreateNewInstance() throws Exception { + void newInstanceMailboxAnnotationShouldCreateNewInstance() { MailboxAnnotation annotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE); assertThat(annotation.getKey()).isEqualTo(ANNOTATION_KEY); diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAssertTests.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAssertTests.java index f006308..62f8bae 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAssertTests.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAssertTests.java @@ -19,64 +19,77 @@ package org.apache.james.mailbox.model; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class MailboxAssertTests { +import org.junit.jupiter.api.Test; + +class MailboxAssertTests { private static final long UID_VALIDITY = 42; private static final TestId MAILBOX_ID = TestId.of(24); @Test - public void isEqualToShouldNotFailWithEqualMailbox() { + void isEqualToShouldNotFailWithEqualMailbox() { Mailbox mailbox1 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); Mailbox mailbox2 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); mailbox1.setMailboxId(MAILBOX_ID); mailbox2.setMailboxId(MAILBOX_ID); + MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2); } - @Test(expected = AssertionError.class) - public void isEqualToShouldFailWithNotEqualNamespace() { + @Test + void isEqualToShouldFailWithNotEqualNamespace() { Mailbox mailbox1 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); Mailbox mailbox2 = new Mailbox(new MailboxPath("other_namespace", "user", "name"), UID_VALIDITY); mailbox1.setMailboxId(MAILBOX_ID); mailbox2.setMailboxId(MAILBOX_ID); - MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2); + + assertThatThrownBy(() -> MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void isEqualToShouldFailWithNotEqualUser() { + @Test + void isEqualToShouldFailWithNotEqualUser() { Mailbox mailbox1 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); Mailbox mailbox2 = new Mailbox(new MailboxPath("namespace", "other_user", "name"), UID_VALIDITY); mailbox1.setMailboxId(MAILBOX_ID); mailbox2.setMailboxId(MAILBOX_ID); - MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2); + + assertThatThrownBy(() -> MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void isEqualToShouldFailWithNotEqualName() { + @Test + void isEqualToShouldFailWithNotEqualName() { Mailbox mailbox1 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); Mailbox mailbox2 = new Mailbox(new MailboxPath("namespace", "user", "other_name"), UID_VALIDITY); mailbox1.setMailboxId(MAILBOX_ID); mailbox2.setMailboxId(MAILBOX_ID); - MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2); + + assertThatThrownBy(() -> MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void isEqualToShouldFailWithNotEqualId() { + @Test + void isEqualToShouldFailWithNotEqualId() { Mailbox mailbox1 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); Mailbox mailbox2 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); mailbox1.setMailboxId(MAILBOX_ID); mailbox2.setMailboxId(TestId.of(MAILBOX_ID.id + 1)); - MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2); + + assertThatThrownBy(() -> MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void isEqualToShouldFailWithNotEqualUidValidity() { + @Test + void isEqualToShouldFailWithNotEqualUidValidity() { Mailbox mailbox1 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY); Mailbox mailbox2 = new Mailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY + 1); mailbox1.setMailboxId(MAILBOX_ID); mailbox2.setMailboxId(MAILBOX_ID); - MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2); + + assertThatThrownBy(() -> MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2)) + .isInstanceOf(AssertionError.class); } } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java index e43f2ce..b7efa25 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java @@ -20,14 +20,14 @@ package org.apache.james.mailbox.model; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class MailboxCountersTest { +class MailboxCountersTest { @Test - public void mailboxCountersShouldRespectBeanContract() { + void mailboxCountersShouldRespectBeanContract() { EqualsVerifier.forClass(MailboxCounters.class).verify(); } } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java index d6606cc..b1817cc 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java @@ -23,20 +23,20 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; import org.apache.james.mailbox.DefaultMailboxes; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class MailboxPathTest { +class MailboxPathTest { @Test - public void shouldMatchBeanContract() { + void shouldMatchBeanContract() { EqualsVerifier.forClass(MailboxPath.class) .verify(); } @Test - public void getHierarchyLevelsShouldBeOrdered() { + void getHierarchyLevelsShouldBeOrdered() { assertThat(MailboxPath.forUser("user", "inbox.folder.subfolder") .getHierarchyLevels('.')) .containsExactly( @@ -46,7 +46,7 @@ public class MailboxPathTest { } @Test - public void getHierarchyLevelsShouldReturnPathWhenOneLevel() { + void getHierarchyLevelsShouldReturnPathWhenOneLevel() { assertThat(MailboxPath.forUser("user", "inbox") .getHierarchyLevels('.')) .containsExactly( @@ -54,7 +54,7 @@ public class MailboxPathTest { } @Test - public void getHierarchyLevelsShouldReturnPathWhenEmptyName() { + void getHierarchyLevelsShouldReturnPathWhenEmptyName() { assertThat(MailboxPath.forUser("user", "") .getHierarchyLevels('.')) .containsExactly( @@ -62,7 +62,7 @@ public class MailboxPathTest { } @Test - public void getHierarchyLevelsShouldReturnPathWhenNullName() { + void getHierarchyLevelsShouldReturnPathWhenNullName() { assertThat(MailboxPath.forUser("user", null) .getHierarchyLevels('.')) .containsExactly( @@ -70,7 +70,7 @@ public class MailboxPathTest { } @Test - public void sanitizeShouldNotThrowOnNullMailboxName() { + void sanitizeShouldNotThrowOnNullMailboxName() { assertThat(MailboxPath.forUser("user", null) .sanitize('.')) .isEqualTo( @@ -78,7 +78,7 @@ public class MailboxPathTest { } @Test - public void sanitizeShouldReturnEmptyWhenEmpty() { + void sanitizeShouldReturnEmptyWhenEmpty() { assertThat(MailboxPath.forUser("user", "") .sanitize('.')) .isEqualTo( @@ -86,7 +86,7 @@ public class MailboxPathTest { } @Test - public void sanitizeShouldRemoveMaximumOneTrailingDelimiterWhenAlone() { + void sanitizeShouldRemoveMaximumOneTrailingDelimiterWhenAlone() { assertThat(MailboxPath.forUser("user", ".") .sanitize('.')) .isEqualTo( @@ -94,7 +94,7 @@ public class MailboxPathTest { } @Test - public void sanitizeShouldPreserveHeadingDelimiter() { + void sanitizeShouldPreserveHeadingDelimiter() { assertThat(MailboxPath.forUser("user", ".a") .sanitize('.')) .isEqualTo( @@ -102,7 +102,7 @@ public class MailboxPathTest { } @Test - public void sanitizeShouldRemoveTrailingDelimiter() { + void sanitizeShouldRemoveTrailingDelimiter() { assertThat(MailboxPath.forUser("user", "a.") .sanitize('.')) .isEqualTo( @@ -110,7 +110,7 @@ public class MailboxPathTest { } @Test - public void sanitizeShouldRemoveMaximumOneTrailingDelimiter() { + void sanitizeShouldRemoveMaximumOneTrailingDelimiter() { assertThat(MailboxPath.forUser("user", "a..") .sanitize('.')) .isEqualTo( @@ -118,7 +118,7 @@ public class MailboxPathTest { } @Test - public void sanitizeShouldPreserveRedundantDelimiters() { + void sanitizeShouldPreserveRedundantDelimiters() { assertThat(MailboxPath.forUser("user", "a..a") .sanitize('.')) .isEqualTo( @@ -126,75 +126,75 @@ public class MailboxPathTest { } @Test - public void hasEmptyNameInHierarchyShouldBeFalseIfSingleLevelPath() { + void hasEmptyNameInHierarchyShouldBeFalseIfSingleLevelPath() { assertThat(MailboxPath.forUser("user", "a") .hasEmptyNameInHierarchy('.')) .isFalse(); } @Test - public void hasEmptyNameInHierarchyShouldBeFalseIfNestedLevelWithNonEmptyNames() { + void hasEmptyNameInHierarchyShouldBeFalseIfNestedLevelWithNonEmptyNames() { assertThat(MailboxPath.forUser("user", "a.b.c") .hasEmptyNameInHierarchy('.')) .isFalse(); } @Test - public void hasEmptyNameInHierarchyShouldBeTrueIfEmptyPath() { + void hasEmptyNameInHierarchyShouldBeTrueIfEmptyPath() { assertThat(MailboxPath.forUser("user", "") .hasEmptyNameInHierarchy('.')) .isTrue(); } @Test - public void hasEmptyNameInHierarchyShouldBeTrueIfPathWithTwoEmptyNames() { + void hasEmptyNameInHierarchyShouldBeTrueIfPathWithTwoEmptyNames() { assertThat(MailboxPath.forUser("user", ".") .hasEmptyNameInHierarchy('.')) .isTrue(); } @Test - public void hasEmptyNameInHierarchyShouldBeTrueIfPathWithAnEmptyNameBetweenTwoNames() { + void hasEmptyNameInHierarchyShouldBeTrueIfPathWithAnEmptyNameBetweenTwoNames() { assertThat(MailboxPath.forUser("user", "a..b") .hasEmptyNameInHierarchy('.')) .isTrue(); } @Test - public void hasEmptyNameInHierarchyShouldBeTrueIfPathWithHeadingEmptyNames() { + void hasEmptyNameInHierarchyShouldBeTrueIfPathWithHeadingEmptyNames() { assertThat(MailboxPath.forUser("user", "..a") .hasEmptyNameInHierarchy('.')) .isTrue(); } @Test - public void hasEmptyNameInHierarchyShouldBeTrueIfPathWithATrailingEmptyName() { + void hasEmptyNameInHierarchyShouldBeTrueIfPathWithATrailingEmptyName() { assertThat(MailboxPath.forUser("user", "a.") .hasEmptyNameInHierarchy('.')) .isTrue(); } @Test - public void hasEmptyNameInHierarchyShouldBeTrueIfPathWithTrailingEmptyNames() { + void hasEmptyNameInHierarchyShouldBeTrueIfPathWithTrailingEmptyNames() { assertThat(MailboxPath.forUser("user", "a..") .hasEmptyNameInHierarchy('.')) .isTrue(); } @Test - public void isInboxShouldReturnTrueWhenINBOX() { + void isInboxShouldReturnTrueWhenINBOX() { MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", DefaultMailboxes.INBOX); assertThat(mailboxPath.isInbox()).isTrue(); } @Test - public void isInboxShouldReturnTrueWhenINBOXWithOtherCase() { + void isInboxShouldReturnTrueWhenINBOXWithOtherCase() { MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", "InBoX"); assertThat(mailboxPath.isInbox()).isTrue(); } @Test - public void isInboxShouldReturnFalseWhenOtherThanInbox() { + void isInboxShouldReturnFalseWhenOtherThanInbox() { MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", DefaultMailboxes.ARCHIVE); assertThat(mailboxPath.isInbox()).isFalse(); } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java index 16828ae..edbc673 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java @@ -20,27 +20,30 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class MessageAttachmentTest { +class MessageAttachmentTest { - @Test(expected = IllegalStateException.class) - public void buildShouldThrowWhenAttachmentIsNotGiven() { - MessageAttachment.builder() - .build(); + @Test + void buildShouldThrowWhenAttachmentIsNotGiven() { + assertThatThrownBy(() -> MessageAttachment.builder() + .build()) + .isInstanceOf(IllegalStateException.class); } - @Test(expected = IllegalArgumentException.class) - public void builderShouldThrowWhenAttachmentIsNull() { - MessageAttachment.builder() - .attachment(null); + @Test + void builderShouldThrowWhenAttachmentIsNull() { + assertThatThrownBy(() -> MessageAttachment.builder() + .attachment(null)) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void buildShouldWorkWhenMandatoryAttributesAreGiven() { + void buildShouldWorkWhenMandatoryAttributesAreGiven() { Attachment attachment = Attachment.builder() .bytes("content".getBytes()) .type("type") @@ -55,7 +58,7 @@ public class MessageAttachmentTest { } @Test - public void buildShouldAcceptIsInlineAndNoCid() { + void buildShouldAcceptIsInlineAndNoCid() { Attachment attachment = Attachment.builder() .bytes("content".getBytes()) .type("type") @@ -70,7 +73,7 @@ public class MessageAttachmentTest { } @Test - public void buildShouldSetAttributesWhenAllAreGiven() { + void buildShouldSetAttributesWhenAllAreGiven() { Attachment attachment = Attachment.builder() .bytes("content".getBytes()) .type("type") @@ -88,7 +91,7 @@ public class MessageAttachmentTest { } @Test - public void isInlinedWithCidShouldReturnTrueWhenIsInlineAndHasCid() throws Exception { + void isInlinedWithCidShouldReturnTrueWhenIsInlineAndHasCid() throws Exception { Attachment attachment = Attachment.builder() .bytes("content".getBytes()) .type("type") @@ -105,7 +108,7 @@ public class MessageAttachmentTest { } @Test - public void isInlinedWithCidShouldReturnFalseWhenIsNotInline() throws Exception { + void isInlinedWithCidShouldReturnFalseWhenIsNotInline() throws Exception { Attachment attachment = Attachment.builder() .bytes("content".getBytes()) .type("type") @@ -122,7 +125,7 @@ public class MessageAttachmentTest { } @Test - public void isInlinedWithCidShouldReturnFalseWhenIsInlineButNoCid() throws Exception { + void isInlinedWithCidShouldReturnFalseWhenIsInlineButNoCid() throws Exception { Attachment attachment = Attachment.builder() .bytes("content".getBytes()) .type("type") diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageIdDtoTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageIdDtoTest.java index 0c7e74d..e55022b 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageIdDtoTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageIdDtoTest.java @@ -21,11 +21,11 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class MessageIdDtoTest { +class MessageIdDtoTest { private static final TestMessageId.Factory factory = new TestMessageId.Factory(); private static final Long SAMPLE_ID_VALUE = 42L; @@ -33,37 +33,38 @@ public class MessageIdDtoTest { private static final TestMessageId SAMPLE_ID = TestMessageId.of(SAMPLE_ID_VALUE); @Test - public void shouldRespectJavaBeanContract() { + void shouldRespectJavaBeanContract() { EqualsVerifier.forClass(MessageIdDto.class).verify(); } @Test - public void shouldAcceptStringAndGiveItBack() { + void shouldAcceptStringAndGiveItBack() { assertThat(new MessageIdDto(SAMPLE_ID_STRING).asString()) .isEqualTo(SAMPLE_ID_STRING); } @Test - public void shouldAcceptMessageIdAndGiveTheRightString() { + void shouldAcceptMessageIdAndGiveTheRightString() { assertThat(new MessageIdDto(SAMPLE_ID).asString()) .isEqualTo(SAMPLE_ID_STRING); } @Test - public void shouldAcceptMessageIdAndGiveItBack() { + void shouldAcceptMessageIdAndGiveItBack() { assertThat(new MessageIdDto(SAMPLE_ID).instantiate(factory)) .isEqualTo(SAMPLE_ID); } @Test - public void shouldAcceptStringAndGiveAnInstantiatedMessageId() { + void shouldAcceptStringAndGiveAnInstantiatedMessageId() { assertThat(new MessageIdDto(SAMPLE_ID_STRING).instantiate(factory)) .isEqualTo(SAMPLE_ID); } @Test - public void shouldThrowAnExceptionOnWronglyFormattedString() { + void shouldThrowAnExceptionOnWronglyFormattedString() { MessageIdDto messageIdDto = new MessageIdDto("Definitively not a number"); + assertThatThrownBy(() -> messageIdDto.instantiate(factory)) .isInstanceOf(Exception.class); } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java index 58e07d3..ab10eb0 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java @@ -1,155 +1,154 @@ -/**************************************************************** - * 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.model; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Arrays; -import java.util.List; - -import org.apache.james.mailbox.MessageUid; -import org.apache.james.mailbox.model.MessageRange; -import org.junit.Test; - -public class MessageRangeTest { - - @Test - public void givenSomeNumbersToRangeShouldReturnThreeRanges() { - List<MessageRange> ranges = MessageRange.toRanges( - Arrays.asList( - MessageUid.of(1L), - MessageUid.of(2L), - MessageUid.of(3L), - MessageUid.of(5L), - MessageUid.of(6L), - MessageUid.of(9L))); - assertThat(ranges).containsExactly( - MessageRange.range(MessageUid.of(1), MessageUid.of(3)), - MessageRange.range(MessageUid.of(5), MessageUid.of(6)), - MessageUid.of(9).toRange()); - } - - @Test - public void givenASingleNumberToRangeShouldReturnOneRange() { - List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(MessageUid.of(1L))); - assertThat(ranges).containsExactly(MessageUid.of(1).toRange()); - } - - // Test for MAILBOX-56 - @Test - public void testTwoSeqUidToRange() { - List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(MessageUid.of(1L), MessageUid.of(2L))); - assertThat(ranges).containsExactly(MessageRange.range(MessageUid.of(1), MessageUid.of(2))); - } - - @Test - public void splitASingletonRangeShouldReturnASingleRange() { - MessageRange one = MessageUid.of(1).toRange(); - List<MessageRange> ranges = one.split(2); - assertThat(ranges).containsExactly(MessageUid.of(1).toRange()); - } - - @Test - public void splitUnboundedRangeShouldReturnTheSameRange() { - MessageRange from = MessageRange.from(MessageUid.of(1)); - List<MessageRange> ranges = from.split(2); - assertThat(ranges).containsExactly(MessageRange.from(MessageUid.of(1))); - } - - @Test - public void splitTenElementsRangeShouldReturn4Ranges() { - MessageRange range = MessageRange.range(MessageUid.of(1),MessageUid.of(10)); - List<MessageRange> ranges = range.split(3); - assertThat(ranges).containsExactly( - MessageRange.range(MessageUid.of(1), MessageUid.of(3)), - MessageRange.range(MessageUid.of(4), MessageUid.of(6)), - MessageRange.range(MessageUid.of(7), MessageUid.of(9)), - MessageUid.of(10).toRange()); - } - - @Test - public void includeShouldBeTrueWhenAfterFrom() { - MessageRange range = MessageRange.from(MessageUid.of(3)); - boolean actual = range.includes(MessageUid.of(5)); - assertThat(actual).isTrue(); - } - - @Test - public void includeShouldBeFalseWhenBeforeFrom() { - MessageRange range = MessageRange.from(MessageUid.of(3)); - boolean actual = range.includes(MessageUid.of(1)); - assertThat(actual).isFalse(); - } - - @Test - public void includeShouldBeTrueWhenEqualsFrom() { - MessageRange range = MessageRange.from(MessageUid.of(3)); - boolean actual = range.includes(MessageUid.of(3)); - assertThat(actual).isTrue(); - } - - @Test - public void includeShouldBeFalseWhenDifferentOne() { - MessageRange range = MessageUid.of(3).toRange(); - boolean actual = range.includes(MessageUid.of(1)); - assertThat(actual).isFalse(); - } - - @Test - public void includeShouldBeTrueWhenEqualsOne() { - MessageRange range = MessageUid.of(3).toRange(); - boolean actual = range.includes(MessageUid.of(3)); - assertThat(actual).isTrue(); - } - - @Test - public void includeShouldBeFalseWhenBeforeRange() { - MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); - boolean actual = range.includes(MessageUid.of(1)); - assertThat(actual).isFalse(); - } - - @Test - public void includeShouldBeTrueWhenEqualsFromRange() { - MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); - boolean actual = range.includes(MessageUid.of(3)); - assertThat(actual).isTrue(); - } - - @Test - public void includeShouldBeTrueWhenInRange() { - MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); - boolean actual = range.includes(MessageUid.of(4)); - assertThat(actual).isTrue(); - } - - @Test - public void includeShouldBeTrueWhenEqualsToRange() { - MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); - boolean actual = range.includes(MessageUid.of(6)); - assertThat(actual).isTrue(); - } - - @Test - public void includeShouldBeFalseWhenAfterRange() { - MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); - boolean actual = range.includes(MessageUid.of(7)); - assertThat(actual).isFalse(); - } -} +/**************************************************************** + * 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.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.List; + +import org.apache.james.mailbox.MessageUid; +import org.junit.jupiter.api.Test; + +class MessageRangeTest { + + @Test + void givenSomeNumbersToRangeShouldReturnThreeRanges() { + List<MessageRange> ranges = MessageRange.toRanges( + Arrays.asList( + MessageUid.of(1L), + MessageUid.of(2L), + MessageUid.of(3L), + MessageUid.of(5L), + MessageUid.of(6L), + MessageUid.of(9L))); + assertThat(ranges).containsExactly( + MessageRange.range(MessageUid.of(1), MessageUid.of(3)), + MessageRange.range(MessageUid.of(5), MessageUid.of(6)), + MessageUid.of(9).toRange()); + } + + @Test + void givenASingleNumberToRangeShouldReturnOneRange() { + List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(MessageUid.of(1L))); + assertThat(ranges).containsExactly(MessageUid.of(1).toRange()); + } + + // Test for MAILBOX-56 + @Test + void testTwoSeqUidToRange() { + List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(MessageUid.of(1L), MessageUid.of(2L))); + assertThat(ranges).containsExactly(MessageRange.range(MessageUid.of(1), MessageUid.of(2))); + } + + @Test + void splitASingletonRangeShouldReturnASingleRange() { + MessageRange one = MessageUid.of(1).toRange(); + List<MessageRange> ranges = one.split(2); + assertThat(ranges).containsExactly(MessageUid.of(1).toRange()); + } + + @Test + void splitUnboundedRangeShouldReturnTheSameRange() { + MessageRange from = MessageRange.from(MessageUid.of(1)); + List<MessageRange> ranges = from.split(2); + assertThat(ranges).containsExactly(MessageRange.from(MessageUid.of(1))); + } + + @Test + void splitTenElementsRangeShouldReturn4Ranges() { + MessageRange range = MessageRange.range(MessageUid.of(1),MessageUid.of(10)); + List<MessageRange> ranges = range.split(3); + assertThat(ranges).containsExactly( + MessageRange.range(MessageUid.of(1), MessageUid.of(3)), + MessageRange.range(MessageUid.of(4), MessageUid.of(6)), + MessageRange.range(MessageUid.of(7), MessageUid.of(9)), + MessageUid.of(10).toRange()); + } + + @Test + void includeShouldBeTrueWhenAfterFrom() { + MessageRange range = MessageRange.from(MessageUid.of(3)); + boolean actual = range.includes(MessageUid.of(5)); + assertThat(actual).isTrue(); + } + + @Test + void includeShouldBeFalseWhenBeforeFrom() { + MessageRange range = MessageRange.from(MessageUid.of(3)); + boolean actual = range.includes(MessageUid.of(1)); + assertThat(actual).isFalse(); + } + + @Test + void includeShouldBeTrueWhenEqualsFrom() { + MessageRange range = MessageRange.from(MessageUid.of(3)); + boolean actual = range.includes(MessageUid.of(3)); + assertThat(actual).isTrue(); + } + + @Test + void includeShouldBeFalseWhenDifferentOne() { + MessageRange range = MessageUid.of(3).toRange(); + boolean actual = range.includes(MessageUid.of(1)); + assertThat(actual).isFalse(); + } + + @Test + void includeShouldBeTrueWhenEqualsOne() { + MessageRange range = MessageUid.of(3).toRange(); + boolean actual = range.includes(MessageUid.of(3)); + assertThat(actual).isTrue(); + } + + @Test + void includeShouldBeFalseWhenBeforeRange() { + MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); + boolean actual = range.includes(MessageUid.of(1)); + assertThat(actual).isFalse(); + } + + @Test + void includeShouldBeTrueWhenEqualsFromRange() { + MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); + boolean actual = range.includes(MessageUid.of(3)); + assertThat(actual).isTrue(); + } + + @Test + void includeShouldBeTrueWhenInRange() { + MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); + boolean actual = range.includes(MessageUid.of(4)); + assertThat(actual).isTrue(); + } + + @Test + void includeShouldBeTrueWhenEqualsToRange() { + MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); + boolean actual = range.includes(MessageUid.of(6)); + assertThat(actual).isTrue(); + } + + @Test + void includeShouldBeFalseWhenAfterRange() { + MessageRange range = MessageRange.range(MessageUid.of(3), MessageUid.of(6)); + boolean actual = range.includes(MessageUid.of(7)); + assertThat(actual).isFalse(); + } +} diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MultimailboxesSearchQueryTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MultimailboxesSearchQueryTest.java index 8430f08..9f08817 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MultimailboxesSearchQueryTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MultimailboxesSearchQueryTest.java @@ -19,76 +19,84 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableSet; -public class MultimailboxesSearchQueryTest { +class MultimailboxesSearchQueryTest { private static final SearchQuery EMPTY_QUERY = new SearchQuery(); private static final TestId.Factory FACTORY = new TestId.Factory(); private static final MailboxId ID_1 = FACTORY.fromString("1"); private static final MailboxId ID_2 = FACTORY.fromString("2"); - @Test(expected = NullPointerException.class) - public void buildShouldThrowWhenQueryIsNull() { - MultimailboxesSearchQuery.from(null); + @Test + void buildShouldThrowWhenQueryIsNull() { + assertThatThrownBy(() -> MultimailboxesSearchQuery.from(null)) + .isInstanceOf(NullPointerException.class); } @Test - public void buildShouldBuildWheninMailboxes() { + void buildShouldBuildWheninMailboxes() { ImmutableSet<MailboxId> inMailboxes = ImmutableSet.of(); ImmutableSet<MailboxId> notInMailboxes = ImmutableSet.of(); MultimailboxesSearchQuery expected = new MultimailboxesSearchQuery(EMPTY_QUERY, inMailboxes, notInMailboxes); MultimailboxesSearchQuery actual = MultimailboxesSearchQuery.from(EMPTY_QUERY).build(); + assertThat(actual).isEqualToComparingFieldByField(expected); } @Test - public void buildShouldBuildWhenEmptyMailboxes() { + void buildShouldBuildWhenEmptyMailboxes() { ImmutableSet<MailboxId> inMailboxes = ImmutableSet.of(); ImmutableSet<MailboxId> notInMailboxes = ImmutableSet.of(); MultimailboxesSearchQuery expected = new MultimailboxesSearchQuery(EMPTY_QUERY, inMailboxes, notInMailboxes); MultimailboxesSearchQuery actual = MultimailboxesSearchQuery.from(EMPTY_QUERY).inMailboxes().build(); + assertThat(actual).isEqualToComparingFieldByField(expected); } @Test - public void buildShouldBuildWhenEmptyNotInMailboxes() { + void buildShouldBuildWhenEmptyNotInMailboxes() { ImmutableSet<MailboxId> inMailboxes = ImmutableSet.of(); ImmutableSet<MailboxId> notInMailboxes = ImmutableSet.of(); MultimailboxesSearchQuery expected = new MultimailboxesSearchQuery(EMPTY_QUERY, inMailboxes, notInMailboxes); MultimailboxesSearchQuery actual = MultimailboxesSearchQuery.from(EMPTY_QUERY).notInMailboxes().build(); + assertThat(actual).isEqualToComparingFieldByField(expected); } @Test - public void buildShouldBuildWhenOneMailbox() { + void buildShouldBuildWhenOneMailbox() { ImmutableSet<MailboxId> inMailboxes = ImmutableSet.of(ID_1); ImmutableSet<MailboxId> notInMailboxes = ImmutableSet.of(); MultimailboxesSearchQuery expected = new MultimailboxesSearchQuery(EMPTY_QUERY, inMailboxes, notInMailboxes); MultimailboxesSearchQuery actual = MultimailboxesSearchQuery.from(EMPTY_QUERY).inMailboxes(ID_1).build(); + assertThat(actual).isEqualToComparingFieldByField(expected); } @Test - public void buildShouldBuildWhenOneNotInMailbox() { + void buildShouldBuildWhenOneNotInMailbox() { ImmutableSet<MailboxId> inMailboxes = ImmutableSet.of(); ImmutableSet<MailboxId> notInMailboxes = ImmutableSet.of(ID_1); MultimailboxesSearchQuery expected = new MultimailboxesSearchQuery(EMPTY_QUERY, inMailboxes, notInMailboxes); MultimailboxesSearchQuery actual = MultimailboxesSearchQuery.from(EMPTY_QUERY).notInMailboxes(ID_1).build(); + assertThat(actual).isEqualToComparingFieldByField(expected); } @Test - public void buildShouldBuildWhenAllDefined() { + void buildShouldBuildWhenAllDefined() { ImmutableSet<MailboxId> inMailboxes = ImmutableSet.of(ID_1); ImmutableSet<MailboxId> notInMailboxes = ImmutableSet.of(ID_2); MultimailboxesSearchQuery expected = new MultimailboxesSearchQuery(EMPTY_QUERY, inMailboxes, notInMailboxes); MultimailboxesSearchQuery actual = MultimailboxesSearchQuery.from(EMPTY_QUERY).inMailboxes(ID_1).notInMailboxes(ID_2).build(); + assertThat(actual).isEqualToComparingFieldByField(expected); } diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java index e11ebdc..f1633bc 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java @@ -24,69 +24,69 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class QuotaTest { +class QuotaTest { @Test - public void isOverQuotaShouldReturnFalseWhenQuotaIsNotExceeded() { + void isOverQuotaShouldReturnFalseWhenQuotaIsNotExceeded() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.count(360)).build(); assertThat(quota.isOverQuota()).isFalse(); } @Test - public void isOverQuotaShouldReturnFalseWhenMaxValueIsUnlimited() { + void isOverQuotaShouldReturnFalseWhenMaxValueIsUnlimited() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.unlimited()).build(); assertThat(quota.isOverQuota()).isFalse(); } @Test - public void isOverQuotaShouldReturnTrueWhenQuotaIsExceeded() { + void isOverQuotaShouldReturnTrueWhenQuotaIsExceeded() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(360)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuota()).isTrue(); } @Test - public void isOverQuotaWithAdditionalValueShouldReturnTrueWhenOverLimit() { + void isOverQuotaWithAdditionalValueShouldReturnTrueWhenOverLimit() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuotaWithAdditionalValue(1)).isTrue(); } @Test - public void isOverQuotaWithAdditionalValueShouldReturnTrueWhenUnderLimit() { + void isOverQuotaWithAdditionalValueShouldReturnTrueWhenUnderLimit() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(34)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuotaWithAdditionalValue(1)).isFalse(); } @Test - public void isOverQuotaWithAdditionalValueShouldReturnFalseWhenAtLimit() { + void isOverQuotaWithAdditionalValueShouldReturnFalseWhenAtLimit() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuotaWithAdditionalValue(0)).isFalse(); } @Test - public void isOverQuotaWithAdditionalValueShouldThrowOnNegativeValue() { + void isOverQuotaWithAdditionalValueShouldThrowOnNegativeValue() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(25)).computedLimit(QuotaCount.count(36)).build(); assertThatThrownBy(() -> quota.isOverQuotaWithAdditionalValue(-1)).isInstanceOf(IllegalArgumentException.class); } @Test - public void buildShouldThrowOnMissingUsedValue() { + void buildShouldThrowOnMissingUsedValue() { assertThatThrownBy( () -> Quota.<QuotaCount>builder().computedLimit(QuotaCount.count(1)).build()) .isInstanceOf(IllegalStateException.class); } @Test - public void buildShouldThrowOnMissingComputedLimitValue() { + void buildShouldThrowOnMissingComputedLimitValue() { assertThatThrownBy( () -> Quota.<QuotaCount>builder().used(QuotaCount.count(1)).build()) .isInstanceOf(IllegalStateException.class); } @Test - public void buildShouldCreateValidObjectGivenMandatoryFields() { + void buildShouldCreateValidObjectGivenMandatoryFields() { Quota<QuotaCount> actual = Quota.<QuotaCount>builder() .used(QuotaCount.count(1)) .computedLimit(QuotaCount.count(2)) @@ -95,7 +95,7 @@ public class QuotaTest { } @Test - public void getRatioShouldReturnUsedDividedByLimit() { + void getRatioShouldReturnUsedDividedByLimit() { assertThat( Quota.<QuotaSize>builder() .used(QuotaSize.size(15)) @@ -106,7 +106,7 @@ public class QuotaTest { } @Test - public void getRatioShouldReturnZeroWhenUnlimited() { + void getRatioShouldReturnZeroWhenUnlimited() { assertThat( Quota.<QuotaSize>builder() .used(QuotaSize.size(15)) diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java index 46c069c..8f54432 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/Rfc4314RightsTest.java @@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.apache.james.mailbox.exception.UnsupportedRightException; import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class Rfc4314RightsTest { +class Rfc4314RightsTest { private Rfc4314Rights aeik; private Rfc4314Rights lprs; @@ -47,8 +47,8 @@ public class Rfc4314RightsTest { private Rfc4314Rights full; private Rfc4314Rights none; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { aeik = Rfc4314Rights.fromSerializedRfc4314Rights("aeik"); lprs = Rfc4314Rights.fromSerializedRfc4314Rights("lprs"); twx = Rfc4314Rights.fromSerializedRfc4314Rights("twx"); @@ -56,55 +56,56 @@ public class Rfc4314RightsTest { none = MailboxACL.NO_RIGHTS; } - @Test(expected = NullPointerException.class) - public void newInstanceShouldThrowWhenNullString() throws UnsupportedRightException { - Rfc4314Rights.fromSerializedRfc4314Rights((String) null); + @Test + void newInstanceShouldThrowWhenNullString() throws UnsupportedRightException { + assertThatThrownBy(() -> Rfc4314Rights.fromSerializedRfc4314Rights((String) null)) + .isInstanceOf(NullPointerException.class); } @Test - public void newInstanceShouldHaveNoRightsWhenEmptyString() throws UnsupportedRightException { + void newInstanceShouldHaveNoRightsWhenEmptyString() throws UnsupportedRightException { Rfc4314Rights rights = Rfc4314Rights.fromSerializedRfc4314Rights(""); assertThat(rights.list()).isEmpty(); } @Test - public void containsShouldReturnFalseWhenNotMatching() throws UnsupportedRightException { + void containsShouldReturnFalseWhenNotMatching() throws UnsupportedRightException { assertThat(aeik.contains('x')).isFalse(); } @Test - public void containsShouldReturnTrueWhenMatching() throws UnsupportedRightException { + void containsShouldReturnTrueWhenMatching() throws UnsupportedRightException { assertThat(aeik.contains('e')).isTrue(); } @Test - public void exceptShouldRemoveAllWhenChaining() throws UnsupportedRightException { + void exceptShouldRemoveAllWhenChaining() throws UnsupportedRightException { assertThat(full.except(aeik).except(lprs).except(twx)).isEqualTo(none); } @Test - public void exceptShouldReturnOriginWhenExceptingNull() throws UnsupportedRightException { + void exceptShouldReturnOriginWhenExceptingNull() throws UnsupportedRightException { assertThat(aeik.except(null)).isEqualTo(aeik); } @Test - public void exceptShouldReturnOriginWhenExceptingNonExistent() throws UnsupportedRightException { + void exceptShouldReturnOriginWhenExceptingNonExistent() throws UnsupportedRightException { assertThat(aeik.except(lprs)).isEqualTo(aeik); } @Test - public void rfc4314RightsShouldThrowWhenUnknownFlag() throws UnsupportedRightException { + void rfc4314RightsShouldThrowWhenUnknownFlag() { assertThatThrownBy(() -> Rfc4314Rights.fromSerializedRfc4314Rights("z")) .isInstanceOf(UnsupportedRightException.class); } @Test - public void exceptShouldReturnOriginWhenExceptingEmpty() throws UnsupportedRightException { + void exceptShouldReturnOriginWhenExceptingEmpty() throws UnsupportedRightException { assertThat(aeik.except(none)).isEqualTo(aeik); } @Test - public void fullRightsShouldContainsAllRights() { + void fullRightsShouldContainsAllRights() { assertThat(full.list()).containsOnly( Administer, PerformExpunge, @@ -120,12 +121,12 @@ public class Rfc4314RightsTest { } @Test - public void noneRightsShouldContainsNoRights() { + void noneRightsShouldContainsNoRights() { assertThat(none.list()).isEmpty(); } @Test - public void rightsShouldContainsSpecificRightsWhenAEIK() { + void rightsShouldContainsSpecificRightsWhenAEIK() { assertThat(aeik.list()).containsOnly( Administer, PerformExpunge, @@ -134,7 +135,7 @@ public class Rfc4314RightsTest { } @Test - public void rightsShouldContainsSpecificRightsWhenLPRS() { + void rightsShouldContainsSpecificRightsWhenLPRS() { assertThat(lprs.list()).containsOnly( Lookup, Post, @@ -143,7 +144,7 @@ public class Rfc4314RightsTest { } @Test - public void rightsShouldContainsSpecificRightsWhenTWX() { + void rightsShouldContainsSpecificRightsWhenTWX() { assertThat(twx.list()).containsOnly( DeleteMessages, Write, @@ -151,92 +152,92 @@ public class Rfc4314RightsTest { } @Test - public void getValueShouldReturnSigmaWhenAeik() throws UnsupportedRightException { + void getValueShouldReturnSigmaWhenAeik() { assertThat(aeik.list()).containsExactly(Administer, PerformExpunge, Insert, CreateMailbox); } @Test - public void getValueShouldReturnSigmaWhenLprs() throws UnsupportedRightException { + void getValueShouldReturnSigmaWhenLprs() { assertThat(lprs.list()).containsExactly(Lookup, Post, Read, WriteSeenFlag); } @Test - public void getValueShouldReturnSigmaWhenTwx() throws UnsupportedRightException { + void getValueShouldReturnSigmaWhenTwx() { assertThat(twx.list()).containsExactly(DeleteMessages, Write, DeleteMailbox); } @Test - public void getValueShouldReturnEmptyWhenNone() throws UnsupportedRightException { + void getValueShouldReturnEmptyWhenNone() throws UnsupportedRightException { assertThat(Rfc4314Rights.fromSerializedRfc4314Rights("").list()).isEmpty(); } @Test - public void serializeShouldReturnStringWhenAeik() throws UnsupportedRightException { + void serializeShouldReturnStringWhenAeik() { assertThat(aeik.serialize()).isEqualTo("aeik"); } @Test - public void serializeShouldReturnStringWhenLprs() throws UnsupportedRightException { + void serializeShouldReturnStringWhenLprs() { assertThat(lprs.serialize()).isEqualTo("lprs"); } @Test - public void serializeShouldReturnStringWhenTwx() throws UnsupportedRightException { + void serializeShouldReturnStringWhenTwx() { assertThat(twx.serialize()).isEqualTo("twx"); } @Test - public void serializeShouldReturnStringWhenAeiklprstwx() throws UnsupportedRightException { + void serializeShouldReturnStringWhenAeiklprstwx() { assertThat(full.serialize()).isEqualTo("aeiklprstwx"); } @Test - public void serializeShouldReturnEmptyStringWhenEmpty() throws UnsupportedRightException { + void serializeShouldReturnEmptyStringWhenEmpty() { assertThat(none.serialize()).isEmpty(); } @Test - public void unionShouldReturnFullWhenChaining() throws UnsupportedRightException { + void unionShouldReturnFullWhenChaining() throws UnsupportedRightException { assertThat(aeik.union(lprs).union(twx)).isEqualTo(full); } @Test - public void unionShouldReturnOriginWhenAppliedWithEmpty() throws UnsupportedRightException { + void unionShouldReturnOriginWhenAppliedWithEmpty() throws UnsupportedRightException { assertThat(lprs.union(none)).isEqualTo(lprs); } @Test - public void unionShouldThrowWhenAppliedWithNull() throws UnsupportedRightException { + void unionShouldThrowWhenAppliedWithNull() { assertThatThrownBy(() -> lprs.union(null)).isInstanceOf(NullPointerException.class); } @Test - public void containsShouldReturnFalseWhenRightNotPresent() throws UnsupportedRightException { + void containsShouldReturnFalseWhenRightNotPresent() { assertThat(lprs.contains(Write)).isFalse(); } @Test - public void containsShouldReturnFalseWhenAtLeastOneRightNotPresent() throws UnsupportedRightException { + void containsShouldReturnFalseWhenAtLeastOneRightNotPresent() { assertThat(lprs.contains(Lookup, Write)).isFalse(); } @Test - public void containsShouldReturnTrueWhenAllRightsPresent() throws UnsupportedRightException { + void containsShouldReturnTrueWhenAllRightsPresent() { assertThat(lprs.contains(Lookup, Post)).isTrue(); } @Test - public void containsShouldReturnTrueWhenNonRightsPresent() throws UnsupportedRightException { + void containsShouldReturnTrueWhenNonRightsPresent() { assertThat(lprs.contains()).isTrue(); } @Test - public void allExceptShouldReturnFullWhenProvidedEmpty() throws UnsupportedRightException { + void allExceptShouldReturnFullWhenProvidedEmpty() throws UnsupportedRightException { assertThat(Rfc4314Rights.allExcept()).isEqualTo(MailboxACL.FULL_RIGHTS); } @Test - public void allExceptShouldReturnAllButProvidedRight() throws UnsupportedRightException { + void allExceptShouldReturnAllButProvidedRight() throws UnsupportedRightException { assertThat(Rfc4314Rights.allExcept(Lookup)) .isEqualTo(new Rfc4314Rights( DeleteMessages, @@ -252,7 +253,7 @@ public class Rfc4314RightsTest { } @Test - public void allExceptShouldReturnAllButProvidedRights() throws UnsupportedRightException { + void allExceptShouldReturnAllButProvidedRights() throws UnsupportedRightException { assertThat(Rfc4314Rights.allExcept(Lookup, Read)) .isEqualTo(new Rfc4314Rights( DeleteMessages, @@ -267,7 +268,7 @@ public class Rfc4314RightsTest { } @Test - public void allExceptShouldReturnEmptyWhenProvidedAllRights() throws UnsupportedRightException { + void allExceptShouldReturnEmptyWhenProvidedAllRights() throws UnsupportedRightException { assertThat( Rfc4314Rights.allExcept( Lookup, diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java index b5725a6..2011617 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java @@ -22,21 +22,21 @@ package org.apache.james.mailbox.model; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class SearchQueryTest { +class SearchQueryTest { @Test - public void searchQueryShouldRespectBeanContract() { + void searchQueryShouldRespectBeanContract() { EqualsVerifier.forClass(SearchQuery.class) .withOnlyTheseFields("criterias") .verify(); } @Test - public void equalsShouldCompareCriteria() { + void equalsShouldCompareCriteria() { SearchQuery searchQuery1 = new SearchQuery(); SearchQuery searchQuery2 = new SearchQuery(); searchQuery1.andCriteria(SearchQuery.all()); diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java index e79e566..1c81a4d 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java @@ -24,24 +24,24 @@ import static org.assertj.core.api.Assertions.assertThat; import javax.mail.Flags; import org.apache.james.mailbox.MessageUid; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class UpdatedFlagsTest { +class UpdatedFlagsTest { public static final MessageUid UID = MessageUid.of(45L); public static final long MOD_SEQ = 47L; @Test - public void shouldMatchBeanContract() { + void shouldMatchBeanContract() { EqualsVerifier.forClass(UpdatedFlags.class) .withIgnoredFields("modifiedFlags") .verify(); } @Test - public void isModifiedToSetShouldReturnTrueWhenFlagOnlyInNewFlag() { + void isModifiedToSetShouldReturnTrueWhenFlagOnlyInNewFlag() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags(Flags.Flag.RECENT)) .oldFlags(new Flags()) @@ -53,7 +53,7 @@ public class UpdatedFlagsTest { } @Test - public void isModifiedToSetShouldReturnFalseWhenFlagOnlyInOldFlag() { + void isModifiedToSetShouldReturnFalseWhenFlagOnlyInOldFlag() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags()) .oldFlags(new Flags(Flags.Flag.RECENT)) @@ -65,7 +65,7 @@ public class UpdatedFlagsTest { } @Test - public void isModifiedToSetShouldReturnFalseWhenFlagIsOnNone() { + void isModifiedToSetShouldReturnFalseWhenFlagIsOnNone() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags()) .oldFlags(new Flags()) @@ -77,7 +77,7 @@ public class UpdatedFlagsTest { } @Test - public void isModifiedToSetShouldReturnFalseWhenFlagIsOnBoth() { + void isModifiedToSetShouldReturnFalseWhenFlagIsOnBoth() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags(Flags.Flag.RECENT)) .oldFlags(new Flags(Flags.Flag.RECENT)) @@ -89,7 +89,7 @@ public class UpdatedFlagsTest { } @Test - public void isModifiedToUnsetShouldReturnFalseWhenFlagOnlyInNewFlag() { + void isModifiedToUnsetShouldReturnFalseWhenFlagOnlyInNewFlag() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags(Flags.Flag.RECENT)) .oldFlags(new Flags()) @@ -101,7 +101,7 @@ public class UpdatedFlagsTest { } @Test - public void isModifiedToUnsetShouldReturnTrueWhenFlagOnlyInOldFlag() { + void isModifiedToUnsetShouldReturnTrueWhenFlagOnlyInOldFlag() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags()) .oldFlags(new Flags(Flags.Flag.RECENT)) @@ -113,7 +113,7 @@ public class UpdatedFlagsTest { } @Test - public void isModifiedToUnsetShouldReturnFalseWhenFlagIsOnNone() { + void isModifiedToUnsetShouldReturnFalseWhenFlagIsOnNone() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags()) .oldFlags(new Flags()) @@ -125,7 +125,7 @@ public class UpdatedFlagsTest { } @Test - public void isModifiedToUnsetShouldReturnFalseWhenFlagIsOnBoth() { + void isModifiedToUnsetShouldReturnFalseWhenFlagIsOnBoth() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags(Flags.Flag.RECENT)) .oldFlags(new Flags(Flags.Flag.RECENT)) @@ -137,7 +137,7 @@ public class UpdatedFlagsTest { } @Test - public void isUnchangedShouldReturnFalseWhenFlagOnlyInNewFlag() { + void isUnchangedShouldReturnFalseWhenFlagOnlyInNewFlag() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags(Flags.Flag.RECENT)) .oldFlags(new Flags()) @@ -149,7 +149,7 @@ public class UpdatedFlagsTest { } @Test - public void isUnchangedShouldReturnFalseWhenFlagOnlyInOldFlag() { + void isUnchangedShouldReturnFalseWhenFlagOnlyInOldFlag() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags()) .oldFlags(new Flags(Flags.Flag.RECENT)) @@ -161,7 +161,7 @@ public class UpdatedFlagsTest { } @Test - public void isUnchangedShouldReturnTrueWhenFlagIsOnNone() { + void isUnchangedShouldReturnTrueWhenFlagIsOnNone() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags()) .oldFlags(new Flags()) @@ -173,7 +173,7 @@ public class UpdatedFlagsTest { } @Test - public void isUnchangedShouldReturnTrueWhenFlagIsOnBoth() { + void isUnchangedShouldReturnTrueWhenFlagIsOnBoth() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags(Flags.Flag.RECENT)) .oldFlags(new Flags(Flags.Flag.RECENT)) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org