diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index a8f0335..2efff19 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -30,7 +30,9 @@ jobs:
run: mvn --batch-mode clean test
- name: Test Coverage
- uses: codecov/codecov-action@v3
+ uses: codecov/codecov-action@v4.0.1
+ env:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: SonarCloud Analyze
run: >
diff --git a/pom.xml b/pom.xml
index e685013..a06fd85 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,8 +46,8 @@
11
UTF-8
UTF-8
- 1.18.28
- 3.34.0
+ 1.18.30
+ 3.42.0
diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java
index e450f85..c411680 100644
--- a/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java
+++ b/src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java
@@ -51,8 +51,8 @@ public abstract class AbstractTransaction {
protected final @Nullable BigDecimal value; // стоимость в валюте цены, null для зачисления и списания ЦБ
@EqualsAndHashCode.Exclude
protected final @Nullable BigDecimal fee;
- protected final String valueCurrency; // валюта платежа
- protected final String feeCurrency; // валюта комиссии
+ protected final @Nullable String valueCurrency; // валюта платежа. Обязателен, если заполнен value
+ protected final @Nullable String feeCurrency; // валюта комиссии. Обязателен, если заполнен fee
@SuppressWarnings("unused")
@@ -76,7 +76,7 @@ public List getTransactionCashFlows() {
}
protected Optional getValueCashFlow(CashFlowType type) {
- if (value != null && Math.abs(value.floatValue()) >= 0.0001) {
+ if (value != null && valueCurrency != null && isNotZero(value)) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(type)
@@ -88,7 +88,7 @@ protected Optional getValueCashFlow(CashFlowType type) {
}
protected Optional getFeeCashFlow() {
- if (fee != null && Math.abs(fee.floatValue()) >= 0.0001) {
+ if (fee != null && feeCurrency != null && isNotZero(fee)) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(FEE)
@@ -99,6 +99,10 @@ protected Optional getFeeCashFlow() {
return Optional.empty();
}
+ protected boolean isNotZero(BigDecimal value) {
+ return Math.abs(value.floatValue()) > 0.000_000_99f;
+ }
+
@EqualsAndHashCode.Include
@SuppressWarnings("unused")
private @Nullable BigDecimal getValueForEquals() {
diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java
index db9e774..780df9d 100644
--- a/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java
+++ b/src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java
@@ -67,11 +67,11 @@ protected Optional getValueInPointsCashFlow() {
@Override
protected Optional getValueCashFlow(CashFlowType type) {
- if (value != null) {
+ if (value != null && valueCurrency != null) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(type)
- .value(value)
+ .value(value) // zero value is permitted
.currency(valueCurrency)
.build());
}
diff --git a/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java b/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java
index 19096a8..61779e5 100644
--- a/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java
+++ b/src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java
@@ -39,7 +39,7 @@
@EqualsAndHashCode(callSuper = true, cacheStrategy = LAZY)
public class SecurityTransaction extends AbstractTransaction {
@EqualsAndHashCode.Exclude
- private final @Nullable BigDecimal accruedInterest; // НКД, в валюте бумаги
+ private final @Nullable BigDecimal accruedInterest; // НКД, в валюте бумаги. Если задано, то поле valueCurrency обязательно
@Override
public List getTransactionCashFlows() {
@@ -52,7 +52,7 @@ public List getTransactionCashFlows() {
private Optional getAccruedInterestCashFlow() {
// for securities accrued interest = 0
- if (accruedInterest != null && Math.abs(accruedInterest.floatValue()) >= 0.0001) {
+ if (accruedInterest != null && valueCurrency != null && isNotZero(accruedInterest)) {
return Optional.of(TransactionCashFlow.builder()
.transactionId(id)
.eventType(CashFlowType.ACCRUED_INTEREST)
diff --git a/src/test/java/org/spacious_team/broker/report_parser/api/DerivativeTransactionTest.java b/src/test/java/org/spacious_team/broker/report_parser/api/DerivativeTransactionTest.java
index 281fa12..4701006 100644
--- a/src/test/java/org/spacious_team/broker/report_parser/api/DerivativeTransactionTest.java
+++ b/src/test/java/org/spacious_team/broker/report_parser/api/DerivativeTransactionTest.java
@@ -28,6 +28,7 @@
import java.time.Instant;
import java.util.List;
+import static java.util.Objects.requireNonNull;
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.spacious_team.broker.pojo.CashFlowType.*;
@@ -105,6 +106,7 @@ void getTransactionCashFlows_valueIsZero() {
void getTransactionCashFlows_valueIsNull() {
DerivativeTransaction tr = this.tr.toBuilder()
.value(null)
+ .valueCurrency(null)
.build();
expectedCashFlows(tr,
getValueInPointsCashFlow(tr),
@@ -125,6 +127,7 @@ void getTransactionCashFlows_feeIsZero() {
void getTransactionCashFlows_feeIsNull() {
DerivativeTransaction tr = this.tr.toBuilder()
.fee(null)
+ .feeCurrency(null)
.build();
expectedCashFlows(tr,
getValueInPointsCashFlow(tr),
@@ -136,7 +139,7 @@ private TransactionCashFlow getValueInPointsCashFlow(DerivativeTransaction trans
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(DERIVATIVE_QUOTE)
- .value(transaction.getValueInPoints())
+ .value(requireNonNull(transaction.getValueInPoints()))
.currency(DerivativeTransaction.QUOTE_CURRENCY)
.build();
}
@@ -146,8 +149,8 @@ private TransactionCashFlow getValueCashFlow(DerivativeTransaction transaction)
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(DERIVATIVE_PRICE)
- .value(transaction.getValue())
- .currency(transaction.getValueCurrency())
+ .value(requireNonNull(transaction.getValue()))
+ .currency(requireNonNull(transaction.getValueCurrency()))
.build();
}
@@ -156,8 +159,8 @@ private TransactionCashFlow getFeeCashFlow(DerivativeTransaction transaction) {
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(FEE)
- .value(transaction.getFee())
- .currency(transaction.getFeeCurrency())
+ .value(requireNonNull(transaction.getFee()))
+ .currency(requireNonNull(transaction.getFeeCurrency()))
.build();
}
diff --git a/src/test/java/org/spacious_team/broker/report_parser/api/ForeignExchangeTransactionTest.java b/src/test/java/org/spacious_team/broker/report_parser/api/ForeignExchangeTransactionTest.java
index 90dbafe..098900e 100644
--- a/src/test/java/org/spacious_team/broker/report_parser/api/ForeignExchangeTransactionTest.java
+++ b/src/test/java/org/spacious_team/broker/report_parser/api/ForeignExchangeTransactionTest.java
@@ -28,6 +28,7 @@
import java.time.Instant;
import java.util.List;
+import static java.util.Objects.requireNonNull;
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.spacious_team.broker.pojo.CashFlowType.FEE;
@@ -80,6 +81,7 @@ void getTransactionCashFlows_valueIsZero() {
void getTransactionCashFlows_valueIsNull() {
ForeignExchangeTransaction tr = this.tr.toBuilder()
.value(null)
+ .valueCurrency(null)
.build();
expectedCashFlows(tr, getFeeCashFlow(tr));
}
@@ -96,6 +98,7 @@ void getTransactionCashFlows_feeIsZero() {
void getTransactionCashFlows_feeIsNull() {
ForeignExchangeTransaction tr = this.tr.toBuilder()
.fee(null)
+ .feeCurrency(null)
.build();
expectedCashFlows(tr, getValueCashFlow(tr));
}
@@ -105,8 +108,8 @@ private TransactionCashFlow getValueCashFlow(ForeignExchangeTransaction transact
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(PRICE)
- .value(transaction.getValue())
- .currency(transaction.getValueCurrency())
+ .value(requireNonNull(transaction.getValue()))
+ .currency(requireNonNull(transaction.getValueCurrency()))
.build();
}
@@ -115,8 +118,8 @@ private TransactionCashFlow getFeeCashFlow(ForeignExchangeTransaction transactio
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(FEE)
- .value(transaction.getFee())
- .currency(transaction.getFeeCurrency())
+ .value(requireNonNull(transaction.getFee()))
+ .currency(requireNonNull(transaction.getFeeCurrency()))
.build();
}
diff --git a/src/test/java/org/spacious_team/broker/report_parser/api/SecurityTransactionTest.java b/src/test/java/org/spacious_team/broker/report_parser/api/SecurityTransactionTest.java
index dcf969a..08a5ef1 100644
--- a/src/test/java/org/spacious_team/broker/report_parser/api/SecurityTransactionTest.java
+++ b/src/test/java/org/spacious_team/broker/report_parser/api/SecurityTransactionTest.java
@@ -28,6 +28,7 @@
import java.time.Instant;
import java.util.List;
+import static java.util.Objects.requireNonNull;
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.spacious_team.broker.pojo.CashFlowType.*;
@@ -83,6 +84,7 @@ void getTransactionCashFlows_accruedInterestIsZero() {
void getTransactionCashFlows_accruedInterestIsNull() {
SecurityTransaction tr = this.tr.toBuilder()
.accruedInterest(null)
+ // can't set "valueCurrency(null)", "valueCurrency" is used by not null "value" field
.build();
expectedCashFlows(tr,
getValueCashFlow(tr),
@@ -103,6 +105,7 @@ void getTransactionCashFlows_valueIsZero() {
void getTransactionCashFlows_valueIsNull() {
SecurityTransaction tr = this.tr.toBuilder()
.value(null)
+ // can't set "valueCurrency(null)", "valueCurrency" is used by not null "accruedInterest" field
.build();
expectedCashFlows(tr,
getAccruedInterestCashFlow(tr),
@@ -123,6 +126,7 @@ void getTransactionCashFlows_feeIsZero() {
void getTransactionCashFlows_feeIsNull() {
SecurityTransaction tr = this.tr.toBuilder()
.fee(null)
+ .feeCurrency(null)
.build();
expectedCashFlows(tr,
getValueCashFlow(tr),
@@ -134,8 +138,8 @@ private TransactionCashFlow getAccruedInterestCashFlow(SecurityTransaction trans
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(ACCRUED_INTEREST)
- .value(transaction.getAccruedInterest())
- .currency(transaction.getValueCurrency())
+ .value(requireNonNull(transaction.getAccruedInterest()))
+ .currency(requireNonNull(transaction.getValueCurrency()))
.build();
}
@@ -144,8 +148,8 @@ private TransactionCashFlow getValueCashFlow(SecurityTransaction transaction) {
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(PRICE)
- .value(transaction.getValue())
- .currency(transaction.getValueCurrency())
+ .value(requireNonNull(transaction.getValue()))
+ .currency(requireNonNull(transaction.getValueCurrency()))
.build();
}
@@ -154,8 +158,8 @@ private TransactionCashFlow getFeeCashFlow(SecurityTransaction transaction) {
return TransactionCashFlow.builder()
.transactionId(transaction.getId())
.eventType(FEE)
- .value(transaction.getFee())
- .currency(transaction.getFeeCurrency())
+ .value(requireNonNull(transaction.getFee()))
+ .currency(requireNonNull(transaction.getFeeCurrency()))
.build();
}