james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [15/17] james-project git commit: JAMES-2436 Handle UidValidity metadata for mailboxes
Date Wed, 27 Jun 2018 14:44:37 GMT
JAMES-2436 Handle UidValidity metadata for mailboxes


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/628420f3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/628420f3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/628420f3

Branch: refs/heads/master
Commit: 628420f3218af8ad5d8cc653cd1ceb9f6bb663a1
Parents: ca09a60
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Jun 20 16:16:51 2018 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Wed Jun 27 16:41:40 2018 +0200

----------------------------------------------------------------------
 .../mailbox/backup/InternalDateExtraField.java  |  23 +-
 .../james/mailbox/backup/LongExtraField.java    |   5 +-
 .../mailbox/backup/MailboxIdExtraField.java     |  76 +-----
 .../mailbox/backup/MessageIdExtraField.java     |  76 +-----
 .../james/mailbox/backup/StringExtraField.java  |  95 +++++++
 .../mailbox/backup/UidValidityExtraField.java   |  44 ++++
 .../org/apache/james/mailbox/backup/Zipper.java |   2 +
 .../backup/InternalDateExtraFieldTest.java      | 252 ++++++++----------
 .../mailbox/backup/MailboxIdExtraFieldTest.java |  22 +-
 .../mailbox/backup/MailboxMessageFixture.java   |   6 +-
 .../mailbox/backup/MessageIdExtraFieldTest.java |  22 +-
 .../mailbox/backup/SizeExtraFieldTest.java      |  10 +
 .../james/mailbox/backup/UidExtraFieldTest.java |  10 +
 .../backup/UidValidityExtraFieldTest.java       | 264 +++++++++++++++++++
 .../apache/james/mailbox/backup/ZipperTest.java |   7 +-
 15 files changed, 614 insertions(+), 300 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/InternalDateExtraField.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/InternalDateExtraField.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/InternalDateExtraField.java
index ef7af13..f471869 100644
--- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/InternalDateExtraField.java
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/InternalDateExtraField.java
@@ -19,12 +19,15 @@
 
 package org.apache.james.mailbox.backup;
 
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.Optional;
 
 import org.apache.commons.compress.archivers.zip.ZipShort;
 
-public class InternalDateExtraField extends LongExtraField {
+public class InternalDateExtraField extends StringExtraField {
 
     public static final ZipShort ID = new ZipShort(0x6F61); // "ao" in little-endian
 
@@ -32,16 +35,15 @@ public class InternalDateExtraField extends LongExtraField {
         super();
     }
 
-    public InternalDateExtraField(long time) {
-        super(time);
+    public InternalDateExtraField(Optional<Date> date) {
+        super(date
+            .map(Date::toInstant)
+            .map(instant -> ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()))
+            .map(DateTimeFormatter.ISO_OFFSET_DATE_TIME::format));
     }
 
     public InternalDateExtraField(Date date) {
-        super(date.getTime());
-    }
-
-    public InternalDateExtraField(Optional<Date> date) {
-        super(date.map(Date::getTime));
+        this(Optional.of(date));
     }
 
     @Override
@@ -50,6 +52,9 @@ public class InternalDateExtraField extends LongExtraField {
     }
 
     public Optional<Date> getDateValue() {
-        return getValue().map(Date::new);
+        return getValue()
+            .map(time -> ZonedDateTime.parse(time, DateTimeFormatter.ISO_OFFSET_DATE_TIME))
+            .map(ZonedDateTime::toInstant)
+            .map(Date::from);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/LongExtraField.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/LongExtraField.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/LongExtraField.java
index 6cc5fc5..8c0d5cf 100644
--- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/LongExtraField.java
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/LongExtraField.java
@@ -93,13 +93,14 @@ public abstract class LongExtraField implements ZipExtraField {
         if (o instanceof LongExtraField) {
             LongExtraField that = (LongExtraField) o;
 
-            return Objects.equals(this.value, that.value);
+            return Objects.equals(this.value, that.value)
+                && Objects.equals(this.getHeaderId(), that.getHeaderId());
         }
         return false;
     }
 
     @Override
     public final int hashCode() {
-        return Objects.hash(value);
+        return Objects.hash(value, getHeaderId());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MailboxIdExtraField.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MailboxIdExtraField.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MailboxIdExtraField.java
index 5bdbd64..f6535bc 100644
--- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MailboxIdExtraField.java
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MailboxIdExtraField.java
@@ -19,87 +19,33 @@
 
 package org.apache.james.mailbox.backup;
 
-import java.nio.charset.StandardCharsets;
-import java.util.Objects;
 import java.util.Optional;
 
-import org.apache.commons.compress.archivers.zip.ZipExtraField;
 import org.apache.commons.compress.archivers.zip.ZipShort;
+import org.apache.james.mailbox.model.MailboxId;
 
-public class MailboxIdExtraField implements ZipExtraField {
+public class MailboxIdExtraField extends StringExtraField {
 
     public static final ZipShort ID = new ZipShort(0x6D61); // "am" in little-endian
 
-    private Optional<String> mailboxId;
-
     public MailboxIdExtraField() {
-        this(Optional.empty());
-    }
-
-    public MailboxIdExtraField(String mailboxId) {
-        this(Optional.of(mailboxId));
-    }
-
-    public MailboxIdExtraField(Optional<String> mailboxId) {
-        this.mailboxId = mailboxId;
-    }
-
-    @Override
-    public ZipShort getHeaderId() {
-        return ID;
-    }
-
-    @Override
-    public ZipShort getLocalFileDataLength() {
-        return mailboxId
-            .map(value -> value.getBytes(StandardCharsets.UTF_8).length)
-            .map(ZipShort::new)
-            .orElseThrow(() -> new RuntimeException("Value must by initialized"));
-    }
-
-    @Override
-    public ZipShort getCentralDirectoryLength() {
-        return getLocalFileDataLength();
+        super();
     }
 
-    @Override
-    public byte[] getLocalFileDataData() {
-        return mailboxId
-            .map(value -> value.getBytes(StandardCharsets.UTF_8))
-            .orElseThrow(() -> new RuntimeException("Value must by initialized"));
+    public MailboxIdExtraField(String value) {
+        super(Optional.of(value));
     }
 
-    @Override
-    public byte[] getCentralDirectoryData() {
-        return getLocalFileDataData();
+    public MailboxIdExtraField(Optional<String> value) {
+        super(value);
     }
 
-    @Override
-    public void parseFromLocalFileData(byte[] buffer, int offset, int length) {
-        mailboxId = Optional.of(new String(buffer, offset, length, StandardCharsets.UTF_8));
+    public MailboxIdExtraField(MailboxId mailboxId) {
+        super(Optional.of(mailboxId.serialize()));
     }
 
     @Override
-    public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) {
-        parseFromLocalFileData(buffer, offset, length);
-    }
-
-    public Optional<String> getMailboxId() {
-        return mailboxId;
-    }
-
-    @Override
-    public final boolean equals(Object o) {
-        if (o instanceof MailboxIdExtraField) {
-            MailboxIdExtraField that = (MailboxIdExtraField) o;
-
-            return Objects.equals(this.mailboxId, that.mailboxId);
-        }
-        return false;
-    }
-
-    @Override
-    public final int hashCode() {
-        return Objects.hash(mailboxId);
+    public ZipShort getHeaderId() {
+        return ID;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MessageIdExtraField.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MessageIdExtraField.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MessageIdExtraField.java
index 9f68016..919a4e2 100644
--- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MessageIdExtraField.java
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/MessageIdExtraField.java
@@ -19,87 +19,33 @@
 
 package org.apache.james.mailbox.backup;
 
-import java.nio.charset.StandardCharsets;
-import java.util.Objects;
 import java.util.Optional;
 
-import org.apache.commons.compress.archivers.zip.ZipExtraField;
 import org.apache.commons.compress.archivers.zip.ZipShort;
+import org.apache.james.mailbox.model.MessageId;
 
-public class MessageIdExtraField implements ZipExtraField {
+public class MessageIdExtraField extends StringExtraField {
 
     public static final ZipShort ID = new ZipShort(0x6C61); // "al" in little-endian
 
-    private Optional<String> messageId;
-
     public MessageIdExtraField() {
-        this(Optional.empty());
-    }
-
-    public MessageIdExtraField(String messageId) {
-        this(Optional.of(messageId));
-    }
-
-    public MessageIdExtraField(Optional<String> messageId) {
-        this.messageId = messageId;
-    }
-
-    @Override
-    public ZipShort getHeaderId() {
-        return ID;
-    }
-
-    @Override
-    public ZipShort getLocalFileDataLength() {
-        return messageId
-            .map(value -> value.getBytes(StandardCharsets.UTF_8).length)
-            .map(ZipShort::new)
-            .orElseThrow(() -> new RuntimeException("Value must by initialized"));
-    }
-
-    @Override
-    public ZipShort getCentralDirectoryLength() {
-        return getLocalFileDataLength();
+        super();
     }
 
-    @Override
-    public byte[] getLocalFileDataData() {
-        return messageId
-            .map(value -> value.getBytes(StandardCharsets.UTF_8))
-            .orElseThrow(() -> new RuntimeException("Value must by initialized"));
+    public MessageIdExtraField(String value) {
+        super(Optional.of(value));
     }
 
-    @Override
-    public byte[] getCentralDirectoryData() {
-        return getLocalFileDataData();
+    public MessageIdExtraField(Optional<String> value) {
+        super(value);
     }
 
-    @Override
-    public void parseFromLocalFileData(byte[] buffer, int offset, int length) {
-        messageId = Optional.of(new String(buffer, offset, length, StandardCharsets.UTF_8));
+    public MessageIdExtraField(MessageId messageId) {
+        super(Optional.of(messageId.serialize()));
     }
 
     @Override
-    public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) {
-        parseFromLocalFileData(buffer, offset, length);
-    }
-
-    public Optional<String> getMessageId() {
-        return messageId;
-    }
-
-    @Override
-    public final boolean equals(Object o) {
-        if (o instanceof MessageIdExtraField) {
-            MessageIdExtraField that = (MessageIdExtraField) o;
-
-            return Objects.equals(this.messageId, that.messageId);
-        }
-        return false;
-    }
-
-    @Override
-    public final int hashCode() {
-        return Objects.hash(messageId);
+    public ZipShort getHeaderId() {
+        return ID;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/StringExtraField.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/StringExtraField.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/StringExtraField.java
new file mode 100644
index 0000000..34c016d
--- /dev/null
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/StringExtraField.java
@@ -0,0 +1,95 @@
+/****************************************************************
+ * 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.backup;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.commons.compress.archivers.zip.ZipExtraField;
+import org.apache.commons.compress.archivers.zip.ZipShort;
+
+public abstract class StringExtraField implements ZipExtraField {
+
+    private Optional<String> value;
+
+    public StringExtraField() {
+        this(Optional.empty());
+    }
+
+    public StringExtraField(Optional<String> value) {
+        this.value = value;
+    }
+
+    @Override
+    public ZipShort getLocalFileDataLength() {
+        return value
+            .map(value -> value.getBytes(StandardCharsets.UTF_8).length)
+            .map(ZipShort::new)
+            .orElseThrow(() -> new RuntimeException("Value must by initialized"));
+    }
+
+    @Override
+    public ZipShort getCentralDirectoryLength() {
+        return getLocalFileDataLength();
+    }
+
+    @Override
+    public byte[] getLocalFileDataData() {
+        return value
+            .map(value -> value.getBytes(StandardCharsets.UTF_8))
+            .orElseThrow(() -> new RuntimeException("Value must by initialized"));
+    }
+
+    @Override
+    public byte[] getCentralDirectoryData() {
+        return getLocalFileDataData();
+    }
+
+    @Override
+    public void parseFromLocalFileData(byte[] buffer, int offset, int length) {
+        value = Optional.of(new String(buffer, offset, length, StandardCharsets.UTF_8));
+    }
+
+    @Override
+    public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) {
+        parseFromLocalFileData(buffer, offset, length);
+    }
+
+    public Optional<String> getValue() {
+        return value;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof StringExtraField) {
+            StringExtraField that = (StringExtraField) o;
+
+            return Objects.equals(this.getValue(), that.getValue())
+                && Objects.equals(this.getHeaderId(), that.getHeaderId());
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(value, getHeaderId());
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/UidValidityExtraField.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/UidValidityExtraField.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/UidValidityExtraField.java
new file mode 100644
index 0000000..a983881
--- /dev/null
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/UidValidityExtraField.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.backup;
+
+import java.util.Optional;
+
+import org.apache.commons.compress.archivers.zip.ZipShort;
+
+public class UidValidityExtraField extends LongExtraField {
+    public static final ZipShort ID = new ZipShort(0x6E61); // "an" in little-endian
+
+    public UidValidityExtraField() {
+        super();
+    }
+
+    public UidValidityExtraField(long value) {
+        super(value);
+    }
+
+    public UidValidityExtraField(Optional<Long> value) {
+        super(value);
+    }
+
+    @Override
+    public ZipShort getHeaderId() {
+        return ID;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java
index 8d09d7e..a249a9f 100644
--- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java
@@ -40,6 +40,7 @@ public class Zipper implements Backup {
         ExtraFieldUtils.register(MessageIdExtraField.class);
         ExtraFieldUtils.register(MailboxIdExtraField.class);
         ExtraFieldUtils.register(InternalDateExtraField.class);
+        ExtraFieldUtils.register(UidValidityExtraField.class);
     }
 
     @Override
@@ -60,6 +61,7 @@ public class Zipper implements Backup {
         ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new Directory(name), name);
 
         archiveEntry.addExtraField(new MailboxIdExtraField(mailbox.getMailboxId().serialize()));
+        archiveEntry.addExtraField(new UidValidityExtraField(mailbox.getUidValidity()));
 
         archiveOutputStream.putArchiveEntry(archiveEntry);
         archiveOutputStream.closeArchiveEntry();

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/InternalDateExtraFieldTest.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/InternalDateExtraFieldTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/InternalDateExtraFieldTest.java
index c511df5..de3f967 100644
--- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/InternalDateExtraFieldTest.java
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/InternalDateExtraFieldTest.java
@@ -19,52 +19,72 @@
 
 package org.apache.james.mailbox.backup;
 
+import static org.apache.commons.lang3.StringUtils.EMPTY;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
-import java.util.zip.ZipException;
 
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
-import org.testcontainers.shaded.org.bouncycastle.util.Arrays;
 
 import com.google.common.base.Charsets;
 
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+
 public class InternalDateExtraFieldTest {
-    private static final byte[] ZERO_AS_BYTE_ARRAY = {0, 0, 0, 0, 0, 0, 0, 0};
-    private static final byte[] _123456789ABCDEF0_AS_LE_BYTE_ARRAY = new byte[] {(byte) 0xF0, (byte) 0xDE, (byte) 0xBC, (byte) 0x9A, 0x78, 0x56, 0x34, 0x12};
-    private static final byte[] FEDCBA9876543210_AS_LE_BYTE_ARRAY = new byte[] {0x10, 0x32, 0x54, 0x76, (byte) 0x98, (byte) 0xBA, (byte) 0xDC, (byte) 0xFE};
-    private static final byte[] UNUSED = new byte[] {(byte) 0xDE, (byte) 0xAD};
 
-    private static final byte[] DEFAULT_DATE_BYTE_ARRAY = {(byte) 0xdd, (byte) 0xf2, (byte) 0xdc, 0x20, 0x64, 0x01, 0x00, 0x00 };
-    private static final long DEFAULT_DATE_TIMESTAMP = 1529559708381L;
-    private static final Date DEFAULT_DATE = new Date(DEFAULT_DATE_TIMESTAMP);
+    public static final String DATE_STRING_1 = "2018-02-15T22:54:02+07:00";
+    private static final ZonedDateTime DATE_1 = ZonedDateTime.parse(DATE_STRING_1, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
+    private static final byte[] DATE_STRING_1_BYTE_ARRAY = DATE_STRING_1.getBytes(StandardCharsets.UTF_8);
+
+    private static final String DEFAULT_MAILBOX_ID = "123456789ABCDEF0";
+    private static final byte[] DEFAULT_MAILBOX_ID_BYTE_ARRAY = new byte[] {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30};
+    private static final byte [] EMPTY_BYTE_ARRAY = {};
+
+    @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(MailboxIdExtraField.class)
+            .suppress(Warning.NONFINAL_FIELDS)
+            .verify();
+    }
 
     @Nested
     class GetHeaderId {
 
         @Test
         void getHeaderIdShouldReturnSpecificStringInLittleEndian() {
-            InternalDateExtraField testee = new InternalDateExtraField();
-
+            MailboxIdExtraField testee = new MailboxIdExtraField();
             ByteBuffer byteBuffer = ByteBuffer.wrap(testee.getHeaderId().getBytes())
                 .order(ByteOrder.LITTLE_ENDIAN);
+
             assertThat(Charsets.US_ASCII.decode(byteBuffer).toString())
-                .isEqualTo("ao");
+                .isEqualTo("am");
         }
     }
 
     @Nested
     class GetLocalFileDataLength {
+
+        @Test
+        void getLocalFileDataLengthShouldThrowWhenNoValue() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
+            assertThatThrownBy(() -> testee.getLocalFileDataLength().getValue())
+                .isInstanceOf(RuntimeException.class);
+        }
+
         @Test
         void getLocalFileDataLengthShouldReturnIntegerSize() {
-            InternalDateExtraField testee = new InternalDateExtraField();
+            MailboxIdExtraField testee = new MailboxIdExtraField(DEFAULT_MAILBOX_ID);
 
             assertThat(testee.getLocalFileDataLength().getValue())
-                .isEqualTo(Long.BYTES);
+                .isEqualTo(16);
         }
     }
 
@@ -72,68 +92,84 @@ public class InternalDateExtraFieldTest {
     class GetCentralDirectoryLength {
 
         @Test
+        void getCentralDirectoryLengthShouldThrowWhenNoValue() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
+            assertThatThrownBy(() -> testee.getCentralDirectoryLength().getValue())
+                .isInstanceOf(RuntimeException.class);
+        }
+
+        @Test
         void getCentralDirectoryLengthShouldReturnIntegerSize() {
-            InternalDateExtraField testee = new InternalDateExtraField();
+            MailboxIdExtraField testee = new MailboxIdExtraField(DEFAULT_MAILBOX_ID);
 
             assertThat(testee.getCentralDirectoryLength().getValue())
-                .isEqualTo(Long.BYTES);
+                .isEqualTo(16);
         }
+    }
 
+    @Nested
+    class GetLocalFileDataData {
 
         @Test
-        void getCentralDirectoryDataShouldThrowWhenNoValue() {
-            InternalDateExtraField testee = new InternalDateExtraField();
+        void getLocalFileDataDataShouldThrowWhenNoValue() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
 
-            assertThatThrownBy(() -> testee.getCentralDirectoryData())
+            assertThatThrownBy(() -> testee.getLocalFileDataData())
                 .isInstanceOf(RuntimeException.class);
         }
 
         @Test
-        void getCentralDirectoryDataShouldReturnZeroWhenZero() {
-            byte[] actual = new InternalDateExtraField(0).getCentralDirectoryData();
-            assertThat(actual).isEqualTo(ZERO_AS_BYTE_ARRAY);
+        void getLocalFileDataDataShouldReturnEmptyArrayWhenValueIsEmpty() {
+            byte[] actual = new MailboxIdExtraField(EMPTY).getLocalFileDataData();
+            assertThat(actual).isEqualTo(EMPTY_BYTE_ARRAY);
         }
 
         @Test
-        void getCentralDirectoryDataShouldReturnValueInLittleIndianWhen123456789ABCDEF0() {
-            byte[] actual = new InternalDateExtraField(0x123456789ABCDEF0L).getCentralDirectoryData();
-            assertThat(actual).isEqualTo(_123456789ABCDEF0_AS_LE_BYTE_ARRAY);
+        void getLocalFileDataDataShouldReturnValueInByteArray() {
+            byte[] actual = new MailboxIdExtraField(DEFAULT_MAILBOX_ID).getLocalFileDataData();
+            assertThat(actual).isEqualTo(DEFAULT_MAILBOX_ID_BYTE_ARRAY);
         }
 
         @Test
-        void getCentralDirectoryDataShouldReturnValueInLittleIndianWhenFEDCBA9876543210() {
-            byte[] actual = new InternalDateExtraField(0xFEDCBA9876543210L).getCentralDirectoryData();
-            assertThat(actual).isEqualTo(FEDCBA9876543210_AS_LE_BYTE_ARRAY);
+        void getLocalFileDataShouldReturnDateByteArrayWhenPassDate() {
+            byte[] actual = new InternalDateExtraField(Date.from(DATE_1.toInstant()))
+                .getLocalFileDataData();
+
+            assertThat(actual)
+                .isEqualTo(DATE_STRING_1_BYTE_ARRAY);
         }
     }
 
     @Nested
-    class GetLocalFileDataData {
+    class GetCentralDirectoryData {
 
         @Test
-        void getLocalFileDataDataShouldThrowWhenNoValue() {
-            InternalDateExtraField testee = new InternalDateExtraField();
+        void getCentralDirectoryDataShouldThrowWhenNoValue() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
 
-            assertThatThrownBy(() -> testee.getLocalFileDataData())
+            assertThatThrownBy(() -> testee.getCentralDirectoryData())
                 .isInstanceOf(RuntimeException.class);
         }
 
         @Test
-        void getLocalFileDataDataShouldReturnZeroWhenZero() {
-            byte[] actual = new InternalDateExtraField(0).getLocalFileDataData();
-            assertThat(actual).isEqualTo(ZERO_AS_BYTE_ARRAY);
+        void getCentralDirectoryDataShouldReturnEmptyArrayWhenValueIsEmpty() {
+            byte[] actual = new MailboxIdExtraField(EMPTY).getCentralDirectoryData();
+            assertThat(actual).isEqualTo(EMPTY_BYTE_ARRAY);
         }
 
         @Test
-        void getLocalFileDataDataShouldReturnValueInLittleIndianWhen123456789ABCDEF0() {
-            byte[] actual = new InternalDateExtraField(0x123456789ABCDEF0L).getLocalFileDataData();
-            assertThat(actual).isEqualTo(_123456789ABCDEF0_AS_LE_BYTE_ARRAY);
+        void getCentralDirectoryDataShouldReturnValueInByteArray() {
+            byte[] actual = new MailboxIdExtraField(DEFAULT_MAILBOX_ID).getCentralDirectoryData();
+            assertThat(actual).isEqualTo(DEFAULT_MAILBOX_ID_BYTE_ARRAY);
         }
 
         @Test
-        void getLocalFileDataDataShouldReturnValueInLittleIndianWhenFEDCBA9876543210() {
-            byte[] actual = new InternalDateExtraField(0xFEDCBA9876543210L).getLocalFileDataData();
-            assertThat(actual).isEqualTo(FEDCBA9876543210_AS_LE_BYTE_ARRAY);
+        void getCentralDirectoryDataShouldReturnDateByteArrayWhenPassDate() {
+            byte[] actual = new InternalDateExtraField(Date.from(DATE_1.toInstant()))
+                .getCentralDirectoryData();
+
+            assertThat(actual)
+                .isEqualTo(DATE_STRING_1_BYTE_ARRAY);
         }
     }
 
@@ -141,78 +177,43 @@ public class InternalDateExtraFieldTest {
     class ParseFromLocalFileData {
 
         @Test
-        void parseFromLocalFileDataShouldThrownWhenLengthIsSmallerThan8() {
-            InternalDateExtraField testee = new InternalDateExtraField();
-
-            byte[] input = new byte[] {0, 0, 0, 0, 0, 0, 0};
-            assertThatThrownBy(() -> testee.parseFromLocalFileData(input, 0, 7))
-                .isInstanceOf(ZipException.class);
-        }
-
-        @Test
-        void parseFromLocalFileDataShouldThrownWhenLengthIsBiggerThan8() {
-            InternalDateExtraField testee = new InternalDateExtraField();
+        void parseFromLocalFileDataShouldParseWhenZero() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
 
-            byte[] input = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0};
-            assertThatThrownBy(() -> testee.parseFromLocalFileData(input, 0, 9))
-                .isInstanceOf(ZipException.class);
-        }
+            testee.parseFromLocalFileData(EMPTY_BYTE_ARRAY, 0, 0);
 
-        @Test
-        void parseFromLocalFileDataShouldParseWhenZero() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
-
-            testee.parseFromLocalFileData(ZERO_AS_BYTE_ARRAY, 0, 8);
             assertThat(testee.getValue())
-                .contains(0L);
+                .contains(EMPTY);
         }
 
         @Test
-        void parseFromLocalFileDataShouldParseWhen123456789ABCDEF0InLittleEndian() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
+        void parseFromLocalFileDataShouldParseByteArray() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
 
-            testee.parseFromLocalFileData(_123456789ABCDEF0_AS_LE_BYTE_ARRAY, 0, 8);
-            assertThat(testee.getValue())
-                .contains(0x123456789ABCDEF0L);
-        }
-
-        @Test
-        void parseFromLocalFileDataShouldParseWhenFEDCBA9876543210InLittleEndian() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
+            testee.parseFromLocalFileData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 0, 16);
 
-            byte[] input = FEDCBA9876543210_AS_LE_BYTE_ARRAY;
-            testee.parseFromLocalFileData(input, 0, 8);
             assertThat(testee.getValue())
-                .contains(0xFEDCBA9876543210L);
+                .contains(DEFAULT_MAILBOX_ID);
         }
 
         @Test
-        void parseFromLocalFileDataShouldHandleOffset() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
+        void parseFromLocalFileDataShouldHandleOffset() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
+
+            testee.parseFromLocalFileData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 2, 14);
 
-            byte[] input = Arrays.concatenate(UNUSED, _123456789ABCDEF0_AS_LE_BYTE_ARRAY);
-            testee.parseFromLocalFileData(input, 2, 8);
             assertThat(testee.getValue())
-                .contains(0x123456789ABCDEF0L);
+                .contains("3456789ABCDEF0");
         }
 
         @Test
-        void parseFromLocalFileDataShouldReturnZeroDayWhenZero() throws Exception {
+        void parseFromLocalFileDataShouldReturnDateWhenPassDateByteArray() {
             InternalDateExtraField testee = new InternalDateExtraField();
 
-            testee.parseFromLocalFileData(ZERO_AS_BYTE_ARRAY, 0, 8);
-
-            assertThat(testee.getDateValue())
-                .contains(new Date(0L));
-        }
-
-        @Test
-        void parseFromLocalFileDataShouldReturnDefaultDateWhenPassDefaultDateByteArray() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField(new Date());
-            testee.parseFromLocalFileData(DEFAULT_DATE_BYTE_ARRAY, 0, 8);
+            testee.parseFromLocalFileData(DATE_STRING_1_BYTE_ARRAY, 0, 25);
 
             assertThat(testee.getDateValue())
-                .contains(DEFAULT_DATE);
+                .contains(Date.from(DATE_1.toInstant()));
         }
     }
 
@@ -220,78 +221,43 @@ public class InternalDateExtraFieldTest {
     class ParseFromCentralDirectoryData {
 
         @Test
-        void parseFromCentralDirectoryDataShouldThrownWhenLengthIsSmallerThan8() {
-            InternalDateExtraField testee = new InternalDateExtraField();
-            byte[] input = new byte[7];
-
-            assertThatThrownBy(() -> testee.parseFromCentralDirectoryData(input, 0, 7))
-                .isInstanceOf(ZipException.class);
-        }
-
-        @Test
-        void parseFromCentralDirectoryDataShouldThrownWhenLengthIsBiggerThan8() {
-            InternalDateExtraField testee = new InternalDateExtraField();
-            byte[] input = new byte[9];
-
-            assertThatThrownBy(() -> testee.parseFromCentralDirectoryData(input, 0, 9))
-                .isInstanceOf(ZipException.class);
-        }
+        void parseFromCentralDirectoryDataShouldParseWhenZero() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
 
-        @Test
-        void parseFromCentralDirectoryDataShouldParseWhenZero() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
+            testee.parseFromCentralDirectoryData(EMPTY_BYTE_ARRAY, 0, 0);
 
-            testee.parseFromCentralDirectoryData(ZERO_AS_BYTE_ARRAY, 0, 8);
             assertThat(testee.getValue())
-                .contains(0L);
+                .contains(EMPTY);
         }
 
         @Test
-        void parseFromCentralDirectoryDataShouldParseWhen123456789ABCDEF0InLittleEndian() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
-
-            testee.parseFromCentralDirectoryData(_123456789ABCDEF0_AS_LE_BYTE_ARRAY, 0, 8);
-            assertThat(testee.getValue())
-                .contains(0x123456789ABCDEF0L);
-        }
+        void parseFromCentralDirectoryDataShouldParseByteArray() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
 
-        @Test
-        void parseFromCentralDirectoryDataShouldParseWhenFEDCBA9876543210InLittleEndian() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
-            byte[] input = FEDCBA9876543210_AS_LE_BYTE_ARRAY;
+            testee.parseFromCentralDirectoryData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 0, 16);
 
-            testee.parseFromCentralDirectoryData(input, 0, 8);
             assertThat(testee.getValue())
-                .contains(0xFEDCBA9876543210L);
+                .contains(DEFAULT_MAILBOX_ID);
         }
 
         @Test
-        void parseFromCentralDirectoryDataShouldHandleOffset() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField();
-            byte[] input = Arrays.concatenate(UNUSED, _123456789ABCDEF0_AS_LE_BYTE_ARRAY);
+        void parseFromCentralDirectoryDataShouldHandleOffset() {
+            MailboxIdExtraField testee = new MailboxIdExtraField();
+
+            testee.parseFromCentralDirectoryData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 2, 14);
 
-            testee.parseFromCentralDirectoryData(input, 2, 8);
             assertThat(testee.getValue())
-                .contains(0x123456789ABCDEF0L);
+                .contains("3456789ABCDEF0");
         }
 
         @Test
-        void parseFromCentralDirectoryDataShouldReturnZeroDayWhenZero() throws Exception {
+        void parseFromCentralDirectoryDataShouldReturnDateWhenPassDateByteArray() {
             InternalDateExtraField testee = new InternalDateExtraField();
 
-            testee.parseFromCentralDirectoryData(ZERO_AS_BYTE_ARRAY, 0, 8);
-
-            assertThat(testee.getDateValue())
-                .contains(new Date(0L));
-        }
-
-        @Test
-        void parseFromCentralDirectoryDataShouldReturnDefaultDateWhenPassDefaultDateByteArray() throws Exception {
-            InternalDateExtraField testee = new InternalDateExtraField(new Date());
-            testee.parseFromCentralDirectoryData(DEFAULT_DATE_BYTE_ARRAY, 0, 8);
+            testee.parseFromCentralDirectoryData(DATE_STRING_1_BYTE_ARRAY, 0, 25);
 
             assertThat(testee.getDateValue())
-                .contains(DEFAULT_DATE);
+                .contains(Date.from(DATE_1.toInstant()));
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxIdExtraFieldTest.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxIdExtraFieldTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxIdExtraFieldTest.java
index 684f20c..b5a95b7 100644
--- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxIdExtraFieldTest.java
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxIdExtraFieldTest.java
@@ -31,12 +31,22 @@ import org.junit.jupiter.api.Test;
 
 import com.google.common.base.Charsets;
 
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+
 public class MailboxIdExtraFieldTest {
 
     private static final String DEFAULT_MAILBOX_ID = "123456789ABCDEF0";
     private static final byte[] DEFAULT_MAILBOX_ID_BYTE_ARRAY = new byte[] {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30};
     private static final byte [] EMPTY_BYTE_ARRAY = {};
 
+    @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(MailboxIdExtraField.class)
+            .suppress(Warning.NONFINAL_FIELDS)
+            .verify();
+    }
+
     @Nested
     class GetHeaderId {
 
@@ -146,7 +156,7 @@ public class MailboxIdExtraFieldTest {
 
             testee.parseFromLocalFileData(EMPTY_BYTE_ARRAY, 0, 0);
 
-            assertThat(testee.getMailboxId())
+            assertThat(testee.getValue())
                 .contains(EMPTY);
         }
 
@@ -156,7 +166,7 @@ public class MailboxIdExtraFieldTest {
 
             testee.parseFromLocalFileData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 0, 16);
 
-            assertThat(testee.getMailboxId())
+            assertThat(testee.getValue())
                 .contains(DEFAULT_MAILBOX_ID);
         }
 
@@ -166,7 +176,7 @@ public class MailboxIdExtraFieldTest {
 
             testee.parseFromLocalFileData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 2, 14);
 
-            assertThat(testee.getMailboxId())
+            assertThat(testee.getValue())
                 .contains("3456789ABCDEF0");
         }
     }
@@ -180,7 +190,7 @@ public class MailboxIdExtraFieldTest {
 
             testee.parseFromCentralDirectoryData(EMPTY_BYTE_ARRAY, 0, 0);
 
-            assertThat(testee.getMailboxId())
+            assertThat(testee.getValue())
                 .contains(EMPTY);
         }
 
@@ -190,7 +200,7 @@ public class MailboxIdExtraFieldTest {
 
             testee.parseFromCentralDirectoryData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 0, 16);
 
-            assertThat(testee.getMailboxId())
+            assertThat(testee.getValue())
                 .contains(DEFAULT_MAILBOX_ID);
         }
 
@@ -200,7 +210,7 @@ public class MailboxIdExtraFieldTest {
 
             testee.parseFromCentralDirectoryData(DEFAULT_MAILBOX_ID_BYTE_ARRAY, 2, 14);
 
-            assertThat(testee.getMailboxId())
+            assertThat(testee.getValue())
                 .contains("3456789ABCDEF0");
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java
index 92ff524..697c2b5 100644
--- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java
@@ -42,8 +42,10 @@ import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 
 public interface MailboxMessageFixture {
 
-    ZonedDateTime DATE_1 = ZonedDateTime.parse("2018-02-15T15:54:02Z");
-    ZonedDateTime DATE_2 = ZonedDateTime.parse("2018-03-15T15:54:02Z");
+    String DATE_STRING_1 = "2018-02-15T15:54:02Z";
+    String DATE_STRING_2 = "2018-03-15T15:54:02Z";
+    ZonedDateTime DATE_1 = ZonedDateTime.parse(DATE_STRING_1);
+    ZonedDateTime DATE_2 = ZonedDateTime.parse(DATE_STRING_2);
 
     MessageId.Factory MESSAGE_ID_FACTORY = new TestMessageId.Factory();
     Charset MESSAGE_CHARSET = StandardCharsets.UTF_8;

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MessageIdExtraFieldTest.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MessageIdExtraFieldTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MessageIdExtraFieldTest.java
index c78dc7a..16079aa 100644
--- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MessageIdExtraFieldTest.java
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MessageIdExtraFieldTest.java
@@ -31,12 +31,22 @@ import org.junit.jupiter.api.Test;
 
 import com.google.common.base.Charsets;
 
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+
 public class MessageIdExtraFieldTest {
 
     private static final String DEFAULT_MESSAGE_ID = "123456789ABCDEF0";
     private static final byte[] DEFAULT_MESSAGE_ID_BYTE_ARRAY = new byte[] {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x30};
     private static final byte [] EMPTY_BYTE_ARRAY = {};
 
+    @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(MessageIdExtraField.class)
+            .suppress(Warning.NONFINAL_FIELDS)
+            .verify();
+    }
+
     @Nested
     class GetHeaderId {
 
@@ -150,7 +160,7 @@ public class MessageIdExtraFieldTest {
 
             testee.parseFromLocalFileData(EMPTY_BYTE_ARRAY, 0, 0);
 
-            assertThat(testee.getMessageId())
+            assertThat(testee.getValue())
                 .contains(EMPTY);
         }
 
@@ -160,7 +170,7 @@ public class MessageIdExtraFieldTest {
 
             testee.parseFromLocalFileData(DEFAULT_MESSAGE_ID_BYTE_ARRAY, 0, 16);
 
-            assertThat(testee.getMessageId())
+            assertThat(testee.getValue())
                 .contains(DEFAULT_MESSAGE_ID);
         }
 
@@ -170,7 +180,7 @@ public class MessageIdExtraFieldTest {
 
             testee.parseFromLocalFileData(DEFAULT_MESSAGE_ID_BYTE_ARRAY, 2, 14);
 
-            assertThat(testee.getMessageId())
+            assertThat(testee.getValue())
                 .contains("3456789ABCDEF0");
         }
     }
@@ -184,7 +194,7 @@ public class MessageIdExtraFieldTest {
 
             testee.parseFromCentralDirectoryData(EMPTY_BYTE_ARRAY, 0, 0);
 
-            assertThat(testee.getMessageId())
+            assertThat(testee.getValue())
                 .contains(EMPTY);
         }
 
@@ -194,7 +204,7 @@ public class MessageIdExtraFieldTest {
 
             testee.parseFromCentralDirectoryData(DEFAULT_MESSAGE_ID_BYTE_ARRAY, 0, 16);
 
-            assertThat(testee.getMessageId())
+            assertThat(testee.getValue())
                 .contains(DEFAULT_MESSAGE_ID);
         }
 
@@ -204,7 +214,7 @@ public class MessageIdExtraFieldTest {
 
             testee.parseFromCentralDirectoryData(DEFAULT_MESSAGE_ID_BYTE_ARRAY, 2, 14);
 
-            assertThat(testee.getMessageId())
+            assertThat(testee.getValue())
                 .contains("3456789ABCDEF0");
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/SizeExtraFieldTest.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/SizeExtraFieldTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/SizeExtraFieldTest.java
index d38384a..c2275bd 100644
--- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/SizeExtraFieldTest.java
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/SizeExtraFieldTest.java
@@ -31,6 +31,9 @@ import org.testcontainers.shaded.org.bouncycastle.util.Arrays;
 
 import com.google.common.base.Charsets;
 
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+
 public class SizeExtraFieldTest {
     private static final byte[] ZERO_AS_BYTE_ARRAY = {0, 0, 0, 0, 0, 0, 0, 0};
     private static final byte[] _123456789ABCDEF0_AS_LE_BYTE_ARRAY = new byte[] {(byte) 0xF0, (byte) 0xDE, (byte) 0xBC, (byte) 0x9A, 0x78, 0x56, 0x34, 0x12};
@@ -45,6 +48,13 @@ public class SizeExtraFieldTest {
     }
 
     @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(SizeExtraField.class)
+            .suppress(Warning.NONFINAL_FIELDS)
+            .verify();
+    }
+
+    @Test
     void getLocalFileDataLengthShouldReturnIntegerSize() {
         assertThat(testee.getLocalFileDataLength().getValue())
             .isEqualTo(Long.BYTES);

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidExtraFieldTest.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidExtraFieldTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidExtraFieldTest.java
index ed3376d..3514717 100644
--- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidExtraFieldTest.java
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidExtraFieldTest.java
@@ -32,12 +32,22 @@ import org.testcontainers.shaded.org.bouncycastle.util.Arrays;
 
 import com.google.common.base.Charsets;
 
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+
 public class UidExtraFieldTest {
     private static final byte[] ZERO_AS_BYTE_ARRAY = {0, 0, 0, 0, 0, 0, 0, 0};
     private static final byte[] _123456789ABCDEF0_AS_LE_BYTE_ARRAY = new byte[] {(byte) 0xF0, (byte) 0xDE, (byte) 0xBC, (byte) 0x9A, 0x78, 0x56, 0x34, 0x12};
     private static final byte[] FEDCBA9876543210_AS_LE_BYTE_ARRAY = new byte[] {0x10, 0x32, 0x54, 0x76, (byte) 0x98, (byte) 0xBA, (byte) 0xDC, (byte) 0xFE};
     private static final byte[] UNUSED = new byte[] {(byte) 0xDE, (byte) 0xAD};
 
+    @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(UidExtraField.class)
+            .suppress(Warning.NONFINAL_FIELDS)
+            .verify();
+    }
+
     @Nested
     class GetHeaderId {
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidValidityExtraFieldTest.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidValidityExtraFieldTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidValidityExtraFieldTest.java
new file mode 100644
index 0000000..e9b312f
--- /dev/null
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/UidValidityExtraFieldTest.java
@@ -0,0 +1,264 @@
+/****************************************************************
+ * 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.backup;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.zip.ZipException;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.org.bouncycastle.util.Arrays;
+
+import com.google.common.base.Charsets;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+import nl.jqno.equalsverifier.Warning;
+
+public class UidValidityExtraFieldTest {
+    private static final byte[] ZERO_AS_BYTE_ARRAY = {0, 0, 0, 0, 0, 0, 0, 0};
+    private static final byte[] _123456789ABCDEF0_AS_LE_BYTE_ARRAY = new byte[] {(byte) 0xF0, (byte) 0xDE, (byte) 0xBC, (byte) 0x9A, 0x78, 0x56, 0x34, 0x12};
+    private static final byte[] FEDCBA9876543210_AS_LE_BYTE_ARRAY = new byte[] {0x10, 0x32, 0x54, 0x76, (byte) 0x98, (byte) 0xBA, (byte) 0xDC, (byte) 0xFE};
+    private static final byte[] UNUSED = new byte[] {(byte) 0xDE, (byte) 0xAD};
+
+    @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(UidValidityExtraField.class)
+            .suppress(Warning.NONFINAL_FIELDS)
+            .verify();
+    }
+
+    @Nested
+    class GetHeaderId {
+
+        @Test
+        void getHeaderIdShouldReturnSpecificStringInLittleEndian() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            ByteBuffer byteBuffer = ByteBuffer.wrap(testee.getHeaderId().getBytes())
+                .order(ByteOrder.LITTLE_ENDIAN);
+            assertThat(Charsets.US_ASCII.decode(byteBuffer).toString())
+                .isEqualTo("an");
+        }
+    }
+
+    @Nested
+    class GetLocalFileDataLength {
+        @Test
+        void getLocalFileDataLengthShouldReturnIntegerSize() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            assertThat(testee.getLocalFileDataLength().getValue())
+                .isEqualTo(Long.BYTES);
+        }
+    }
+
+    @Nested
+    class GetCentralDirectoryLength {
+
+        @Test
+        void getCentralDirectoryLengthShouldReturnIntegerSize() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            assertThat(testee.getCentralDirectoryLength().getValue())
+                .isEqualTo(Long.BYTES);
+        }
+
+
+        @Test
+        void getCentralDirectoryDataShouldThrowWhenNoValue() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            assertThatThrownBy(() -> testee.getCentralDirectoryData())
+                .isInstanceOf(RuntimeException.class);
+        }
+
+        @Test
+        void getCentralDirectoryDataShouldReturnZeroWhenZero() {
+            byte[] actual = new UidValidityExtraField(0).getCentralDirectoryData();
+            assertThat(actual).isEqualTo(ZERO_AS_BYTE_ARRAY);
+        }
+
+        @Test
+        void getCentralDirectoryDataShouldReturnValueInLittleIndianWhen123456789ABCDEF0() {
+            byte[] actual = new UidValidityExtraField(0x123456789ABCDEF0L).getCentralDirectoryData();
+            assertThat(actual).isEqualTo(_123456789ABCDEF0_AS_LE_BYTE_ARRAY);
+        }
+
+        @Test
+        void getCentralDirectoryDataShouldReturnValueInLittleIndianWhenFEDCBA9876543210() {
+            byte[] actual = new UidValidityExtraField(0xFEDCBA9876543210L).getCentralDirectoryData();
+            assertThat(actual).isEqualTo(FEDCBA9876543210_AS_LE_BYTE_ARRAY);
+        }
+    }
+
+    @Nested
+    class GetLocalFileDataData {
+
+        @Test
+        void getLocalFileDataDataShouldThrowWhenNoValue() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            assertThatThrownBy(() -> testee.getLocalFileDataData())
+                .isInstanceOf(RuntimeException.class);
+        }
+
+        @Test
+        void getLocalFileDataDataShouldReturnZeroWhenZero() {
+            byte[] actual = new UidValidityExtraField(0).getLocalFileDataData();
+            assertThat(actual).isEqualTo(ZERO_AS_BYTE_ARRAY);
+        }
+
+        @Test
+        void getLocalFileDataDataShouldReturnValueInLittleIndianWhen123456789ABCDEF0() {
+            byte[] actual = new UidValidityExtraField(0x123456789ABCDEF0L).getLocalFileDataData();
+            assertThat(actual).isEqualTo(_123456789ABCDEF0_AS_LE_BYTE_ARRAY);
+        }
+
+        @Test
+        void getLocalFileDataDataShouldReturnValueInLittleIndianWhenFEDCBA9876543210() {
+            byte[] actual = new UidValidityExtraField(0xFEDCBA9876543210L).getLocalFileDataData();
+            assertThat(actual).isEqualTo(FEDCBA9876543210_AS_LE_BYTE_ARRAY);
+        }
+    }
+
+    @Nested
+    class ParseFromLocalFileData {
+
+        @Test
+        void parseFromLocalFileDataShouldThrownWhenLengthIsSmallerThan8() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            byte[] input = new byte[] {0, 0, 0, 0, 0, 0, 0};
+            assertThatThrownBy(() -> testee.parseFromLocalFileData(input, 0, 7))
+                .isInstanceOf(ZipException.class);
+        }
+
+        @Test
+        void parseFromLocalFileDataShouldThrownWhenLengthIsBiggerThan8() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            byte[] input = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0};
+            assertThatThrownBy(() -> testee.parseFromLocalFileData(input, 0, 9))
+                .isInstanceOf(ZipException.class);
+        }
+
+        @Test
+        void parseFromLocalFileDataShouldParseWhenZero() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            testee.parseFromLocalFileData(ZERO_AS_BYTE_ARRAY, 0, 8);
+            assertThat(testee.getValue())
+                .contains(0L);
+        }
+
+        @Test
+        void parseFromLocalFileDataShouldParseWhen123456789ABCDEF0InLittleEndian() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            testee.parseFromLocalFileData(_123456789ABCDEF0_AS_LE_BYTE_ARRAY, 0, 8);
+            assertThat(testee.getValue())
+                .contains(0x123456789ABCDEF0L);
+        }
+
+        @Test
+        void parseFromLocalFileDataShouldParseWhenFEDCBA9876543210InLittleEndian() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            byte[] input = FEDCBA9876543210_AS_LE_BYTE_ARRAY;
+            testee.parseFromLocalFileData(input, 0, 8);
+            assertThat(testee.getValue())
+                .contains(0xFEDCBA9876543210L);
+        }
+
+        @Test
+        void parseFromLocalFileDataShouldHandleOffset() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            byte[] input = Arrays.concatenate(UNUSED, _123456789ABCDEF0_AS_LE_BYTE_ARRAY);
+            testee.parseFromLocalFileData(input, 2, 8);
+            assertThat(testee.getValue())
+                .contains(0x123456789ABCDEF0L);
+        }
+    }
+
+    @Nested
+    class ParseFromCentralDirectoryData {
+
+        @Test
+        void parseFromCentralDirectoryDataShouldThrownWhenLengthIsSmallerThan8() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+            byte[] input = new byte[7];
+
+            assertThatThrownBy(() -> testee.parseFromCentralDirectoryData(input, 0, 7))
+                .isInstanceOf(ZipException.class);
+        }
+
+        @Test
+        void parseFromCentralDirectoryDataShouldThrownWhenLengthIsBiggerThan8() {
+            UidValidityExtraField testee = new UidValidityExtraField();
+            byte[] input = new byte[9];
+
+            assertThatThrownBy(() -> testee.parseFromCentralDirectoryData(input, 0, 9))
+                .isInstanceOf(ZipException.class);
+        }
+
+        @Test
+        void parseFromCentralDirectoryDataShouldParseWhenZero() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            testee.parseFromCentralDirectoryData(ZERO_AS_BYTE_ARRAY, 0, 8);
+            assertThat(testee.getValue())
+                .contains(0L);
+        }
+
+        @Test
+        void parseFromCentralDirectoryDataShouldParseWhen123456789ABCDEF0InLittleEndian() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+
+            testee.parseFromCentralDirectoryData(_123456789ABCDEF0_AS_LE_BYTE_ARRAY, 0, 8);
+            assertThat(testee.getValue())
+                .contains(0x123456789ABCDEF0L);
+        }
+
+        @Test
+        void parseFromCentralDirectoryDataShouldParseWhenFEDCBA9876543210InLittleEndian() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+            byte[] input = FEDCBA9876543210_AS_LE_BYTE_ARRAY;
+
+            testee.parseFromCentralDirectoryData(input, 0, 8);
+            assertThat(testee.getValue())
+                .contains(0xFEDCBA9876543210L);
+        }
+
+        @Test
+        void parseFromCentralDirectoryDataShouldHandleOffset() throws Exception {
+            UidValidityExtraField testee = new UidValidityExtraField();
+            byte[] input = Arrays.concatenate(UNUSED, _123456789ABCDEF0_AS_LE_BYTE_ARRAY);
+
+            testee.parseFromCentralDirectoryData(input, 2, 8);
+            assertThat(testee.getValue())
+                .contains(0x123456789ABCDEF0L);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/628420f3/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
index 975d53c..58ca610 100644
--- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
+++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/ZipperTest.java
@@ -30,8 +30,8 @@ import static org.apache.james.mailbox.backup.MailboxMessageFixture.MESSAGE_ID_1
 import static org.apache.james.mailbox.backup.MailboxMessageFixture.MESSAGE_ID_2;
 import static org.apache.james.mailbox.backup.MailboxMessageFixture.MESSAGE_UID_1_VALUE;
 import static org.apache.james.mailbox.backup.MailboxMessageFixture.SIZE_1;
-import static org.apache.james.mailbox.backup.ZipAssert.assertThatZip;
 import static org.apache.james.mailbox.backup.ZipAssert.EntryChecks.hasName;
+import static org.apache.james.mailbox.backup.ZipAssert.assertThatZip;
 
 import java.io.ByteArrayOutputStream;
 import java.util.List;
@@ -101,6 +101,7 @@ class ZipperTest {
                         .containsExtraFields(new SizeExtraField(SIZE_1))
                         .containsExtraFields(new UidExtraField(MESSAGE_UID_1_VALUE))
                         .containsExtraFields(new MessageIdExtraField(MESSAGE_ID_1.serialize()))
+                        .containsExtraFields(new MailboxIdExtraField(MAILBOX_ID_1))
                         .containsExtraFields(new InternalDateExtraField(MESSAGE_1.getInternalDate())));
         }
     }
@@ -169,7 +170,9 @@ class ZipperTest {
             assertThatZip(zipFile)
                 .containsOnlyEntriesMatching(
                     hasName(MAILBOX_1.getName() + "/")
-                        .containsExtraFields(new MailboxIdExtraField(MAILBOX_1.getMailboxId().serialize())));
+                        .containsExtraFields(
+                            new MailboxIdExtraField(MAILBOX_1.getMailboxId()),
+                            new UidValidityExtraField(MAILBOX_1.getUidValidity())));
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message