package com.hida.service;

import com.hida.model.Citation;
import com.hida.repositories.CitationRepository;
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 CitationRepository CitationRepo;

    @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(CitationRepo.findOne(any(String.class))).thenReturn(entity);

        Service.retrieveUrl("");

        verify(CitationRepo, atLeastOnce()).findOne(any(String.class));
    }

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

        Service.editUrl("", "");
        verify(CitationRepo, atLeastOnce()).findOne(any(String.class));
    }

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

        Service.deleteCitation("");
        verify(CitationRepo, atLeastOnce()).delete(any(Citation.class));
    }

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

        verify(CitationRepo, atLeastOnce()).findOne(any(String.class));
    }

    /**
     * Tests to see if a Citation object can be persisted
     */
    @Test
    public void testInsertCitation() {
        Citation purl = new Citation();
        when(CitationRepo.save(purl)).thenReturn(null);
        

        Service.insertCitation(purl);
        verify(CitationRepo, atLeastOnce()).save(any(Citation.class));
    }

}

@@ -101,16 +101,41 @@
 sitory;%0A
+import org.junit.Assert;%0A
 import o
@@ -1096,32 +1096,90 @@
 RetrieveUrl() %7B%0A
+        String purl = %22purl%22;%0A        String url = %22url%22;%0A
         Citation
@@ -1193,32 +1193,36 @@
  = new Citation(
+purl
 );%0A        entit
@@ -1230,18 +1230,19 @@
 .setUrl(
-%22%22
+url
 );%0A     
@@ -1270,33 +1270,20 @@
 findOne(
-any(String.class)
+purl
 )).thenR
@@ -1297,32 +1297,51 @@
 ntity);%0A%0A       
+ String entityUrl =
  Service.retriev
@@ -1345,18 +1345,20 @@
 ieveUrl(
-%22%22
+purl
 );%0A%0A    
@@ -1405,35 +1405,76 @@
 findOne(
-any(String.class));
+purl);%0A        Assert.assertEquals(url, entityUrl);%0A        
 %0A    %7D%0A%0A
@@ -1695,32 +1695,66 @@
 eturn(entity);%0A%0A
+        String newUrl = %22newUrl%22;%0A
         Service.
@@ -1766,13 +1766,21 @@
 rl(%22
-%22, %22%22
+purl%22, newUrl
 );%0A 
@@ -1842,32 +1842,86 @@
 String.class));%0A
+        Assert.assertEquals(newUrl, entity.getUrl());%0A
     %7D%0A%0A    /**%0A 
@@ -2434,13 +2434,16 @@
 ieve
-Model
+Citation
 () %7B
@@ -2452,38 +2452,40 @@
        Citation 
-entity
+citation
  = new Citation(
@@ -2499,75 +2499,206 @@
     
-when(CitationRepo.findOne(any(String.class))).thenReturn(entity
+String purl = %22purl%22;%0A        citation.setPurl(purl);%0A        %0A        when(CitationRepo.findOne(any(String.class))).thenReturn(citation);%0A%0A        Citation entity = Service.retrieveCitation(purl
 );%0A
-%0A
     
@@ -2757,32 +2757,79 @@
 String.class));%0A
+        Assert.assertEquals(citation, entity);%0A
     %7D%0A%0A    /**%0A 
@@ -3037,25 +3037,16 @@
 n(null);
-%0A        
 %0A%0A      

Improve ResolverServiceTest test cases