@Test void deserializeShouldThrowWhenNoFlags() { assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"modSeq\": 35," + " \"size\": 45, " + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + " \"messageId\": \"42\"" + "}")) .get()) .isInstanceOf(NoSuchElementException.class); }
@Test void mailboxPathDeserializationShouldFailWhenLongMailboxName() { assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":\"user\"," + " \"name\":42" + "}"))) .isInstanceOf(JsError.class); }
@Test void fromJsonShouldDeserializeQuotaCount() { assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava()) .isEqualTo(quota); } }
@Test void flagsUpdatedShouldThrowWhenMoqSeqIsAString() { assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": \"35\"," + " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," + " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" + " }"))) .isInstanceOf(JsError.class); }
@Test void flagsUpdatedShouldThrowWhenMoqSeqIsNotAnInteger() { assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": 35.2567454," + " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," + " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" + " }"))) .isInstanceOf(JsError.class); }
@Test void deSerializeShouldThrowWhenNewACLIsMissing() { assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( "{\"oldACL\":{}}"))) .isInstanceOf(JsError.class); }
@Test void deSerializeShouldThrowWhenOldACLIsMissing() { assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( "{\"newACL\":{}}"))) .isInstanceOf(JsError.class); }
@Test void deserializeShouldThrowWhenNoSystemFlags() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"userFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } }
@Test void mailboxPathDeserializationShouldFailWhenLongUser() { assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":42," + " \"name\":\"mailboxName\"" + "}"))) .isInstanceOf(JsError.class); }
@Test void fromJsonShouldDeserializeQuotaCount() { assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava()) .isEqualTo(quota); } }
@Test void fromJsonShouldDeserializeQuotaCount() { assertThat(DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava()) .isEqualTo(quota); } }
@Test void fromJsonShouldThrowOnInvalidScope() { assertThatThrownBy(() -> DTO_JSON_SERIALIZE.quotaCReads().reads(Json.parse(json)).get().toJava()) .isInstanceOf(IllegalArgumentException.class); }
@Test void flagsUpdatedShouldThrowWhenOldFlagIsMissing() { assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": 35," + " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" + " }"))) .isInstanceOf(JsError.class); }
@Test void deserializeShouldThrowWhenUserFlagsContainsNonStringElements() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[42, \"a\"]}")) .get())) .isInstanceOf(NoSuchElementException.class); }
@Test void deserializeShouldThrowWhenNoUserFlags() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); }
@Test void mailboxPathWithNullUserShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":null," + " \"name\":\"mailboxName\"" + "}")).get()) .isEqualTo(DTOs.MailboxPath$.MODULE$.fromJava( new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME))); }
@Test void emptyFlagsShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags()); }
@Test void answeredShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.ANSWERED)); }
@Test void seenShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.SEEN)); }
@Test void userFlagShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}")) .get())) .isEqualTo(new Flags("user flag")); }