mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 15:04:22 +01:00
add PaymentInformation to track pending payments
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user