/*
 * Copyright 2016 Jaakko Hannikainen
 *
 * Licensed 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 fi.jgke.tagger.domain;

import fi.jgke.tagger.exception.TagAlreadyExistsException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.junit.Test;
import static org.junit.Assert.*;

public class SourceTest {

    public SourceTest() {
    }

    @Test
    public void testSetGetTitle() {
        String title = UUID.randomUUID().toString();
        Source instance = new Source();
        instance.setTitle(title);
        assertEquals(title, instance.getTitle());
    }

    @Test
    public void testSetGetUrl() {
        String url = UUID.randomUUID().toString();
        Source instance = new Source();
        instance.setUrl(url);
        assertEquals(url, instance.getUrl());
    }

    @Test
    public void testSetGetTitleAndUrl() {
        String title = UUID.randomUUID().toString();
        String url = UUID.randomUUID().toString();
        Source instance = new Source();
        instance.setTitle(title);
        instance.setUrl(url);
        assertEquals(title, instance.getTitle());
        assertEquals(url, instance.getUrl());
    }

    @Test
    public void testSetGetSourcetype() {
        Type sourcetype = new Type();
        sourcetype.setValue(UUID.randomUUID().toString());
        Source instance = new Source();
        instance.setSourcetype(sourcetype);
        assertEquals(sourcetype, instance.getSourcetype());
    }

    @Test
    public void testSetGetTags() throws NoSuchMethodException {
        Set<Tag> tags = new HashSet<>();
        for (int i = 0; i < 3; i++) {
            Tag tag = new Tag();
            tag.setValue(UUID.randomUUID().toString());
            tags.add(tag);
        }
        Source instance = new Source();
        instance.setTags(tags);
        assertEquals(tags, instance.getTags());
    }

    @Test
    public void testAddTag() {
        Source instance = new Source();
        Tag tag = new Tag("foo");
        instance.addTag(tag);
        assertTrue(instance.getTags().contains(tag));
    }

    @Test(expected = TagAlreadyExistsException.class)
    public void testAddDuplicateTagThrows() {
        Source instance = new Source();
        Tag tag = new Tag("foo");
        instance.addTag(tag);
        instance.addTag(tag);
    }
}

@@ -2078,43 +2078,793 @@
 tGet
-Tags() throws NoSuchMethodException
+Comments() %7B%0A        List%3CComment%3E comments = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C 3; i++) %7B%0A            Comment comment = new Comment();%0A            comment.setComment(UUID.randomUUID().toString());%0A            comments.add(comment);%0A        %7D%0A        Source instance = new Source();%0A        instance.setComments(comments);%0A        assertEquals(comments, instance.getComments());%0A    %7D%0A%0A    @Test%0A    public void testAddComment() %7B%0A        Comment comment = new Comment();%0A        comment.setComment(UUID.randomUUID().toString());%0A        Source instance = new Source();%0A        instance.setComments(new ArrayList%3C%3E());%0A        instance.addComment(comment);%0A        assertTrue(instance.getComments().get(0).equals(comment));%0A    %7D%0A%0A    @Test%0A    public void testSetGetTags()
  %7B%0A 
@@ -3596,32 +3596,32 @@
 ce.addTag(tag);%0A
-
         instance
@@ -3639,11 +3639,484 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testRemoveTag() %7B%0A        Source instance = new Source();%0A        Tag tag = new Tag(%22foo%22);%0A        Tag tag2 = new Tag(%22bar%22);%0A        instance.addTag(tag);%0A        instance.addTag(tag2);%0A        assertTrue(instance.getTags().contains(tag));%0A        assertTrue(instance.getTags().contains(tag2));%0A        instance.removeTag(tag);%0A        assertFalse(instance.getTags().contains(tag));%0A        assertTrue(instance.getTags().contains(tag2));%0A    %7D
 %0A%7D%0A

Add some more unit tests for Source