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/07/28 03:20:37 UTC
[james-project] 09/25: [Refactoring] Migrate ICALAttributeDTOTest
to Junit 5
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 f2351ec0e817f14a9f70a33a55f5faa73420771e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 17:11:32 2020 +0700
[Refactoring] Migrate ICALAttributeDTOTest to Junit 5
---
.../mailets/model/ICALAttributeDTOTest.java | 95 +++++++++++-----------
1 file changed, 48 insertions(+), 47 deletions(-)
diff --git a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java
index 5c69a99..3f577d9 100644
--- a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java
+++ b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java
@@ -20,6 +20,7 @@
package org.apache.james.transport.mailets.model;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.ByteArrayInputStream;
@@ -27,27 +28,25 @@ import org.apache.james.core.MailAddress;
import org.apache.james.transport.mailets.ICal4JConfigurator;
import org.apache.james.util.ClassLoaderUtils;
import org.apache.mailet.base.MailAddressFixture;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import com.github.fge.lambdas.Throwing;
import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.model.Calendar;
import nl.jqno.equalsverifier.EqualsVerifier;
-public class ICALAttributeDTOTest {
+class ICALAttributeDTOTest {
- @BeforeClass
- public static void setUpIcal4J() {
+ @BeforeAll
+ static void setUpIcal4J() {
ICal4JConfigurator.configure();
}
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
- public void buildShouldWork() throws Exception {
+ void buildShouldWork() throws Exception {
byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics");
Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
@@ -59,73 +58,75 @@ public class ICALAttributeDTOTest {
.recipient(recipient)
.replyTo(sender);
- assertThat(ical.getRecipient()).isEqualTo(recipient.asString());
- assertThat(ical.getSender()).isEqualTo(sender.asString());
- assertThat(ical.getUid())
- .contains("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7" +
- "c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
- assertThat(ical.getMethod()).contains("REQUEST");
- assertThat(ical.getRecurrenceId()).isEmpty();
- assertThat(ical.getDtstamp()).contains("20170106T115036Z");
- assertThat(ical.getSequence()).isEqualTo("0");
- assertThat(ical.getIcal()).isEqualTo(new String(ics, "UTF-8"));
+ SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+ softly.assertThat(ical.getRecipient()).isEqualTo(recipient.asString());
+ softly.assertThat(ical.getSender()).isEqualTo(sender.asString());
+ softly.assertThat(ical.getUid())
+ .contains("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7" +
+ "c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
+ softly.assertThat(ical.getMethod()).contains("REQUEST");
+ softly.assertThat(ical.getRecurrenceId()).isEmpty();
+ softly.assertThat(ical.getDtstamp()).contains("20170106T115036Z");
+ softly.assertThat(ical.getSequence()).isEqualTo("0");
+ softly.assertThat(ical.getIcal()).isEqualTo(new String(ics, "UTF-8"));
+ }));
}
@Test
- public void equalsAndHashCodeShouldBeWellImplemented() {
+ void equalsAndHashCodeShouldBeWellImplemented() {
EqualsVerifier.forClass(ICALAttributeDTO.class).verify();
}
@Test
- public void buildShouldThrowOnCalendarWithoutDtstamp() throws Exception {
+ void buildShouldThrowOnCalendarWithoutDtstamp() throws Exception {
byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_dtstamp.ics");
Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
- expectedException.expect(IllegalStateException.class);
-
MailAddress recipient = MailAddressFixture.ANY_AT_JAMES;
MailAddress sender = MailAddressFixture.OTHER_AT_JAMES;
- ICALAttributeDTO.builder()
- .from(calendar, ics)
- .sender(sender)
- .recipient(recipient)
- .replyTo(sender);
+
+ assertThatThrownBy(() -> ICALAttributeDTO.builder()
+ .from(calendar, ics)
+ .sender(sender)
+ .recipient(recipient)
+ .replyTo(sender))
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void buildShouldThrowOnCalendarWithoutUid() throws Exception {
+ void buildShouldThrowOnCalendarWithoutUid() throws Exception {
byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_uid.ics");
Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
- expectedException.expect(IllegalStateException.class);
-
MailAddress recipient = MailAddressFixture.ANY_AT_JAMES;
MailAddress sender = MailAddressFixture.OTHER_AT_JAMES;
- ICALAttributeDTO.builder()
- .from(calendar, ics)
- .sender(sender)
- .recipient(recipient)
- .replyTo(sender);
+
+ assertThatThrownBy(() -> ICALAttributeDTO.builder()
+ .from(calendar, ics)
+ .sender(sender)
+ .recipient(recipient)
+ .replyTo(sender))
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void buildShouldThrowOnCalendarWithoutMethod() throws Exception {
+ void buildShouldThrowOnCalendarWithoutMethod() throws Exception {
byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_method.ics");
Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
- expectedException.expect(IllegalStateException.class);
-
MailAddress recipient = MailAddressFixture.ANY_AT_JAMES;
MailAddress sender = MailAddressFixture.OTHER_AT_JAMES;
- ICALAttributeDTO.builder()
- .from(calendar, ics)
- .sender(sender)
- .recipient(recipient)
- .replyTo(sender);
+
+ assertThatThrownBy(() -> ICALAttributeDTO.builder()
+ .from(calendar, ics)
+ .sender(sender)
+ .recipient(recipient)
+ .replyTo(sender))
+ .isInstanceOf(IllegalStateException.class);
}
@Test
- public void buildShouldSetDefaultValueWhenCalendarWithoutSequence() throws Exception {
+ void buildShouldSetDefaultValueWhenCalendarWithoutSequence() throws Exception {
byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_sequence.ics");
Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org