JAMES-2352 port webadmin-mailbox to junit 5
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/cb3a6e60 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cb3a6e60 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cb3a6e60 Branch: refs/heads/master Commit: cb3a6e60ada6b5aed49ae8c2951dc121e814e41a Parents: b588e8c Author: Matthieu Baechler <matth...@apache.org> Authored: Thu Mar 15 17:24:15 2018 +0100 Committer: benwa <btell...@linagora.com> Committed: Tue Mar 27 15:13:47 2018 +0700 ---------------------------------------------------------------------- .../protocols/webadmin/webadmin-mailbox/pom.xml | 26 ++-- .../dto/QuotaValueDeserializerTest.java | 6 +- .../DomainQuotaRoutesNoVirtualHostingTest.java | 76 ++++------ .../webadmin/routes/DomainQuotaRoutesTest.java | 70 ++++----- .../webadmin/routes/GlobalQuotaRoutesTest.java | 51 +++---- .../routes/UserMailboxesRoutesTest.java | 151 +++++++++---------- .../webadmin/routes/UserQuotaRoutesTest.java | 84 +++++------ .../webadmin/validation/QuotaValueTest.java | 24 +-- 8 files changed, 233 insertions(+), 255 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/pom.xml ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/pom.xml b/server/protocols/webadmin/webadmin-mailbox/pom.xml index bfed1ee..5e12fcf 100644 --- a/server/protocols/webadmin/webadmin-mailbox/pom.xml +++ b/server/protocols/webadmin/webadmin-mailbox/pom.xml @@ -102,21 +102,10 @@ <scope>test</scope> </dependency> <dependency> - <groupId>de.bechte.junit</groupId> - <artifactId>junit-hierarchicalcontextrunner</artifactId> - <version>4.11.3</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> @@ -127,6 +116,21 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.platform</groupId> + <artifactId>junit-platform-launcher</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/QuotaValueDeserializerTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/QuotaValueDeserializerTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/QuotaValueDeserializerTest.java index 2293b50..e47256a 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/QuotaValueDeserializerTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/QuotaValueDeserializerTest.java @@ -23,14 +23,14 @@ import org.apache.james.mailbox.quota.QuotaSize; import org.apache.james.webadmin.utils.JsonExtractException; import org.apache.james.webadmin.utils.JsonExtractor; import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.module.SimpleModule; -public class QuotaValueDeserializerTest { +class QuotaValueDeserializerTest { @Test - public void objectDeserializeShouldContainGivenValues() throws JsonExtractException { + void objectDeserializeShouldContainGivenValues() throws JsonExtractException { String payload = "{\"count\":52,\"size\":42}"; QuotaDTO actual = new JsonExtractor<>(QuotaDTO.class, new SimpleModule() http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java index ddb89b7..bfca198 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java @@ -22,8 +22,6 @@ package org.apache.james.webadmin.routes; import static com.jayway.restassured.RestAssured.given; import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION; -import java.util.Collection; - import org.apache.james.core.Domain; import org.apache.james.dnsservice.api.InMemoryDNSService; import org.apache.james.domainlist.memory.MemoryDomainList; @@ -35,19 +33,15 @@ import org.apache.james.webadmin.WebAdminUtils; import org.apache.james.webadmin.jackson.QuotaModule; import org.apache.james.webadmin.utils.JsonTransformer; import org.eclipse.jetty.http.HttpStatus; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.jayway.restassured.RestAssured; -@RunWith(Parameterized.class) -public class DomainQuotaRoutesNoVirtualHostingTest { +class DomainQuotaRoutesNoVirtualHostingTest { private static final String QUOTA_DOMAINS = "/quota/domains"; private static final String FOUND_COM = "found.com"; @@ -55,21 +49,8 @@ public class DomainQuotaRoutesNoVirtualHostingTest { private static final String SIZE = "size"; private WebAdminServer webAdminServer; - @Parameters - public static Collection<Object[]> data() { - return ImmutableList.of( - new String[] {QUOTA_DOMAINS + "/" + FOUND_COM + "/" + COUNT}, - new String[] {QUOTA_DOMAINS + "/" + FOUND_COM + "/" + SIZE}); - } - - private String endpoint; - - public DomainQuotaRoutesNoVirtualHostingTest(String endpoint) { - this.endpoint = endpoint; - } - - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { InMemoryPerUserMaxQuotaManager maxQuotaManager = new InMemoryPerUserMaxQuotaManager(); MemoryDomainList memoryDomainList = new MemoryDomainList(new InMemoryDNSService()); memoryDomainList.setAutoDetect(false); @@ -89,49 +70,44 @@ public class DomainQuotaRoutesNoVirtualHostingTest { RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); } - @After - public void stop() { + @AfterEach + void stop() { webAdminServer.destroy(); } - @Test - public void allGetEndpointsShouldReturnNotAllowed() { + @ParameterizedTest + @ValueSource(strings = { + QUOTA_DOMAINS + "/" + FOUND_COM, + QUOTA_DOMAINS + "/" + FOUND_COM + "/" + COUNT, + QUOTA_DOMAINS + "/" + FOUND_COM + "/" + SIZE }) + void allGetEndpointsShouldReturnNotAllowed(String endpoint) { given() .get(endpoint) .then() .statusCode(HttpStatus.METHOD_NOT_ALLOWED_405); } - @Test - public void allPutEndpointsShouldReturnNotAllowed() { + @ParameterizedTest + @ValueSource(strings = { + QUOTA_DOMAINS + "/" + FOUND_COM, + QUOTA_DOMAINS + "/" + FOUND_COM + "/" + COUNT, + QUOTA_DOMAINS + "/" + FOUND_COM + "/" + SIZE }) + void allPutEndpointsShouldReturnNotAllowed(String endpoint) { given() .put(endpoint) .then() .statusCode(HttpStatus.METHOD_NOT_ALLOWED_405); } - @Test - public void allDeleteEndpointsShouldReturnNotAllowed() { + @ParameterizedTest + @ValueSource(strings = { + QUOTA_DOMAINS + "/" + FOUND_COM + "/" + COUNT, + QUOTA_DOMAINS + "/" + FOUND_COM + "/" + SIZE }) + void allDeleteEndpointsShouldReturnNotAllowed(String endpoint) { given() .delete(endpoint) .then() .statusCode(HttpStatus.METHOD_NOT_ALLOWED_405); } - @Test - public void domainGetEndpointsShouldReturnNotAllowed() { - given() - .get(QUOTA_DOMAINS + "/" + FOUND_COM) - .then() - .statusCode(HttpStatus.METHOD_NOT_ALLOWED_405); - } - - @Test - public void domainPutEndpointsShouldReturnNotAllowed() { - given() - .put(QUOTA_DOMAINS + "/" + FOUND_COM) - .then() - .statusCode(HttpStatus.METHOD_NOT_ALLOWED_405); - } - } http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java index 816e184..2e96dda 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java @@ -39,16 +39,16 @@ import org.apache.james.webadmin.WebAdminUtils; import org.apache.james.webadmin.jackson.QuotaModule; import org.apache.james.webadmin.utils.JsonTransformer; import org.eclipse.jetty.http.HttpStatus; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableSet; import com.jayway.restassured.RestAssured; import com.jayway.restassured.http.ContentType; import com.jayway.restassured.path.json.JsonPath; -public class DomainQuotaRoutesTest { +class DomainQuotaRoutesTest { private static final String QUOTA_DOMAINS = "/quota/domains"; private static final String PERDU_COM = "perdu.com"; @@ -58,8 +58,8 @@ public class DomainQuotaRoutesTest { private WebAdminServer webAdminServer; private InMemoryPerUserMaxQuotaManager maxQuotaManager; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { maxQuotaManager = new InMemoryPerUserMaxQuotaManager(); MemoryDomainList memoryDomainList = new MemoryDomainList(new InMemoryDNSService()); memoryDomainList.setAutoDetect(false); @@ -80,13 +80,13 @@ public class DomainQuotaRoutesTest { RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); } - @After - public void stop() { + @AfterEach + void stop() { webAdminServer.destroy(); } @Test - public void getCountShouldReturnNotFoundWhenDomainDoesntExist() { + void getCountShouldReturnNotFoundWhenDomainDoesntExist() { when() .get(QUOTA_DOMAINS + "/" + PERDU_COM + "/" + COUNT) .then() @@ -94,7 +94,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getCountShouldReturnNoContentByDefault() { + void getCountShouldReturnNoContentByDefault() { given() .get(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name() + "/" + COUNT) .then() @@ -102,7 +102,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getCountShouldReturnStoredValue() { + void getCountShouldReturnStoredValue() { int value = 42; maxQuotaManager.setDomainMaxMessage(TROUVÃ_COM, QuotaCount.count(value)); @@ -119,7 +119,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putCountShouldReturnNotFoundWhenDomainDoesntExist() { + void putCountShouldReturnNotFoundWhenDomainDoesntExist() { given() .body("123") .when() @@ -129,7 +129,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putCountShouldRejectInvalid() { + void putCountShouldRejectInvalid() { Map<String, Object> errors = given() .body("invalid") .put(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name() + "/" + COUNT) @@ -149,7 +149,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putCountShouldSetToInfiniteWhenMinusOne() { + void putCountShouldSetToInfiniteWhenMinusOne() { given() .body("-1") .when() @@ -161,7 +161,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putCountShouldRejectNegativeOtherThanMinusOne() { + void putCountShouldRejectNegativeOtherThanMinusOne() { Map<String, Object> errors = given() .body("-2") .put(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name() + "/" + COUNT) @@ -180,7 +180,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putCountShouldAcceptValidValue() { + void putCountShouldAcceptValidValue() { given() .body("42") .put(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name() + "/" + COUNT) @@ -191,7 +191,7 @@ public class DomainQuotaRoutesTest { } @Test - public void deleteCountShouldReturnNotFoundWhenDomainDoesntExist() { + void deleteCountShouldReturnNotFoundWhenDomainDoesntExist() { when() .delete(QUOTA_DOMAINS + "/" + PERDU_COM + "/" + COUNT) .then() @@ -199,7 +199,7 @@ public class DomainQuotaRoutesTest { } @Test - public void deleteCountShouldSetQuotaToEmpty() { + void deleteCountShouldSetQuotaToEmpty() { maxQuotaManager.setDomainMaxMessage(TROUVÃ_COM, QuotaCount.count(42)); given() @@ -211,7 +211,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getSizeShouldReturnNotFoundWhenDomainDoesntExist() { + void getSizeShouldReturnNotFoundWhenDomainDoesntExist() { when() .get(QUOTA_DOMAINS + "/" + PERDU_COM + "/" + SIZE) .then() @@ -219,7 +219,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getSizeShouldReturnNoContentByDefault() { + void getSizeShouldReturnNoContentByDefault() { when() .get(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name() + "/" + SIZE) .then() @@ -227,7 +227,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getSizeShouldReturnStoredValue() { + void getSizeShouldReturnStoredValue() { long value = 42; maxQuotaManager.setDomainMaxStorage(TROUVÃ_COM, QuotaSize.size(value)); @@ -245,7 +245,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putSizeShouldRejectInvalid() { + void putSizeShouldRejectInvalid() { Map<String, Object> errors = given() .body("invalid") .put(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name() + "/" + SIZE) @@ -265,7 +265,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putSizeShouldReturnNotFoundWhenDomainDoesntExist() { + void putSizeShouldReturnNotFoundWhenDomainDoesntExist() { given() .body("123") .when() @@ -275,7 +275,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putSizeShouldSetToInfiniteWhenMinusOne() { + void putSizeShouldSetToInfiniteWhenMinusOne() { given() .body("-1") .when() @@ -287,7 +287,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putSizeShouldRejectNegativeOtherThanMinusOne() { + void putSizeShouldRejectNegativeOtherThanMinusOne() { Map<String, Object> errors = given() .body("-2") .put(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name() + "/" + SIZE) @@ -306,7 +306,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putSizeShouldAcceptValidValue() { + void putSizeShouldAcceptValidValue() { given() .body("42") .when() @@ -318,7 +318,7 @@ public class DomainQuotaRoutesTest { } @Test - public void deleteSizeShouldReturnNotFoundWhenDomainDoesntExist() { + void deleteSizeShouldReturnNotFoundWhenDomainDoesntExist() { when() .delete(QUOTA_DOMAINS + "/" + PERDU_COM + "/" + SIZE) .then() @@ -326,7 +326,7 @@ public class DomainQuotaRoutesTest { } @Test - public void deleteSizeShouldSetQuotaToEmpty() { + void deleteSizeShouldSetQuotaToEmpty() { maxQuotaManager.setDomainMaxStorage(TROUVÃ_COM, QuotaSize.size(42)); given() @@ -338,7 +338,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getQuotaShouldReturnNotFoundWhenDomainDoesntExist() { + void getQuotaShouldReturnNotFoundWhenDomainDoesntExist() { when() .get(QUOTA_DOMAINS + "/" + PERDU_COM) .then() @@ -346,7 +346,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getQuotaShouldReturnBothEmptyWhenDefaultValues() { + void getQuotaShouldReturnBothEmptyWhenDefaultValues() { JsonPath jsonPath = given() .get(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name()) @@ -361,7 +361,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getQuotaShouldReturnSizeWhenNoCount() { + void getQuotaShouldReturnSizeWhenNoCount() { int maxStorage = 42; maxQuotaManager.setDomainMaxStorage(TROUVÃ_COM, QuotaSize.size(maxStorage)); @@ -379,7 +379,7 @@ public class DomainQuotaRoutesTest { } @Test - public void getQuotaShouldReturnBothWhenNoSize() { + void getQuotaShouldReturnBothWhenNoSize() { int maxMessage = 42; maxQuotaManager.setDomainMaxMessage(TROUVÃ_COM, QuotaCount.count(maxMessage)); @@ -398,7 +398,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putQuotaShouldReturnNotFoundWhenDomainDoesntExist() { + void putQuotaShouldReturnNotFoundWhenDomainDoesntExist() { when() .put(QUOTA_DOMAINS + "/" + PERDU_COM) .then() @@ -406,7 +406,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putQuotaShouldUpdateBothQuota() { + void putQuotaShouldUpdateBothQuota() { given() .body("{\"count\":52,\"size\":42}") .put(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name()) @@ -418,7 +418,7 @@ public class DomainQuotaRoutesTest { } @Test - public void putQuotaShouldBeAbleToRemoveBothQuota() { + void putQuotaShouldBeAbleToRemoveBothQuota() { given() .body("{\"count\":null,\"count\":null}") .put(QUOTA_DOMAINS + "/" + TROUVÃ_COM.name()) http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java index 8400558..c82cb45 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java @@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Map; -import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; @@ -38,21 +37,21 @@ import org.apache.james.webadmin.service.GlobalQuotaService; import org.apache.james.webadmin.utils.JsonTransformer; import org.assertj.core.api.SoftAssertions; import org.eclipse.jetty.http.HttpStatus; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.jayway.restassured.RestAssured; import com.jayway.restassured.http.ContentType; import com.jayway.restassured.path.json.JsonPath; -public class GlobalQuotaRoutesTest { +class GlobalQuotaRoutesTest { private WebAdminServer webAdminServer; private InMemoryPerUserMaxQuotaManager maxQuotaManager; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { maxQuotaManager = new InMemoryPerUserMaxQuotaManager(); webAdminServer = WebAdminUtils.createWebAdminServer( new DefaultMetricFactory(), @@ -64,13 +63,13 @@ public class GlobalQuotaRoutesTest { .build(); } - @After - public void stop() { + @AfterEach + void stop() { webAdminServer.destroy(); } @Test - public void getQuotaCountShouldReturnNoContentWhenUndefined() { + void getQuotaCountShouldReturnNoContentWhenUndefined() { when() .get("/quota/count") .then() @@ -78,7 +77,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void getCountShouldReturnStoredValue() throws Exception { + void getCountShouldReturnStoredValue() { int value = 42; maxQuotaManager.setGlobalMaxMessage(QuotaCount.count(value)); @@ -95,7 +94,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putCountShouldRejectInvalid() { + void putCountShouldRejectInvalid() { Map<String, Object> errors = given() .body("invalid") .when() @@ -117,7 +116,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putCountShouldRejectNegative() { + void putCountShouldRejectNegative() { Map<String, Object> errors = given() .body("-2") .when() @@ -139,7 +138,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putCountShouldHandleMinusOneAsInfinite() throws MailboxException { + void putCountShouldHandleMinusOneAsInfinite() { given() .body("-1") .when() @@ -152,7 +151,7 @@ public class GlobalQuotaRoutesTest { @Test - public void putCountShouldAcceptValidValue() throws Exception { + void putCountShouldAcceptValidValue() { given() .body("42") .when() @@ -176,7 +175,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void getQuotaSizeShouldReturnNothingByDefault() { + void getQuotaSizeShouldReturnNothingByDefault() { when() .get("/quota/size") .then() @@ -184,7 +183,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void getSizeShouldReturnStoredValue() throws Exception { + void getSizeShouldReturnStoredValue() { long value = 42; maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(value)); @@ -202,7 +201,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putSizeShouldRejectInvalid() { + void putSizeShouldRejectInvalid() { Map<String, Object> errors = given() .body("invalid") .when() @@ -225,7 +224,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putSizeShouldHandleMinusOneAsInfinite() throws MailboxException { + void putSizeShouldHandleMinusOneAsInfinite() { given() .body("-1") .when() @@ -237,7 +236,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putSizeShouldRejectNegative() { + void putSizeShouldRejectNegative() { Map<String, Object> errors = given() .body("-2") .when() @@ -259,7 +258,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putSizeShouldAcceptValidValue() throws Exception { + void putSizeShouldAcceptValidValue() { given() .body("42") .when() @@ -283,7 +282,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void getQuotaShouldReturnBothWhenValueSpecified() throws Exception { + void getQuotaShouldReturnBothWhenValueSpecified() { int maxStorage = 42; int maxMessage = 52; maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(maxStorage)); @@ -305,7 +304,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void getQuotaShouldReturnNothingWhenNothingSet() { + void getQuotaShouldReturnNothingWhenNothingSet() { JsonPath jsonPath = when() .get("/quota") @@ -341,7 +340,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void getQuotaShouldReturnOnlyCountWhenNoSize() throws Exception { + void getQuotaShouldReturnOnlyCountWhenNoSize() { int maxMessage = 42; maxQuotaManager.setGlobalMaxMessage(QuotaCount.count(maxMessage)); @@ -362,7 +361,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putQuotaShouldUpdateBothQuota() throws Exception { + void putQuotaShouldUpdateBothQuota() { given() .body("{\"count\":52,\"size\":42}") .when() @@ -376,7 +375,7 @@ public class GlobalQuotaRoutesTest { } @Test - public void putQuotaShouldSetBothQuotaToInfinite() throws Exception { + void putQuotaShouldSetBothQuotaToInfinite() { given() .body("{\"count\":-1,\"size\":-1}") .when() http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java index 08f63e7..68c1cbf 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java @@ -54,23 +54,20 @@ import org.apache.james.webadmin.WebAdminUtils; import org.apache.james.webadmin.service.UserMailboxesService; import org.apache.james.webadmin.utils.JsonTransformer; import org.eclipse.jetty.http.HttpStatus; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.jayway.restassured.RestAssured; import com.jayway.restassured.http.ContentType; -import de.bechte.junit.runners.context.HierarchicalContextRunner; +class UserMailboxesRoutesTest { -@RunWith(HierarchicalContextRunner.class) -public class UserMailboxesRoutesTest { - - public static final String USERNAME = "username"; - public static final String MAILBOX_NAME = "myMailboxName"; + private static final String USERNAME = "username"; + private static final String MAILBOX_NAME = "myMailboxName"; private WebAdminServer webAdminServer; private UsersRepository usersRepository; @@ -89,22 +86,23 @@ public class UserMailboxesRoutesTest { .build(); } - @After - public void tearDown() { + @AfterEach + void tearDown() { webAdminServer.destroy(); } - public class NormalBehaviour { + @Nested + class NormalBehaviour { - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { InMemoryIntegrationResources inMemoryIntegrationResources = new InMemoryIntegrationResources(); createServer(inMemoryIntegrationResources.createMailboxManager(new SimpleGroupMembershipResolver())); } @Test - public void getMailboxesShouldUserErrorFoundWithNonExistingUser() throws Exception { + void getMailboxesShouldUserErrorFoundWithNonExistingUser() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -124,7 +122,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldReturnNotFoundWithNonExistingUser() throws Exception { + void getShouldReturnNotFoundWithNonExistingUser() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -144,7 +142,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnNotFoundWithNonExistingUser() throws Exception { + void putShouldReturnNotFoundWithNonExistingUser() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -164,7 +162,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnNotFoundWithNonExistingUser() throws Exception { + void deleteShouldReturnNotFoundWithNonExistingUser() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -184,7 +182,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception { + void getShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -204,7 +202,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception { + void putShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -224,7 +222,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception { + void deleteShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -244,7 +242,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception { + void getShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -264,7 +262,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception { + void putShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -284,7 +282,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception { + void deleteShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -304,7 +302,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception { + void getShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -324,7 +322,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception { + void putShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -344,7 +342,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception { + void deleteShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -364,7 +362,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception { + void getShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -384,7 +382,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception { + void putShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -404,7 +402,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception { + void deleteShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -424,7 +422,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteMailboxesShouldReturnUserErrorWithNonExistingUser() throws Exception { + void deleteMailboxesShouldReturnUserErrorWithNonExistingUser() throws Exception { when(usersRepository.contains(USERNAME)).thenReturn(false); Map<String, Object> errors = when() @@ -444,7 +442,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getMailboxesShouldReturnEmptyListByDefault() { + void getMailboxesShouldReturnEmptyListByDefault() { List<Object> list = when() .get() @@ -460,7 +458,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnNotFoundWhenNoMailboxName() { + void putShouldReturnNotFoundWhenNoMailboxName() { when() .put() .then() @@ -469,7 +467,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnNotFoundWhenJustSeparator() { + void putShouldReturnNotFoundWhenJustSeparator() { when() .put(SEPARATOR) .then() @@ -478,7 +476,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnOk() { + void putShouldReturnOk() { when() .put(MAILBOX_NAME) .then() @@ -486,7 +484,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnOkWhenIssuedTwoTimes() { + void putShouldReturnOkWhenIssuedTwoTimes() { with() .put(MAILBOX_NAME); @@ -497,7 +495,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldAddAMailbox() { + void putShouldAddAMailbox() { with() .put(MAILBOX_NAME); @@ -509,7 +507,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldReturnNotFoundWhenMailboxDoesNotExist() { + void getShouldReturnNotFoundWhenMailboxDoesNotExist() { Map<String, Object> errors = when() .get(MAILBOX_NAME) .then() @@ -527,7 +525,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldReturnOkWhenMailboxExists() { + void getShouldReturnOkWhenMailboxExists() { with() .put(MAILBOX_NAME); @@ -538,7 +536,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnOkWhenMailboxDoesNotExist() { + void deleteShouldReturnOkWhenMailboxDoesNotExist() { when() .delete(MAILBOX_NAME) .then() @@ -546,7 +544,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnOkWhenMailboxExists() { + void deleteShouldReturnOkWhenMailboxExists() { with() .put(MAILBOX_NAME); @@ -557,7 +555,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldRemoveMailbox() { + void deleteShouldRemoveMailbox() { with() .put(MAILBOX_NAME); @@ -581,7 +579,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteMailboxesShouldReturnOkWhenNoMailboxes() { + void deleteMailboxesShouldReturnOkWhenNoMailboxes() { when() .delete() .then() @@ -589,7 +587,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteMailboxesShouldReturnOkWhenMailboxes() { + void deleteMailboxesShouldReturnOkWhenMailboxes() { with() .put(MAILBOX_NAME); @@ -600,7 +598,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteMailboxesShouldRemoveAllUserMailboxes() { + void deleteMailboxesShouldRemoveAllUserMailboxes() { with() .put(MAILBOX_NAME); @@ -625,7 +623,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnOkWhenMailboxHasChildren() { + void deleteShouldReturnOkWhenMailboxHasChildren() { with() .put(MAILBOX_NAME); @@ -639,7 +637,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldDeleteAMailboxAndItsChildren() { + void deleteShouldDeleteAMailboxAndItsChildren() { with() .put(MAILBOX_NAME); @@ -664,7 +662,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldNotDeleteUnrelatedMailbox() { + void deleteShouldNotDeleteUnrelatedMailbox() { String mailboxName = MAILBOX_NAME + "!child"; with() .put(MAILBOX_NAME); @@ -690,7 +688,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnOkWhenDeletingChildMailboxes() { + void deleteShouldReturnOkWhenDeletingChildMailboxes() { with() .put(MAILBOX_NAME); @@ -704,7 +702,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldBeAbleToRemoveChildMailboxes() { + void deleteShouldBeAbleToRemoveChildMailboxes() { with() .put(MAILBOX_NAME); @@ -729,12 +727,13 @@ public class UserMailboxesRoutesTest { } } - public class ExceptionHandling { + @Nested + class ExceptionHandling { private MailboxManager mailboxManager; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { mailboxManager = mock(MailboxManager.class); when(mailboxManager.createSystemSession(any())).thenReturn(new MockMailboxSession(USERNAME)); @@ -742,7 +741,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldGenerateInternalErrorOnUnknownException() throws Exception { + void putShouldGenerateInternalErrorOnUnknownException() throws Exception { doThrow(new RuntimeException()).when(mailboxManager).createMailbox(any(), any()); when() @@ -753,7 +752,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception { + void putShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception { doThrow(new MailboxException()).when(mailboxManager).createMailbox(any(), any()); when() @@ -764,7 +763,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldReturnOkOnMailboxExists() throws Exception { + void putShouldReturnOkOnMailboxExists() throws Exception { doThrow(new MailboxExistsException(MAILBOX_NAME)).when(mailboxManager).createMailbox(any(), any()); when() @@ -774,7 +773,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldGenerateInternalErrorOnUnknownExceptionOnDelete() throws Exception { + void deleteShouldGenerateInternalErrorOnUnknownExceptionOnDelete() throws Exception { MailboxId mailboxId = InMemoryId.of(12); when(mailboxManager.search(any(MailboxQuery.class), any())) .thenReturn( @@ -791,7 +790,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldGenerateInternalErrorOnUnknownExceptionOnSearch() throws Exception { + void deleteShouldGenerateInternalErrorOnUnknownExceptionOnSearch() throws Exception { when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new RuntimeException()); when() @@ -802,7 +801,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnDelete() throws Exception { + void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnDelete() throws Exception { MailboxId mailboxId = InMemoryId.of(12); when(mailboxManager.search(any(MailboxQuery.class), any())) .thenReturn( @@ -818,7 +817,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnSearch() throws Exception { + void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnSearch() throws Exception { when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new MailboxException()); when() @@ -829,7 +828,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnOkOnMailboxDoesNotExists() throws Exception { + void deleteShouldReturnOkOnMailboxDoesNotExists() throws Exception { doThrow(new MailboxNotFoundException(MAILBOX_NAME)).when(mailboxManager).deleteMailbox(any(), any()); when() @@ -839,7 +838,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenListingMailboxes() throws Exception { + void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenListingMailboxes() throws Exception { doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class), any()); when() @@ -850,7 +849,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldGenerateInternalErrorOnMailboxExceptionWhenListingMailboxes() throws Exception { + void deleteShouldGenerateInternalErrorOnMailboxExceptionWhenListingMailboxes() throws Exception { doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class), any()); when() @@ -862,7 +861,7 @@ public class UserMailboxesRoutesTest { @Test - public void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenRemovingMailboxes() throws Exception { + void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenRemovingMailboxes() throws Exception { MailboxId mailboxId = InMemoryId.of(12); when(mailboxManager.search(any(MailboxQuery.class), any())) .thenReturn( @@ -878,7 +877,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnOkOnMailboxNotFoundExceptionWhenRemovingMailboxes() throws Exception { + void deleteShouldReturnOkOnMailboxNotFoundExceptionWhenRemovingMailboxes() throws Exception { MailboxId mailboxId = InMemoryId.of(12); when(mailboxManager.search(any(MailboxQuery.class), any())) .thenReturn( @@ -892,7 +891,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldReturnInternalErrorOnMailboxExceptionWhenRemovingMailboxes() throws Exception { + void deleteShouldReturnInternalErrorOnMailboxExceptionWhenRemovingMailboxes() throws Exception { MailboxId mailboxId = InMemoryId.of(12); when(mailboxManager.search(any(MailboxQuery.class), any())) .thenReturn( @@ -907,7 +906,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldGenerateInternalErrorOnUnknownException() throws Exception { + void getShouldGenerateInternalErrorOnUnknownException() throws Exception { doThrow(new RuntimeException()).when(mailboxManager).mailboxExists(any(), any()); when() @@ -918,7 +917,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception { + void getShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception { doThrow(new MailboxException()).when(mailboxManager).mailboxExists(any(), any()); when() @@ -929,7 +928,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getMailboxesShouldGenerateInternalErrorOnUnknownException() throws Exception { + void getMailboxesShouldGenerateInternalErrorOnUnknownException() throws Exception { doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class), any()); when() @@ -940,7 +939,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getMailboxesShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception { + void getMailboxesShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception { doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class), any()); when() @@ -951,7 +950,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getMailboxesShouldGenerateInternalErrorOnRepositoryException() throws Exception { + void getMailboxesShouldGenerateInternalErrorOnRepositoryException() throws Exception { doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME); when() @@ -962,7 +961,7 @@ public class UserMailboxesRoutesTest { } @Test - public void getShouldGenerateInternalErrorOnRepositoryException() throws Exception { + void getShouldGenerateInternalErrorOnRepositoryException() throws Exception { doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME); when() @@ -973,7 +972,7 @@ public class UserMailboxesRoutesTest { } @Test - public void putShouldGenerateInternalErrorOnRepositoryException() throws Exception { + void putShouldGenerateInternalErrorOnRepositoryException() throws Exception { doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME); when() @@ -984,7 +983,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteShouldGenerateInternalErrorOnRepositoryException() throws Exception { + void deleteShouldGenerateInternalErrorOnRepositoryException() throws Exception { doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME); when() @@ -995,7 +994,7 @@ public class UserMailboxesRoutesTest { } @Test - public void deleteMailboxesShouldGenerateInternalErrorOnRepositoryException() throws Exception { + void deleteMailboxesShouldGenerateInternalErrorOnRepositoryException() throws Exception { doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME); when() http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java index 8c11748..2d877e3 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java @@ -44,17 +44,17 @@ import org.apache.james.webadmin.service.UserQuotaService; import org.apache.james.webadmin.utils.JsonTransformer; import org.assertj.core.api.SoftAssertions; import org.eclipse.jetty.http.HttpStatus; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableSet; import com.jayway.restassured.RestAssured; import com.jayway.restassured.http.ContentType; import com.jayway.restassured.path.json.JsonPath; -public class UserQuotaRoutesTest { +class UserQuotaRoutesTest { private static final String QUOTA_USERS = "/quota/users"; private static final String PERDU_COM = "perdu.com"; @@ -68,8 +68,8 @@ public class UserQuotaRoutesTest { private InMemoryPerUserMaxQuotaManager maxQuotaManager; private DefaultUserQuotaRootResolver userQuotaRootResolver; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { maxQuotaManager = new InMemoryPerUserMaxQuotaManager(); MemoryDomainList memoryDomainList = new MemoryDomainList(new InMemoryDNSService()); memoryDomainList.setAutoDetect(false); @@ -93,13 +93,13 @@ public class UserQuotaRoutesTest { RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); } - @After - public void stop() { + @AfterEach + void stop() { webAdminServer.destroy(); } @Test - public void getCountShouldReturnNotFoundWhenUserDoesntExist() { + void getCountShouldReturnNotFoundWhenUserDoesntExist() { when() .get(QUOTA_USERS + "/" + JOE.asString() + "/" + COUNT) .then() @@ -107,7 +107,7 @@ public class UserQuotaRoutesTest { } @Test - public void getCountShouldReturnNoContentByDefault() { + void getCountShouldReturnNoContentByDefault() { given() .get(QUOTA_USERS + "/" + BOB.asString() + "/" + COUNT) .then() @@ -115,7 +115,7 @@ public class UserQuotaRoutesTest { } @Test - public void getCountShouldReturnStoredValue() { + void getCountShouldReturnStoredValue() { int value = 42; maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCount.count(value)); @@ -132,7 +132,7 @@ public class UserQuotaRoutesTest { } @Test - public void putCountShouldReturnNotFoundWhenUserDoesntExist() { + void putCountShouldReturnNotFoundWhenUserDoesntExist() { given() .body("invalid") .when() @@ -142,7 +142,7 @@ public class UserQuotaRoutesTest { } @Test - public void putCountShouldAcceptEscapedUsers() { + void putCountShouldAcceptEscapedUsers() { given() .body("35") .when() @@ -152,7 +152,7 @@ public class UserQuotaRoutesTest { } @Test - public void putCountSizeAcceptEscapedUsers() { + void putCountSizeAcceptEscapedUsers() { given() .body("36") .when() @@ -162,7 +162,7 @@ public class UserQuotaRoutesTest { } @Test - public void putCountShouldRejectInvalid() { + void putCountShouldRejectInvalid() { Map<String, Object> errors = given() .body("invalid") .put(QUOTA_USERS + "/" + BOB.asString() + "/" + COUNT) @@ -182,7 +182,7 @@ public class UserQuotaRoutesTest { } @Test - public void putCountShouldSetToInfiniteWhenMinusOne() throws Exception { + void putCountShouldSetToInfiniteWhenMinusOne() throws Exception { given() .body("-1") .when() @@ -194,7 +194,7 @@ public class UserQuotaRoutesTest { } @Test - public void putCountShouldRejectNegativeOtherThanMinusOne() { + void putCountShouldRejectNegativeOtherThanMinusOne() { Map<String, Object> errors = given() .body("-2") .put(QUOTA_USERS + "/" + BOB.asString() + "/" + COUNT) @@ -213,7 +213,7 @@ public class UserQuotaRoutesTest { } @Test - public void putCountShouldAcceptValidValue() throws Exception { + void putCountShouldAcceptValidValue() throws Exception { given() .body("42") .put(QUOTA_USERS + "/" + BOB.asString() + "/" + COUNT) @@ -224,8 +224,8 @@ public class UserQuotaRoutesTest { } @Test - @Ignore("no link between quota and mailbox for now") - public void putCountShouldRejectTooSmallValue() throws Exception { + @Disabled("no link between quota and mailbox for now") + void putCountShouldRejectTooSmallValue() throws Exception { given() .body("42") .put(QUOTA_USERS + "/" + BOB.asString() + "/" + COUNT) @@ -236,7 +236,7 @@ public class UserQuotaRoutesTest { } @Test - public void deleteCountShouldReturnNotFoundWhenUserDoesntExist() { + void deleteCountShouldReturnNotFoundWhenUserDoesntExist() { when() .delete(QUOTA_USERS + "/" + JOE.asString() + "/" + COUNT) .then() @@ -245,7 +245,7 @@ public class UserQuotaRoutesTest { @Test - public void deleteCountShouldSetQuotaToEmpty() throws Exception { + void deleteCountShouldSetQuotaToEmpty() throws Exception { maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCount.count(42)); given() @@ -257,7 +257,7 @@ public class UserQuotaRoutesTest { } @Test - public void getSizeShouldReturnNotFoundWhenUserDoesntExist() { + void getSizeShouldReturnNotFoundWhenUserDoesntExist() { when() .get(QUOTA_USERS + "/" + JOE.asString() + "/" + SIZE) .then() @@ -265,7 +265,7 @@ public class UserQuotaRoutesTest { } @Test - public void getSizeShouldReturnNoContentByDefault() { + void getSizeShouldReturnNoContentByDefault() { when() .get(QUOTA_USERS + "/" + BOB.asString() + "/" + SIZE) .then() @@ -273,7 +273,7 @@ public class UserQuotaRoutesTest { } @Test - public void getSizeShouldReturnStoredValue() { + void getSizeShouldReturnStoredValue() { long value = 42; maxQuotaManager.setMaxStorage(userQuotaRootResolver.forUser(BOB), QuotaSize.size(value)); @@ -291,7 +291,7 @@ public class UserQuotaRoutesTest { } @Test - public void putSizeShouldRejectInvalid() { + void putSizeShouldRejectInvalid() { Map<String, Object> errors = given() .body("invalid") .put(QUOTA_USERS + "/" + BOB.asString() + "/" + SIZE) @@ -311,7 +311,7 @@ public class UserQuotaRoutesTest { } @Test - public void putSizeShouldReturnNotFoundWhenUserDoesntExist() { + void putSizeShouldReturnNotFoundWhenUserDoesntExist() { given() .body("123") .when() @@ -321,7 +321,7 @@ public class UserQuotaRoutesTest { } @Test - public void putSizeShouldSetToInfiniteWhenMinusOne() throws Exception { + void putSizeShouldSetToInfiniteWhenMinusOne() throws Exception { given() .body("-1") .when() @@ -334,7 +334,7 @@ public class UserQuotaRoutesTest { } @Test - public void putSizeShouldRejectNegativeOtherThanMinusOne() { + void putSizeShouldRejectNegativeOtherThanMinusOne() { Map<String, Object> errors = given() .body("-2") .put(QUOTA_USERS + "/" + BOB.asString() + "/" + SIZE) @@ -353,7 +353,7 @@ public class UserQuotaRoutesTest { } @Test - public void putSizeShouldAcceptValidValue() throws Exception { + void putSizeShouldAcceptValidValue() throws Exception { given() .body("42") .when() @@ -365,7 +365,7 @@ public class UserQuotaRoutesTest { } @Test - public void deleteSizeShouldReturnNotFoundWhenUserDoesntExist() { + void deleteSizeShouldReturnNotFoundWhenUserDoesntExist() { when() .delete(QUOTA_USERS + "/" + JOE.asString() + "/" + SIZE) .then() @@ -373,7 +373,7 @@ public class UserQuotaRoutesTest { } @Test - public void deleteSizeShouldSetQuotaToEmpty() throws Exception { + void deleteSizeShouldSetQuotaToEmpty() throws Exception { maxQuotaManager.setMaxStorage(userQuotaRootResolver.forUser(BOB), QuotaSize.size(42)); given() @@ -385,7 +385,7 @@ public class UserQuotaRoutesTest { } @Test - public void getQuotaShouldReturnNotFoundWhenUserDoesntExist() { + void getQuotaShouldReturnNotFoundWhenUserDoesntExist() { when() .get(QUOTA_USERS + "/" + JOE.asString()) .then() @@ -471,7 +471,7 @@ public class UserQuotaRoutesTest { } @Test - public void getQuotaShouldReturnBothWhenValueSpecifiedAndEscaped() { + void getQuotaShouldReturnBothWhenValueSpecifiedAndEscaped() { int maxStorage = 42; int maxMessage = 52; maxQuotaManager.setMaxStorage(userQuotaRootResolver.forUser(BOB), QuotaSize.size(maxStorage)); @@ -491,7 +491,7 @@ public class UserQuotaRoutesTest { } @Test - public void getQuotaShouldReturnBothEmptyWhenDefaultValues() { + void getQuotaShouldReturnBothEmptyWhenDefaultValues() { JsonPath jsonPath = given() .get(QUOTA_USERS + "/" + BOB.asString()) @@ -506,7 +506,7 @@ public class UserQuotaRoutesTest { } @Test - public void getQuotaShouldReturnSizeWhenNoCount() { + void getQuotaShouldReturnSizeWhenNoCount() { int maxStorage = 42; maxQuotaManager.setMaxStorage(userQuotaRootResolver.forUser(BOB), QuotaSize.size(maxStorage)); @@ -524,7 +524,7 @@ public class UserQuotaRoutesTest { } @Test - public void getQuotaShouldReturnBothWhenNoSize() { + void getQuotaShouldReturnBothWhenNoSize() { int maxMessage = 42; maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCount.count(maxMessage)); @@ -543,7 +543,7 @@ public class UserQuotaRoutesTest { } @Test - public void putQuotaShouldReturnNotFoundWhenUserDoesntExist() { + void putQuotaShouldReturnNotFoundWhenUserDoesntExist() { when() .put(QUOTA_USERS + "/" + JOE.asString()) .then() @@ -551,7 +551,7 @@ public class UserQuotaRoutesTest { } @Test - public void putQuotaShouldUpdateBothQuota() throws Exception { + void putQuotaShouldUpdateBothQuota() throws Exception { given() .body("{\"count\":52,\"size\":42}") .put(QUOTA_USERS + "/" + BOB.asString()) @@ -565,7 +565,7 @@ public class UserQuotaRoutesTest { } @Test - public void putQuotaShouldUpdateBothQuotaWhenEscaped() throws Exception { + void putQuotaShouldUpdateBothQuotaWhenEscaped() throws Exception { given() .body("{\"count\":52,\"size\":42}") .put(QUOTA_USERS + "/" + ESCAPED_BOB.asString()) @@ -579,7 +579,7 @@ public class UserQuotaRoutesTest { } @Test - public void putQuotaShouldBeAbleToRemoveBothQuota() throws Exception { + void putQuotaShouldBeAbleToRemoveBothQuota() throws Exception { given() .body("{\"count\":null,\"count\":null}") .put(QUOTA_USERS + "/" + BOB.asString()) http://git-wip-us.apache.org/repos/asf/james-project/blob/cb3a6e60/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/validation/QuotaValueTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/validation/QuotaValueTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/validation/QuotaValueTest.java index b57a754..d38d78a 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/validation/QuotaValueTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/validation/QuotaValueTest.java @@ -24,67 +24,67 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; -import org.junit.Test; +import org.junit.jupiter.api.Test; import spark.HaltException; -public class QuotaValueTest { +class QuotaValueTest { @Test - public void quotaCountShouldThrowWhenNotANumber() { + void quotaCountShouldThrowWhenNotANumber() { assertThatThrownBy(() -> Quotas.quotaCount("invalid")) .isInstanceOf(HaltException.class); } @Test - public void quotaCountShouldParseZero() { + void quotaCountShouldParseZero() { assertThat(Quotas.quotaCount("0").asLong()) .isEqualTo(0); } @Test - public void quotaCountShouldParsePositiveValue() { + void quotaCountShouldParsePositiveValue() { assertThat(Quotas.quotaCount("42").asLong()) .isEqualTo(42); } @Test - public void quotaCountShouldBeUnlimitedOnMinusOne() { + void quotaCountShouldBeUnlimitedOnMinusOne() { assertThat(Quotas.quotaCount("-1")).isEqualTo(QuotaCount.unlimited()); } @Test - public void quotaCountShouldThrowOnNegativeNumber() { + void quotaCountShouldThrowOnNegativeNumber() { assertThatThrownBy(() -> Quotas.quotaCount("-2")) .isInstanceOf(HaltException.class); } @Test - public void quotaSizeShouldThrowWhenNotANumber() { + void quotaSizeShouldThrowWhenNotANumber() { assertThatThrownBy(() -> Quotas.quotaSize("invalid")) .isInstanceOf(HaltException.class); } @Test - public void quotaSizeShouldParseZero() { + void quotaSizeShouldParseZero() { assertThat(Quotas.quotaSize("0").asLong()) .isEqualTo(0); } @Test - public void quotaSizeShouldParsePositiveValue() { + void quotaSizeShouldParsePositiveValue() { assertThat(Quotas.quotaSize("42").asLong()) .isEqualTo(42); } @Test - public void quotaSizeShouldBeUnlimitedOnMinusOne() { + void quotaSizeShouldBeUnlimitedOnMinusOne() { assertThat(Quotas.quotaSize("-1")).isEqualTo(QuotaSize.unlimited()); } @Test - public void quotaSizeShouldThrowOnNegativeNumber() { + void quotaSizeShouldThrowOnNegativeNumber() { assertThatThrownBy(() -> Quotas.quotaSize("-2")) .isInstanceOf(HaltException.class); } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org