package com.bookshop.structural.adapter;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.bookshop.domain.Customer;
import java.math.BigDecimal;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("Adapter -- checkout talks pounds and domain objects, the legacy gateway never leaks")
class LegacyGatewayAdapterTest {
private final CardPayments payments = new LegacyGatewayAdapter(new LegacyPaymentGateway());
private final Customer alice = new Customer("42", "Alice", "alice@example.com", 0);
@Test
@DisplayName("a clean domain call is translated into the gateway's reference-and-pence API")
void successfulChargeIsTranslated() {
PaymentResult result = payments.charge(alice, new BigDecimal("19.99"));
assertTrue(result.successful());
}
@Test
@DisplayName("magic status codes come back as meaningful domain results")
void statusCodesBecomeMeaningfulResults() {
PaymentResult result = payments.charge(alice, new BigDecimal("2000.00"));
assertFalse(result.successful());
assertEquals("insufficient funds", result.message());
}
}