You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rc...@apache.org on 2020/08/10 02:47:46 UTC
[james-project] 16/23: [Refactoring] Migrate ReportingUserAgentTest
to JUnit5
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 58b51a52f7f76f3a87ce787d5957d62ee7b410c9
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 31 14:50:04 2020 +0700
[Refactoring] Migrate ReportingUserAgentTest to JUnit5
---
.../james/mdn/fields/ReportingUserAgentTest.java | 154 +++++++++++++--------
1 file changed, 97 insertions(+), 57 deletions(-)
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
index e425f63..4134ccc 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
@@ -20,130 +20,170 @@
package org.apache.james.mdn.fields;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-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 ReportingUserAgentTest {
- public static final String USER_AGENT_NAME = "name";
- public static final String USER_AGENT_PRODUCT = "product";
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
+class ReportingUserAgentTest {
+ static final String USER_AGENT_NAME = "name";
+ static final String USER_AGENT_PRODUCT = "product";
@Test
- public void shouldMatchBeanContact() {
+ void shouldMatchBeanContact() {
EqualsVerifier.forClass(ReportingUserAgent.class)
.verify();
}
@Test
- public void productShouldBeOptional() {
- assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).build())
- .isEqualTo(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).build());
+ void productShouldBeOptional() {
+ assertThat(ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .build())
+ .isEqualTo(ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .build());
}
@Test
- public void shouldThrowOnNullName() {
- expectedException.expect(NullPointerException.class);
-
+ void shouldThrowOnNullName() {
String userAgentName = null;
- ReportingUserAgent.builder().userAgentName(userAgentName).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(userAgentName)
+ .build())
+ .isInstanceOf(NullPointerException.class);
}
@Test
- public void shouldThrowOnNullNameWhenSpecifyingProduct() {
- expectedException.expect(NullPointerException.class);
-
+ void shouldThrowOnNullNameWhenSpecifyingProduct() {
String userAgentName = null;
- ReportingUserAgent.builder().userAgentName(userAgentName).userAgentProduct(USER_AGENT_PRODUCT).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(userAgentName)
+ .userAgentProduct(USER_AGENT_PRODUCT)
+ .build())
+ .isInstanceOf(NullPointerException.class);
}
@Test
- public void shouldThrowOnNullProduct() {
- expectedException.expect(NullPointerException.class);
-
+ void shouldThrowOnNullProduct() {
String userAgentProduct = null;
- ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct(userAgentProduct).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .userAgentProduct(userAgentProduct)
+ .build())
+ .isInstanceOf(NullPointerException.class);
}
@Test
- public void shouldThrowOnEmptyName() {
- expectedException.expect(IllegalStateException.class);
-
+ void shouldThrowOnEmptyName() {
String userAgentName = "";
- ReportingUserAgent.builder().userAgentName(userAgentName).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(userAgentName)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void shouldThrowOnFoldingWhiteSpaceName() {
- expectedException.expect(IllegalStateException.class);
-
+ void shouldThrowOnFoldingWhiteSpaceName() {
String userAgentName = " ";
- ReportingUserAgent.builder().userAgentName(userAgentName).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(userAgentName)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void shouldThrowOnNameWithLineBreak() {
- expectedException.expect(IllegalStateException.class);
-
+ void shouldThrowOnNameWithLineBreak() {
String userAgentName = "a\nb";
- ReportingUserAgent.builder().userAgentName(userAgentName).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(userAgentName)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void shouldThrowOnNameWithLineBreakAtTheEnd() {
- expectedException.expect(IllegalStateException.class);
-
+ void shouldThrowOnNameWithLineBreakAtTheEnd() {
String userAgentName = "a\n";
- ReportingUserAgent.builder().userAgentName(userAgentName).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(userAgentName)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void shouldThrowOnNameWithLineBreakAtTheBeginning() {
- expectedException.expect(IllegalStateException.class);
-
+ void shouldThrowOnNameWithLineBreakAtTheBeginning() {
String userAgentName = "\nb";
- ReportingUserAgent.builder().userAgentName(userAgentName).build();
+
+ assertThatThrownBy(() -> ReportingUserAgent.builder()
+ .userAgentName(userAgentName)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void nameShouldBeTrimmed() {
- assertThat(ReportingUserAgent.builder().userAgentName(" name ").build().getUserAgentName())
+ void nameShouldBeTrimmed() {
+ assertThat(ReportingUserAgent.builder()
+ .userAgentName(" name ")
+ .build()
+ .getUserAgentName())
.isEqualTo(USER_AGENT_NAME);
}
@Test
- public void productShouldBeTrimmed() {
- assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct(" product ").build().getUserAgentProduct())
+ void productShouldBeTrimmed() {
+ assertThat(ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .userAgentProduct(" product ")
+ .build()
+ .getUserAgentProduct())
.contains(USER_AGENT_PRODUCT);
}
@Test
- public void formattedValueShouldDisplayNameWhenProductMissing() {
- assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).build().formattedValue())
+ void formattedValueShouldDisplayNameWhenProductMissing() {
+ assertThat(ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .build()
+ .formattedValue())
.isEqualTo("Reporting-UA: name; ");
}
@Test
- public void emptyProductShouldBeFilteredOut() {
- assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct("").build().getUserAgentProduct())
+ void emptyProductShouldBeFilteredOut() {
+ assertThat(ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .userAgentProduct("")
+ .build()
+ .getUserAgentProduct())
.isEmpty();
}
@Test
- public void foldingWhiteSpaceProductShouldBeFilteredOut() {
- assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct(" ").build().getUserAgentProduct())
+ void foldingWhiteSpaceProductShouldBeFilteredOut() {
+ assertThat(ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .userAgentProduct(" ")
+ .build()
+ .getUserAgentProduct())
.isEmpty();
}
@Test
- public void formattedValueShouldDisplayProduct() {
- assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct(USER_AGENT_PRODUCT).build().formattedValue())
+ void formattedValueShouldDisplayProduct() {
+ assertThat(ReportingUserAgent.builder()
+ .userAgentName(USER_AGENT_NAME)
+ .userAgentProduct(USER_AGENT_PRODUCT)
+ .build()
+ .formattedValue())
.isEqualTo("Reporting-UA: name; product");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org