@@ -0,0 +1,3668 @@
+/*%0A * Copyright 2016-2017 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage de.vorb.platon.web.api.common;%0A%0Aimport de.vorb.platon.jooq.tables.records.CommentsRecord;%0Aimport de.vorb.platon.model.CommentStatus;%0Aimport de.vorb.platon.web.api.json.CommentJson;%0A%0Aimport org.junit.Test;%0A%0Aimport java.sql.Timestamp;%0Aimport java.time.Instant;%0Aimport java.util.Base64;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Apublic class CommentConverterTest %7B%0A%0A    private final CommentConverter commentConverter = new CommentConverter();%0A%0A    @Test%0A    public void convertsRegularRecordToEquivalentJson() throws Exception %7B%0A%0A        final CommentsRecord record = createCommentRecord(CommentStatus.PUBLIC);%0A%0A        final CommentJson json = commentConverter.convertRecordToJson(record);%0A%0A        assertThatMetaFieldsMatchRecord(json, record);%0A        assertThatContentFieldsMatchRecord(json, record);%0A    %7D%0A%0A    @Test%0A    public void convertsDeletedRecordToJsonWithoutContent() throws Exception %7B%0A%0A        final CommentsRecord record = createCommentRecord(CommentStatus.DELETED);%0A%0A        final CommentJson json = commentConverter.convertRecordToJson(record);%0A%0A        assertThatMetaFieldsMatchRecord(json, record);%0A        assertThatContentFieldsAreNull(json);%0A        assertThat(json.getReplies()).isEmpty();%0A    %7D%0A%0A    private void assertThatMetaFieldsMatchRecord(CommentJson json, CommentsRecord record) %7B%0A        assertThat(json.getId()).isEqualTo(record.getId());%0A        assertThat(json.getParentId()).isEqualTo(record.getParentId());%0A        assertThat(json.getCreationDate()).isEqualTo(record.getCreationDate().toInstant());%0A        assertThat(json.getLastModificationDate()).isEqualTo(record.getLastModificationDate().toInstant());%0A        assertThat(json.getStatus()).isEqualTo(CommentStatus.valueOf(record.getStatus()));%0A    %7D%0A%0A    private void assertThatContentFieldsMatchRecord(CommentJson json, CommentsRecord record) %7B%0A        assertThat(json.getText()).isEqualTo(record.getText());%0A        assertThat(json.getAuthor()).isEqualTo(record.getAuthor());%0A        assertThat(json.getEmailHash()).isEqualTo(Base64.getDecoder().decode(record.getEmailHash()));%0A        assertThat(json.getUrl()).isEqualTo(record.getUrl());%0A        assertThat(json.getReplies()).isEmpty();%0A    %7D%0A%0A    private void assertThatContentFieldsAreNull(CommentJson json) %7B%0A        assertThat(json.getText()).isNull();%0A        assertThat(json.getAuthor()).isNull();%0A        assertThat(json.getEmailHash()).isNull();%0A        assertThat(json.getUrl()).isNull();%0A    %7D%0A%0A    private CommentsRecord createCommentRecord(CommentStatus status) %7B%0A        return new CommentsRecord()%0A                .setId(15L)%0A                .setParentId(13L)%0A                .setCreationDate(Timestamp.from(Instant.now().minusSeconds(53)))%0A                .setLastModificationDate(Timestamp.from(Instant.now()))%0A                .setStatus(status.toString())%0A                .setText(%22Some text%22)%0A                .setAuthor(%22Jane Doe%22)%0A                .setEmailHash(%22DBe/ZuZJBwFncB0tPNcXEQ==%22)%0A                .setUrl(%22https://example.org/~jane.html%22);%0A    %7D%0A%0A%7D%0A

Implement unit test for CommentConverter