package by.kraskovski.pms.service;

import by.kraskovski.pms.domain.Store;
import by.kraskovski.pms.repository.StoreRepository;
import by.kraskovski.pms.service.impl.StoreServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static by.kraskovski.pms.utils.TestUtils.prepareStore;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class StoreServiceTest {

    @Mock
    private StoreRepository storeRepository;

    @Mock
    private ImageService imageService;

    @InjectMocks
    private StoreServiceImpl storeService;

    @Test
    public void createTest() {
        final Store store = prepareStore();
        when(storeRepository.save((Store) anyObject())).thenReturn(store);

        assertNotEquals(0, storeService.create(new Store()).getId());
        verify(storeRepository).save((Store) anyObject());
    }
}

@@ -396,24 +396,69 @@
 epareStore;%0A
+import static org.junit.Assert.assertEquals;%0A
 import stati
@@ -531,21 +531,18 @@
 hers.any
-Objec
+In
 t;%0Aimpor
@@ -567,21 +567,71 @@
 to.M
-ockito.verify
+atchers.anyObject;%0Aimport static org.mockito.Matchers.anyString
 ;%0Aim
@@ -662,20 +662,17 @@
 Mockito.
-when
+*
 ;%0A%0A@RunW
@@ -954,95 +954,635 @@
     
-final Store store = prepareStore();%0A        when(storeRepository.save((Store) anyObject
+when(storeRepository.save((Store) anyObject())).thenReturn(prepareStore());%0A%0A        assertNotEquals(0, storeService.create(new Store()).getId());%0A        verify(storeRepository).save((Store) anyObject());%0A    %7D%0A%0A    @Test%0A    public void findByIdTest() %7B%0A        final Store store = prepareStore();%0A        when(storeRepository.findOne(anyInt())).thenReturn(store);%0A%0A        assertEquals(store, storeService.find(store.getId()));%0A        verify(storeRepository).findOne(anyInt());%0A    %7D%0A%0A    @Test%0A    public void findByNameTest() %7B%0A        final Store store = prepareStore();%0A        when(storeRepository.findByName(anyString
 ()))
@@ -1612,35 +1612,36 @@
       assert
-Not
 Equals(
-0
+store
 , storeServi
@@ -1643,35 +1643,374 @@
 Service.
-create(new Store())
+findByName(store.getName()));%0A        verify(storeRepository).findByName(anyString());%0A    %7D%0A%0A    @Test%0A    public void deleteStoreWithLogoTest() %7B%0A        final Store store = prepareStore();%0A        when(storeRepository.findOne(anyInt())).thenReturn(store);%0A        when(imageService.delete(anyString())).thenReturn(true);%0A%0A        storeService.delete(store
 .getId()
@@ -2004,32 +2004,33 @@
 store.getId());%0A
+%0A
         verify(s
@@ -2049,32 +2049,575 @@
 ry).
-save((Store) anyObject()
+findOne(store.getId());%0A        verify(imageService).delete(store.getLogo());%0A        verify(storeRepository).delete(store.getId());%0A    %7D%0A%0A    @Test%0A    public void deleteStoreWithoutLogoTest() %7B%0A        final Store store = prepareStore();%0A        store.setLogo(org.apache.commons.lang3.StringUtils.EMPTY);%0A        when(storeRepository.findOne(anyInt())).thenReturn(store);%0A%0A        storeService.delete(store.getId());%0A%0A        verify(storeRepository).findOne(store.getId());%0A        verifyZeroInteractions(imageService);%0A        verify(storeRepository).delete(store
 );%0A 

store service testing finished