generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PRDP-254] added Cosmos service unit test
- Loading branch information
giomella
committed
Nov 30, 2023
1 parent
6f1d0a5
commit ca4bcdd
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...st/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package it.gov.pagopa.receipt.pdf.helpdesk.service.impl; | ||
|
||
import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; | ||
import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; | ||
import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; | ||
import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ReceiptCosmosServiceImplTest { | ||
|
||
private ReceiptCosmosClient receiptCosmosClientMock; | ||
|
||
private ReceiptCosmosService sut; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
receiptCosmosClientMock = mock(ReceiptCosmosClient.class); | ||
|
||
sut = spy(new ReceiptCosmosServiceImpl(receiptCosmosClientMock)); | ||
} | ||
|
||
@Test | ||
void getReceiptSuccess() throws ReceiptNotFoundException { | ||
when(receiptCosmosClientMock.getReceiptDocument(anyString())).thenReturn(new Receipt()); | ||
|
||
Receipt receipt = assertDoesNotThrow(() -> sut.getReceipt(anyString())); | ||
|
||
assertNotNull(receipt); | ||
} | ||
|
||
@Test | ||
void getReceiptFailClientThrowsReceiptNotFound() throws ReceiptNotFoundException { | ||
when(receiptCosmosClientMock.getReceiptDocument(anyString())).thenThrow(ReceiptNotFoundException.class); | ||
|
||
assertThrows(ReceiptNotFoundException.class, () -> sut.getReceipt(anyString())); | ||
} | ||
|
||
@Test | ||
void getReceiptFailClientReturnNull() throws ReceiptNotFoundException { | ||
when(receiptCosmosClientMock.getReceiptDocument(anyString())).thenReturn(null); | ||
|
||
assertThrows(ReceiptNotFoundException.class, () -> sut.getReceipt(anyString())); | ||
} | ||
} |