package org.synyx.urlaubsverwaltung.application.specialleave;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class SpecialLeaveSettingsItemServiceTest {

    @Mock
    private SpecialLeaveSettingsRepository specialLeaveSettingsRepository;
    @Captor
    private ArgumentCaptor<SpecialLeaveSettingsEntity> specialLeaveSettingsEntity;
    private SpecialLeaveSettingsService specialLeaveSettingsService;

    @BeforeEach
    void setUp() {
        specialLeaveSettingsService = new SpecialLeaveSettingsService(specialLeaveSettingsRepository);
    }

    @Test
    void save() {
        SpecialLeaveSettingsItem specialLeaveSettings = new SpecialLeaveSettingsItem(1,true, "message.key", 5);

        specialLeaveSettingsService.saveAll(List.of(specialLeaveSettings));

        verify(specialLeaveSettingsRepository).save(this.specialLeaveSettingsEntity.capture());
        assertThat(specialLeaveSettings).usingRecursiveComparison().isEqualTo(this.specialLeaveSettingsEntity.getValue());
    }

    @Test
    void getSpecialLeaveSettings() {
        final SpecialLeaveSettingsEntity specialLeaveSettingsEntity = new SpecialLeaveSettingsEntity();
        when(specialLeaveSettingsRepository.findAll()).thenReturn(List.of(specialLeaveSettingsEntity));
        final List<SpecialLeaveSettingsItem> specialLeaveSettings = specialLeaveSettingsService.getSpecialLeaveSettings();
        assertThat(specialLeaveSettings).isNotEmpty();
        assertThat(specialLeaveSettingsEntity).usingRecursiveComparison().isEqualTo(specialLeaveSettings);
    }

    @Test
    void getSpecialLeaveSettingsReturnsEmpty() {
        when(specialLeaveSettingsRepository.findAll()).thenReturn(Collections.emptyList());
        final List<SpecialLeaveSettingsItem> specialLeaveSettings = specialLeaveSettingsService.getSpecialLeaveSettings();
        assertThat(specialLeaveSettings).isEmpty();
    }
}

@@ -60,60 +60,8 @@
 e;%0A%0A
-import com.fasterxml.jackson.databind.ObjectMapper;%0A
 impo
@@ -722,16 +722,21 @@
 tCaptor%3C
+List%3C
 SpecialL
@@ -754,16 +754,17 @@
 sEntity%3E
+%3E
  special
@@ -782,16 +782,20 @@
 gsEntity
+List
 ;%0A    pr
@@ -1043,113 +1043,465 @@
     
-SpecialLeaveSettingsItem specialLeaveSettings = new SpecialLeaveSettingsItem(1,true, %22message.key%22, 5
+final SpecialLeaveSettingsEntity specialLeaveSettingsEntity = new SpecialLeaveSettingsEntity();%0A        specialLeaveSettingsEntity.setId(1);%0A        when(specialLeaveSettingsRepository.findAll()).thenReturn(List.of(specialLeaveSettingsEntity));%0A%0A        SpecialLeaveSettingsItem specialLeaveSettings = new SpecialLeaveSettingsItem(1,true, %22foo%22, 5);%0A        final List%3CSpecialLeaveSettingsItem%3E specialLeaveSettingsItemList = List.of(specialLeaveSettings
 );%0A
-%0A
     
@@ -1540,24 +1540,16 @@
 saveAll(
-List.of(
 specialL
@@ -1560,17 +1560,24 @@
 Settings
-)
+ItemList
 );%0A%0A    
@@ -1623,16 +1623,19 @@
 ry).save
+All
 (this.sp
@@ -1658,16 +1658,20 @@
 gsEntity
+List
 .capture
@@ -1687,67 +1687,331 @@
     
-assertThat(specialLeaveSettings).usingRecursiveComparison()
+final List%3CSpecialLeaveSettingsEntity%3E leaveSettingsEntityListValue = this.specialLeaveSettingsEntityList.getValue();%0A        assertThat(leaveSettingsEntityListValue).hasSize(1);%0A%0A        assertThat(leaveSettingsEntityListValue)%0A            .usingRecursiveComparison()%0A            .ignoringFields(%22messageKey%22)%0A            
 .isE
@@ -2017,21 +2017,16 @@
 EqualTo(
-this.
 specialL
@@ -2041,25 +2041,16 @@
 ings
-Entity.getValue()
+ItemList
 );%0A 
@@ -2306,24 +2306,25 @@
 gsEntity));%0A
+%0A
         fina
@@ -2426,32 +2426,33 @@
 eaveSettings();%0A
+%0A
         assertTh
@@ -2480,19 +2480,17 @@
 gs).
-isNotEmpty(
+hasSize(1
 );%0A 
@@ -2588,24 +2588,31 @@
 eaveSettings
+.get(0)
 );%0A    %7D%0A%0A  

fix SpecialLeaveSettingsItemServiceTest