package com.intrasoft.ermis.transit.cargoofficeofdestination.core.service;

import com.intrasoft.ermis.transit.cargoofficeofdestination.domain.ProcessingStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ProcessingStatusServiceImpl implements ProcessingStatusService{

    private final DossierDataService dossierDataService;

    @Override
    public void saveProcessingStatus(String movementId, String status) {
        dossierDataService.saveProcessingStatus(createProcessingStatus(movementId, status));
    }

    private ProcessingStatus createProcessingStatus(String movementId, String status) {

        ProcessingStatus processingStatus = new ProcessingStatus();
        processingStatus.setStatus(status);
        processingStatus.setMovementId(movementId);

        return processingStatus;
    }
}

package com.intrasoft.ermis.transit.cargoofficeofdestination.test.service;

import static org.mockito.Mockito.verify;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.intrasoft.ermis.transit.cargoofficeofdestination.core.service.DossierDataService;
import com.intrasoft.ermis.transit.cargoofficeofdestination.core.service.ProcessingStatusServiceImpl;
import com.intrasoft.ermis.transit.cargoofficeofdestination.domain.ProcessingStatus;
import com.intrasoft.ermis.transit.common.enums.ProcessingStatusTypeEnum;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class ProcessingStatusServiceUT {

    private static final String MOVEMENT_ID = "TEST_MOVEMENT_ID";

    @Mock
    private DossierDataService dossierDataService;

    @InjectMocks
    private ProcessingStatusServiceImpl processingStatusService;

    @Captor
    private ArgumentCaptor<ProcessingStatus> processingStatusArgumentCaptor;

    @Test
    @DisplayName("Test - Save Processing Status")
    void testSaveProcessingStatus() {
        // Call ProcessingStatusService method:
        processingStatusService.saveProcessingStatus(MOVEMENT_ID, ProcessingStatusTypeEnum.CARGO_OODEST_WRITTEN_OFF.getItemCode());
        // Verification & Assertions:
        verify(dossierDataService).saveProcessingStatus(processingStatusArgumentCaptor.capture());
        assertEquals(MOVEMENT_ID, processingStatusArgumentCaptor.getValue().getMovementId());
        assertEquals(ProcessingStatusTypeEnum.CARGO_OODEST_WRITTEN_OFF.getItemCode(), processingStatusArgumentCaptor.getValue().getStatus());
    }

}
