78 lines
2.4 KiB
Java
78 lines
2.4 KiB
Java
package de.rwu.easydrop.api.client;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.MockitoAnnotations;
|
|
|
|
class EbayPurchaserTest {
|
|
private EbayPurchaser demoPurchaser;
|
|
|
|
private static String demoApiKey = "my-api-key";
|
|
private static String demoApiUrl = "https://www.example.com/api";
|
|
private static String demoDataTarget = "eBay";
|
|
|
|
@BeforeEach
|
|
void setup() {
|
|
demoPurchaser = new EbayPurchaser(
|
|
demoApiUrl,
|
|
demoApiKey);
|
|
MockitoAnnotations.openMocks(this);
|
|
}
|
|
|
|
@Test
|
|
void testConstructor() {
|
|
// Assert
|
|
try {
|
|
Field baseUrlField = EbayPurchaser.class.getDeclaredField("baseUrl");
|
|
baseUrlField.setAccessible(true);
|
|
Assertions.assertEquals(demoApiUrl, baseUrlField.get(demoPurchaser));
|
|
|
|
Field apiKeyField = EbayPurchaser.class.getDeclaredField("apiKey");
|
|
apiKeyField.setAccessible(true);
|
|
Assertions.assertEquals(demoApiKey, apiKeyField.get(demoPurchaser));
|
|
} catch (NoSuchFieldException e) {
|
|
Assertions.fail();
|
|
} catch (IllegalAccessException e) {
|
|
Assertions.fail();
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void testCreateApiUrl() throws MalformedURLException {
|
|
// Test case 1
|
|
String productId1 = "12345";
|
|
URL expectedUrl1 = new URL(
|
|
"https://www.example.com/api/buy/"
|
|
+ productId1);
|
|
URL createdUrl1 = demoPurchaser.createApiUrl(productId1);
|
|
Assertions.assertEquals(expectedUrl1, createdUrl1);
|
|
|
|
// Test case 2
|
|
String productId2 = "67890";
|
|
URL expectedUrl2 = new URL(
|
|
"https://www.example.com/api/buy/"
|
|
+ productId2);
|
|
URL createdUrl2 = demoPurchaser.createApiUrl(productId2);
|
|
Assertions.assertEquals(expectedUrl2, createdUrl2);
|
|
}
|
|
|
|
@Test
|
|
void getDataTarget_ReturnsExpectedDataOrigin() {
|
|
String dataTarget = demoPurchaser.getDataTarget();
|
|
assertEquals(demoDataTarget, dataTarget);
|
|
}
|
|
|
|
@Test
|
|
void getApiKey_ReturnsExpectedApiKey() {
|
|
String apiKey = demoPurchaser.getApiKey();
|
|
assertEquals(demoApiKey, apiKey);
|
|
}
|
|
}
|