package com.bookshop.dry;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.bookshop.domain.Book;
import java.math.BigDecimal;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("DRY -- one authoritative home for the VAT rule, so documents cannot disagree")
class VatDryTest {
@Test
@DisplayName("the knowledge itself has exactly one place and one test")
void vatRuleHasOneHome() {
assertEquals(new BigDecimal("2.00"), Vat.vatOn(new BigDecimal("10.00")));
assertEquals(new BigDecimal("12.00"), Vat.withVat(new BigDecimal("10.00")));
}
@Test
@DisplayName("receipt and invoice agree by construction, not by careful copy-paste")
void documentsCannotDrift() {
List<Book> basket = List.of(
new Book("978-0132350884", "Clean Code", "Robert C. Martin", new BigDecimal("32.50")));
BigDecimal onReceipt = new CustomerReceipt().totalWithVat(basket);
BigDecimal onInvoice = new SupplierInvoice().grandTotal(new BigDecimal("32.50"));
assertEquals(onReceipt, onInvoice);
assertEquals(new BigDecimal("39.00"), onReceipt);
}
}