/*******************************************************************************
 * Copyright 2015 Jan Christian Krause
 *
 * 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 de.jankrause.javadoctools.connectors;

import de.jankrause.javadoctools.domain.Column;
import de.jankrause.javadoctools.domain.CommentType;
import de.jankrause.javadoctools.domain.Table;
import de.jankrause.javadoctools.utils.DbCommentProcessor;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

import static org.junit.Assert.assertEquals;

public class FetchDatabaseCommentTest {

    @Test
    public void shouldNotFetchColumnCommentFromAnnotation()throws IOException, SQLException {
        DbConnector dbConnector = Mockito.mock(DbConnector.class);
        Mockito.when(dbConnector.fetchColumnsComment(Mockito.<Column>any())).
                thenThrow(new RuntimeException("Not yet implemented."));

        DbCommentProcessor fetcher = new DbCommentProcessor(26, new File("src/test/resources/testpackage/AnnotatedEntity.java"), "", CommentType.FIELD);
        assertEquals("<MISSING COMMENT>",
                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());

        fetcher = new DbCommentProcessor(26, new File("src/test/resources/testpackage/AnnotatedEntity.java"), "", CommentType.NONE);
        assertEquals("<MISSING COMMENT>",
                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());
    }

    @Test
    public void shouldFindTheTableAnyway()throws IOException, SQLException {
        Table testComments = new Table("test_comments");
        DbConnector dbConnector = Mockito.mock(DbConnector.class);
        Mockito.when(dbConnector.fetchTablesComment(testComments)).
                thenReturn("Comment for table test_comments");

        DbCommentProcessor fetcher = new DbCommentProcessor(26, new File("src/test/resources/testpackage/AnnotatedEntity.java"), "", CommentType.INTERFACE);
        assertEquals("Comment for table test_comments",
                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());

        fetcher = new DbCommentProcessor(26, new File("src/test/resources/testpackage/AnnotatedEntity.java"), "", CommentType.CLASS);
        assertEquals("Comment for table test_comments",
                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());

        fetcher = new DbCommentProcessor(-100, new File("src/test/resources/testpackage/AnnotatedEntity.java"), "", CommentType.CLASS);
        assertEquals("Comment for table test_comments",
                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());
    }

    @Test
    public void shouldNotFindTheTableAnyway()throws IOException, SQLException {
        DbConnector dbConnector = Mockito.mock(DbConnector.class);

        DbCommentProcessor fetcher = new DbCommentProcessor(26, new File("src/test/resources/testpackage/MyTermDefinition.java"), "", CommentType.INTERFACE);
        assertEquals("<MISSING COMMENT>",
                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());

        fetcher = new DbCommentProcessor(-100, new File("src/test/resources/testpackage/MyTermDefinition.java"), "", CommentType.CLASS);
        assertEquals("<MISSING COMMENT>",
                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());
    }

}

@@ -811,257 +811,44 @@
 ort 
-de.jankrause.javadoctools.domain.Column;%0Aimport de.jankrause.javadoctools.domain.CommentType;%0Aimport de.jankrause.javadoctools.domain.Table;%0Aimport de.jankrause.javadoctools.utils.DbCommentProcessor;%0Aimport org.junit.Test;%0Aimport org.mockito.Mockito
+static org.junit.Assert.assertEquals
 ;%0A%0Ai
@@ -925,39 +925,32 @@
 eption;%0A%0Aimport 
-static 
 org.junit.Assert
@@ -947,960 +947,242 @@
 nit.
-Assert.assertEquals;%0A%0Apublic class FetchDatabaseCommentTest %7B%0A%0A    @Test%0A    public void shouldNotFetchColumnCommentFromAnnotation()throws IOException, SQLException %7B%0A        DbConnector dbConnector = Mockito.mock(DbConnector.class);%0A        Mockito.when(dbConnector.fetchColumnsComment(Mockito.%3CColumn%3Eany())).%0A                thenThrow(new RuntimeException(%22Not yet implemented.%22));%0A%0A        DbCommentProcessor fetcher = new DbCommentProcessor(26, new File(%22src/test/resources/testpackage/AnnotatedEntity.java%22), %22%22, CommentType.FIELD);%0A        assertEquals(%22%3CMISSING COMMENT%3E%22,%0A                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());%0A%0A        fetcher = new DbCommentProcessor(26, new File(%22src/test/resources/testpackage/AnnotatedEntity.java%22), %22%22, CommentType.NONE);%0A        assertEquals(%22%3CMISSING COMMENT%3E%22,%0A                fetcher.applyOnComment(new FetchDatabaseComment().with(dbConnector)).fetch());%0A    %7D
+Test;%0Aimport org.mockito.Mockito;%0A%0Aimport de.jankrause.javadoctools.domain.CommentType;%0Aimport de.jankrause.javadoctools.domain.Table;%0Aimport de.jankrause.javadoctools.utils.DbCommentProcessor;%0A%0Apublic class FetchDatabaseCommentTest %7B
 %0A%0A  

Remove invalid unit-tests