created test class "OfferRetrieverTest"
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package de.rwu.easydrop.service.retriever;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import de.rwu.easydrop.api.client.AmazonProductDataSource;
|
||||
import de.rwu.easydrop.api.client.DataSourceFactory;
|
||||
import de.rwu.easydrop.api.client.EbayItemDataSource;
|
||||
import de.rwu.easydrop.api.dto.OfferDTO;
|
||||
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.util.Config;
|
||||
|
||||
|
||||
|
||||
|
||||
class OfferRetrieverTest {
|
||||
|
||||
@Mock
|
||||
private Config config;
|
||||
@Mock
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
@Mock
|
||||
private AmazonProductDataSource amazonDataSource;
|
||||
@Mock
|
||||
private EbayItemDataSource ebayDataSource;
|
||||
@Mock
|
||||
private OfferDTO offerDTO;
|
||||
@Mock
|
||||
private Offer offer;
|
||||
@Mock
|
||||
private OfferPersistenceInterface persistence;
|
||||
|
||||
private OfferRetriever offerRetriever;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws ConfigurationException {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
when(config.getProperty("AMAZON_API_URL")).thenReturn("https://api.amazon.com");
|
||||
when(config.getProperty("AMAZON_API_KEY")).thenReturn("amazon-api-key");
|
||||
dataSourceFactory.setConfig(config);
|
||||
offerRetriever = new OfferRetriever(persistence);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOfferFromPersistence(){
|
||||
//Arrange
|
||||
String offerId = "187";
|
||||
String lastUpdate = "2023-01-01";
|
||||
when(persistence.getOfferDTOById(offerId)).thenReturn(offerDTO);
|
||||
when(offerDTO.getOfferId()).thenReturn(offerId);
|
||||
when(offerDTO.getLastUpdate()).thenReturn(lastUpdate);
|
||||
|
||||
//Act
|
||||
Offer result = offerRetriever.getOfferFromPersistence(offerId);
|
||||
|
||||
//Assert
|
||||
assertEquals(offerId, result.getOfferId());
|
||||
assertEquals(lastUpdate, result.getLastUpdate());
|
||||
|
||||
//Verify
|
||||
verify(persistence, times(1)).getOfferDTOById(offerId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user