diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/model/PaymentInformation.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/model/PaymentInformation.java new file mode 100644 index 00000000..b85fc801 --- /dev/null +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/model/PaymentInformation.java @@ -0,0 +1,19 @@ +package de.cotto.lndmanagej.pickhardtpayments.model; + +import de.cotto.lndmanagej.model.Coins; + +public record PaymentInformation(Coins inFlight, boolean settled, boolean failed) { + public static final PaymentInformation DEFAULT = new PaymentInformation(Coins.NONE, false, false); + + public PaymentInformation withAdditionalInFlight(Coins amount) { + return new PaymentInformation(inFlight.add(amount), settled, failed); + } + + public PaymentInformation withIsSettled() { + return new PaymentInformation(inFlight, true, failed); + } + + public PaymentInformation withIsFailed() { + return new PaymentInformation(inFlight, settled, true); + } +} diff --git a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/model/PaymentInformationTest.java b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/model/PaymentInformationTest.java new file mode 100644 index 00000000..83466d21 --- /dev/null +++ b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/model/PaymentInformationTest.java @@ -0,0 +1,49 @@ +package de.cotto.lndmanagej.pickhardtpayments.model; + +import de.cotto.lndmanagej.model.Coins; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class PaymentInformationTest { + private static final PaymentInformation PAYMENT_INFORMATION = + new PaymentInformation(Coins.ofSatoshis(123), false, false); + + @Test + void inFlight() { + assertThat(PAYMENT_INFORMATION.inFlight()).isEqualTo(Coins.ofSatoshis(123)); + } + + @Test + void settled() { + assertThat(PAYMENT_INFORMATION.settled()).isFalse(); + } + + @Test + void failed() { + assertThat(PAYMENT_INFORMATION.failed()).isFalse(); + } + + @Test + void withAdditionalInFlight() { + assertThat(PAYMENT_INFORMATION.withAdditionalInFlight(Coins.ofSatoshis(77))) + .isEqualTo(new PaymentInformation(Coins.ofSatoshis(200), false, false)); + } + + @Test + void withIsSettled() { + assertThat(PAYMENT_INFORMATION.withIsSettled()) + .isEqualTo(new PaymentInformation(Coins.ofSatoshis(123), true, false)); + } + + @Test + void withIsFailed() { + assertThat(PAYMENT_INFORMATION.withIsFailed()) + .isEqualTo(new PaymentInformation(Coins.ofSatoshis(123), false, true)); + } + + @Test + void default_values() { + assertThat(PaymentInformation.DEFAULT).isEqualTo(new PaymentInformation(Coins.NONE, false, false)); + } +}