Abrufen der PRodukte der AmazonAPI
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package de.rwu.easydrop.api;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AmazonPriceFetcherTest {
|
||||
private static final String BASE_URL = "https://api.amazon.com";
|
||||
private static final String API_KEY = "your_api_key";
|
||||
private static final String PRODUCT_ID = "12345";
|
||||
|
||||
private AmazonPriceFetcher priceFetcher;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
priceFetcher = new AmazonPriceFetcher(BASE_URL, API_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProductPrice_ValidProductId_ReturnsPrice() throws MalformedURLException {
|
||||
// Arrange
|
||||
double expectedPrice = -1.0;
|
||||
|
||||
// Act
|
||||
double actualPrice = priceFetcher.getProductPrice(PRODUCT_ID);
|
||||
|
||||
// Assert
|
||||
Assertions.assertEquals(expectedPrice, actualPrice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProductPrice_InvalidProductId_ReturnsNegativePrice() throws MalformedURLException {
|
||||
// Arrange
|
||||
double expectedPrice = -1.0;
|
||||
|
||||
// Act
|
||||
double actualPrice = priceFetcher.getProductPrice("invalid_product_id");
|
||||
|
||||
// Assert
|
||||
Assertions.assertEquals(expectedPrice, actualPrice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProductPrice_ExceptionThrown_ReturnsNegativePrice() throws MalformedURLException {
|
||||
// Arrange
|
||||
double expectedPrice = -1.0;
|
||||
|
||||
// Act
|
||||
double actualPrice = priceFetcher.getProductPrice("exception_thrown");
|
||||
|
||||
// Assert
|
||||
Assertions.assertEquals(expectedPrice, actualPrice);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user