package cz.muni.fi.pa165.methanolmanager.service;

import cz.muni.fi.pa165.methanolmanager.dal.domain.Bottle;
import cz.muni.fi.pa165.methanolmanager.dal.repository.BottleRepository;
import cz.muni.fi.pa165.methanolmanager.service.dto.BottleDto;
import cz.muni.fi.pa165.methanolmanager.service.exception.EntityNotFoundException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.dao.EmptyResultDataAccessException;

import javax.inject.Inject;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

/**
 * @author Pavel Vomacka
 */
public class BottleServiceTest extends ServiceTest {
    public static final int BOTTLE_ID = 1;
    public static final int INVALID_BOTTLE_ID = 2;
    public static final String BOTTLE_NAME = "Tuzemsky";

    @Inject
    BottleRepository bottleRepository;

    @Inject
    BottleService bottleService;

    @Before
    public void setup() {
        Bottle bottle = new Bottle();
        bottle.setName(BOTTLE_NAME);

        when(bottleRepository.findOne(BOTTLE_ID)).thenReturn(bottle);
        doThrow(EmptyResultDataAccessException.class).when(bottleRepository).delete(INVALID_BOTTLE_ID);
    }

    @Test
    public void testCreateBottle() {
        BottleDto bottleDto = new BottleDto();
        bottleDto.setName(BOTTLE_NAME);

        bottleService.createBottle(bottleDto);

        ArgumentCaptor<Bottle> captor = ArgumentCaptor.forClass(Bottle.class);
        verify(bottleRepository).save(captor.capture());

        assertEquals(captor.getValue().getName(), BOTTLE_NAME);
    }

    @Test
    public void testStampBottle() {
        bottleService.stampBottle(BOTTLE_ID);

        assertTrue(bottleRepository.findOne(BOTTLE_ID).isStamped());
    }

    @Test(expected = EntityNotFoundException.class)
    public void testStampBottle_NotFound() {
        bottleService.stampBottle(INVALID_BOTTLE_ID);
    }

    @Test
    public void testDeleteBottle() {
        bottleService.deleteBottle(BOTTLE_ID);

        verify(bottleRepository).delete(BOTTLE_ID);
    }

    @Test(expected = EntityNotFoundException.class)
    public void testDeleteBottle_NotFound() {
        bottleService.deleteBottle(INVALID_BOTTLE_ID);
    }
}

@@ -55,578 +55,708 @@
 ort 
-cz.muni.fi.pa165.methanolmanager.dal.domain.Bottle;%0Aimport cz.muni.fi.pa165.methanolmanager.dal.repository.BottleRepository;%0Aimport cz.muni.fi.pa165.methanolmanager.service.dto.BottleDto;%0Aimport cz.muni.fi.pa165.methanolmanager.service.exception.EntityNotFoundException;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.mockito.ArgumentCaptor;%0Aimport org.springframework.dao.EmptyResultDataAccessException;%0A%0Aimport javax.inject.Inject;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.mockito.Mockito.*
+static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.mockito.Mockito.doThrow;%0Aimport static org.mockito.Mockito.reset;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport javax.inject.Inject;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.mockito.ArgumentCaptor;%0Aimport org.springframework.dao.EmptyResultDataAccessException;%0A%0Aimport cz.muni.fi.pa165.methanolmanager.dal.domain.Bottle;%0Aimport cz.muni.fi.pa165.methanolmanager.dal.repository.BottleRepository;%0Aimport cz.muni.fi.pa165.methanolmanager.service.dto.BottleDto;%0Aimport cz.muni.fi.pa165.methanolmanager.service.exception.EntityNotFoundException
 ;%0A%0A/
@@ -1196,32 +1196,182 @@
 (BOTTLE_NAME);%0A%0A
+        // reset bottle repository mock before each test%0A        // in order to reset the argument captor call count%0A        reset(bottleRepository);%0A
         when(bot

Fix BottleServiceTest#testCreateBottle