fix toString+toShortString for empty CoopAssetTransaction+CoopShareTransaction + test
This commit is contained in:
parent
0926dacd77
commit
5f72025d86
@ -29,7 +29,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
|||||||
public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, HasUuid {
|
public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, HasUuid {
|
||||||
|
|
||||||
private static Stringify<HsOfficeCoopAssetsTransactionEntity> stringify = stringify(HsOfficeCoopAssetsTransactionEntity.class)
|
private static Stringify<HsOfficeCoopAssetsTransactionEntity> stringify = stringify(HsOfficeCoopAssetsTransactionEntity.class)
|
||||||
.withProp(e -> ofNullable(e.getMembership()).map(HsOfficeMembershipEntity::getMemberNumber).orElse(null))
|
.withProp(HsOfficeCoopAssetsTransactionEntity::getMemberNumber)
|
||||||
.withProp(HsOfficeCoopAssetsTransactionEntity::getValueDate)
|
.withProp(HsOfficeCoopAssetsTransactionEntity::getValueDate)
|
||||||
.withProp(HsOfficeCoopAssetsTransactionEntity::getTransactionType)
|
.withProp(HsOfficeCoopAssetsTransactionEntity::getTransactionType)
|
||||||
.withProp(HsOfficeCoopAssetsTransactionEntity::getAssetValue)
|
.withProp(HsOfficeCoopAssetsTransactionEntity::getAssetValue)
|
||||||
@ -63,6 +63,11 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, HasUu
|
|||||||
@Column(name = "comment")
|
@Column(name = "comment")
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
|
|
||||||
|
public Integer getMemberNumber() {
|
||||||
|
return ofNullable(membership).map(HsOfficeMembershipEntity::getMemberNumber).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return stringify.apply(this);
|
return stringify.apply(this);
|
||||||
@ -70,6 +75,6 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, HasUu
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toShortString() {
|
public String toShortString() {
|
||||||
return membership.getMemberNumber() + new DecimalFormat("+0.00").format(assetValue);
|
return "%s%+1.2f".formatted(getMemberNumber(), assetValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import jakarta.persistence.*;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static java.util.Optional.ofNullable;
|
||||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -24,7 +25,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
|||||||
public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, HasUuid {
|
public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, HasUuid {
|
||||||
|
|
||||||
private static Stringify<HsOfficeCoopSharesTransactionEntity> stringify = stringify(HsOfficeCoopSharesTransactionEntity.class)
|
private static Stringify<HsOfficeCoopSharesTransactionEntity> stringify = stringify(HsOfficeCoopSharesTransactionEntity.class)
|
||||||
.withProp(e -> e.getMembership().getMemberNumber())
|
.withProp(HsOfficeCoopSharesTransactionEntity::getMemberNumber)
|
||||||
.withProp(HsOfficeCoopSharesTransactionEntity::getValueDate)
|
.withProp(HsOfficeCoopSharesTransactionEntity::getValueDate)
|
||||||
.withProp(HsOfficeCoopSharesTransactionEntity::getTransactionType)
|
.withProp(HsOfficeCoopSharesTransactionEntity::getTransactionType)
|
||||||
.withProp(HsOfficeCoopSharesTransactionEntity::getShareCount)
|
.withProp(HsOfficeCoopSharesTransactionEntity::getShareCount)
|
||||||
@ -62,8 +63,12 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, HasUu
|
|||||||
return stringify.apply(this);
|
return stringify.apply(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getMemberNumber() {
|
||||||
|
return ofNullable(membership).map(HsOfficeMembershipEntity::getMemberNumber).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toShortString() {
|
public String toShortString() {
|
||||||
return "%s%+d".formatted(membership.getMemberNumber(), shareCount);
|
return "%s%+d".formatted(getMemberNumber(), shareCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
|
|||||||
.transactionType(HsOfficeCoopAssetsTransactionType.DEPOSIT)
|
.transactionType(HsOfficeCoopAssetsTransactionType.DEPOSIT)
|
||||||
.assetValue(new BigDecimal("128.00"))
|
.assetValue(new BigDecimal("128.00"))
|
||||||
.build();
|
.build();
|
||||||
|
final HsOfficeCoopAssetsTransactionEntity givenEmptyCoopAssetsTransaction = HsOfficeCoopAssetsTransactionEntity.builder().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toStringContainsAlmostAllPropertiesAccount() {
|
void toStringContainsAlmostAllPropertiesAccount() {
|
||||||
@ -31,4 +32,18 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
|
|||||||
|
|
||||||
assertThat(result).isEqualTo("300001+128.00");
|
assertThat(result).isEqualTo("300001+128.00");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toStringWithEmptyTransactionDoesNotThrowException() {
|
||||||
|
final var result = givenEmptyCoopAssetsTransaction.toString();
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("CoopAssetsTransaction()");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toShortStringEmptyTransactionDoesNotThrowException() {
|
||||||
|
final var result = givenEmptyCoopAssetsTransaction.toShortString();
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("nullnu");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ class HsOfficeCoopSharesTransactionEntityUnitTest {
|
|||||||
.transactionType(HsOfficeCoopSharesTransactionType.SUBSCRIPTION)
|
.transactionType(HsOfficeCoopSharesTransactionType.SUBSCRIPTION)
|
||||||
.shareCount(4)
|
.shareCount(4)
|
||||||
.build();
|
.build();
|
||||||
|
final HsOfficeCoopSharesTransactionEntity givenEmptyCoopSharesTransaction = HsOfficeCoopSharesTransactionEntity.builder().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toStringContainsAlmostAllPropertiesAccount() {
|
void toStringContainsAlmostAllPropertiesAccount() {
|
||||||
@ -25,9 +26,23 @@ class HsOfficeCoopSharesTransactionEntityUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toShortStringContainsOnlyMemberNumberAndshareCountOnly() {
|
void toShortStringContainsOnlyMemberNumberAndShareCountOnly() {
|
||||||
final var result = givenCoopSharesTransaction.toShortString();
|
final var result = givenCoopSharesTransaction.toShortString();
|
||||||
|
|
||||||
assertThat(result).isEqualTo("300001+4");
|
assertThat(result).isEqualTo("300001+4");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toStringEmptyTransactionDoesNotThrowException() {
|
||||||
|
final var result = givenEmptyCoopSharesTransaction.toString();
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("CoopShareTransaction(0)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toShortStringEmptyTransactionDoesNotThrowException() {
|
||||||
|
final var result = givenEmptyCoopSharesTransaction.toShortString();
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("null+0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user