Skip to content

Commit

Permalink
Re-add the Transaction.name property to the Transaction record type
Browse files Browse the repository at this point in the history
The property was lost when transforming Transaction from bean to record.
  • Loading branch information
steinarb committed Sep 29, 2024
1 parent 3c5133f commit f9d89e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package no.priv.bang.ukelonn.beans;

import java.util.Date;
import static java.util.Optional.*;

public record Transaction(
int id,
Expand All @@ -24,6 +25,9 @@ public record Transaction(
double transactionAmount,
boolean paidOut)
{
public String getName() {
return ofNullable(transactionType).map(TransactionType::transactionTypeName).orElse(null);
}

public static Builder with(Transaction transaction) {
Builder builder = new Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void testNoArgConstructor() {
var bean = Transaction.with().build();
assertEquals(-1, bean.id());
assertNull(bean.transactionType());
assertNull(bean.getName());
assertNull(bean.transactionTime());
assertEquals(0.0, bean.transactionAmount(), 0.0);
assertFalse(bean.paidOut());
Expand All @@ -34,7 +35,7 @@ void testNoArgConstructor() {
@Test
void testConstructorWithArgs() {
var id = 5;
var transactionType = TransactionType.with().build();
var transactionType = TransactionType.with().transactionTypeName("Paid to account").build();
var transactionTime = new Date();
var transactionAmount = 100.0;
var paidOut = true;
Expand All @@ -46,6 +47,7 @@ void testConstructorWithArgs() {
.paidOut(paidOut)
.build();
assertEquals(id, bean.id());
assertEquals(transactionType.transactionTypeName(), bean.getName());
assertEquals(transactionType, bean.transactionType());
assertEquals(transactionTime, bean.transactionTime());
assertEquals(transactionAmount, bean.transactionAmount(), 0.0);
Expand Down

0 comments on commit f9d89e0

Please sign in to comment.