package com.hida.service;

import com.hida.repositories.CitationDao;
import com.hida.model.Citation;
import org.mockito.InjectMocks;
import static org.mockito.Matchers.any;
import org.mockito.Mock;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;

/**
 * This class tests the functionality of MinterServiceImpl using Mockito.
 *
 * @author lruffin
 */
public class ResolverServiceImplTest {

    @Mock
    private CitationDao Dao;

    @InjectMocks
    private ResolverServiceImpl Service;

    /**
     * Sets up Mockito
     *
     * @throws Exception
     */
    @BeforeClass
    public void setUpClass() throws Exception {
        MockitoAnnotations.initMocks(this);
    }

    /**
     * Tests to see if the URL of a given Citation entity is properly retrieved
     */
    @Test
    public void testRetrieveUrl() {
        Citation entity = new Citation();
        entity.setUrl("");
        when(Dao.findByPurl(any(String.class))).thenReturn(entity);

        Service.retrieveUrl("");

        verify(Dao, atLeastOnce()).findByPurl(any(String.class));
    }

    /**
     * Tests to see if a Citation entity can be edited
     */
    @Test
    public void testEditUrl() {
        Citation entity = new Citation();
        when(Dao.findByPurl(any(String.class))).thenReturn(entity);

        Service.editUrl("", "");
        verify(Dao, atLeastOnce()).findByPurl(any(String.class));
    }

    /**
     * Tests to see if a Citation entity can be deleted
     */
    @Test
    public void testDeleteCitation() {
        Citation entity = new Citation();
        when(Dao.findByPurl(any(String.class))).thenReturn(entity);
        doNothing().when(Dao).deletePurl(entity);

        Service.deleteCitation("");
        verify(Dao, atLeastOnce()).deletePurl(any(Citation.class));
    }

    /**
     * Tests to see if a Citation entity is retrievable
     */
    @Test
    public void testRetrieveModel() {
        Citation entity = new Citation();
        when(Dao.findByPurl(any(String.class))).thenReturn(entity);

        verify(Dao, atLeastOnce()).findByPurl(any(String.class));
    }

    /**
     * Tests to see if a Citation object can be persisted
     */
    @Test
    public void testInsertCitation() {
        Citation purl = new Citation();
        doNothing().when(Dao).savePurl(purl);

        Service.insertCitation(purl);
        verify(Dao, atLeastOnce()).savePurl(any(Citation.class));
    }

}

@@ -40,20 +40,13 @@
 ida.
-repositories
+model
 .Cit
@@ -50,19 +50,16 @@
 Citation
-Dao
 ;%0Aimport
@@ -64,38 +64,55 @@
 rt com.hida.
-model.Citation
+repositories.CitationRepository
 ;%0Aimport org
@@ -669,14 +669,30 @@
 tion
-Dao Da
+Repository CitationRep
 o;%0A%0A
@@ -1157,38 +1157,44 @@
        when(
-Dao.findByPurl
+CitationRepo.findOne
 (any(String.
@@ -1264,34 +1264,43 @@
 %0A        verify(
-Da
+CitationRep
 o, atLeastOnce()
@@ -1297,38 +1297,35 @@
 eastOnce()).find
-ByPurl
+One
 (any(String.clas
@@ -1500,38 +1500,44 @@
        when(
-Dao.findByPurl
+CitationRepo.findOne
 (any(String.
@@ -1606,34 +1606,43 @@
 %0A        verify(
-Da
+CitationRep
 o, atLeastOnce()
@@ -1639,38 +1639,35 @@
 eastOnce()).find
-ByPurl
+One
 (any(String.clas
@@ -1850,38 +1850,44 @@
        when(
-Dao.findByPurl
+CitationRepo.findOne
 (any(String.
@@ -1940,18 +1940,27 @@
 ().when(
-Da
+CitationRep
 o).delet
@@ -1960,20 +1960,16 @@
 ).delete
-Purl
 (entity)
@@ -2014,34 +2014,43 @@
 %0A        verify(
-Da
+CitationRep
 o, atLeastOnce()
@@ -2057,20 +2057,16 @@
 ).delete
-Purl
 (any(Cit
@@ -2266,22 +2266,28 @@
 hen(
-Dao.findByPurl
+CitationRepo.findOne
 (any
@@ -2331,34 +2331,43 @@
 %0A        verify(
-Da
+CitationRep
 o, atLeastOnce()
@@ -2376,14 +2376,11 @@
 find
-ByPurl
+One
 (any
@@ -2595,21 +2595,26 @@
 hen(
-Da
+CitationRep
 o).save
-Purl
 (pur
@@ -2675,10 +2675,19 @@
 ify(
-Da
+CitationRep
 o, a
@@ -2708,12 +2708,8 @@
 save
-Purl
 (any

Replace CitationDaoImpl with CitationRepository