Untitled
unknown
plain_text
3 years ago
2.9 kB
8
Indexable
package br.com.senior.erpxcomfat.saleinvoice.service.impl;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import br.com.senior.erpxcomfat.saleinvoice.E140nfsEntity;
import br.com.senior.erpxcomfat.saleinvoice.EnumSitNfs;
import br.com.senior.erpxcomfat.saleinvoice.EnumTipNfs;
import br.com.senior.erpxcomfat.saleinvoice.repository.E140nfsRepository;
import br.com.senior.erpxcomfat.saleinvoice.service.CloneSaleInvoiceService;
import br.com.senior.erpxcomfat.saleinvoice.service.FiscalDocumentIssuanceService;
import br.com.senior.erpxcomfat.saleinvoice.service.RecalculateInstallmentsService;
import br.com.senior.erpxcomfat.saleinvoice.service.impl.CloneSaleInvoiceServiceImpl;
@RunWith(MockitoJUnitRunner.class)
public class CloneSaleInvoiceServiceImplTest {
@Mock
private E140nfsRepository saleInvoiceRepository;
@Mock
private FiscalDocumentIssuanceService fiscalDocumentIssuanceService;
@Mock
private RecalculateInstallmentsService recalculateInstallmentsService;
@Mock
private CloneSaleInvoiceService cloneSaleInvoiceService;
@InjectMocks
private CloneSaleInvoiceServiceImpl cloneSaleInvoiceServiceImpl;
private UUID id;
private E140nfsEntity saleInvoiceOrigin;
@Before
public void setUp() {
this.id = UUID.randomUUID();
this.saleInvoiceOrigin = new E140nfsEntity();
this.saleInvoiceOrigin.setId(id);
}
@Test
public void shouldCloneSaleInvoiceWithNewValuesAndUpdate() {
// given
E140nfsEntity expectedSaleInvoice = new E140nfsEntity();
expectedSaleInvoice.setId(UUID.randomUUID());
when(saleInvoiceRepository.saveAndFlush(any(E140nfsEntity.class))).thenReturn(expectedSaleInvoice);
// when
E140nfsEntity actualSaleInvoice = cloneSaleInvoiceServiceImpl.clone(saleInvoiceOrigin, true, EnumTipNfs.V20, EnumSitNfs.NORMAL, new HashMap<>());
// then
verify(saleInvoiceRepository).saveAndFlush(any(E140nfsEntity.class));
}
@Test
public void shouldCloneSaleInvoiceWithoutCopyingData() {
// given
E140nfsEntity expectedSaleInvoice = new E140nfsEntity();
expectedSaleInvoice.setId(UUID.randomUUID());
when(saleInvoiceRepository.saveAndFlush(any(E140nfsEntity.class))).thenReturn(expectedSaleInvoice);
// when
E140nfsEntity actualSaleInvoice = cloneSaleInvoiceServiceImpl.clone(saleInvoiceOrigin, false, EnumTipNfs.V20, EnumSitNfs.NORMAL, new HashMap<>());
// then
verify(saleInvoiceRepository).saveAndFlush(any(E140nfsEntity.class));
verifyZeroInteractions(recalculateInstallmentsService, fiscalDocumentIssuanceService);
}
}Editor is loading...