Skip to content

Commit 794e3c6

Browse files
authored
Merge pull request #35 from spacious-team/develop
Релиз 2024.1
2 parents 7592194 + 3b2a69e commit 794e3c6

File tree

8 files changed

+42
-26
lines changed

8 files changed

+42
-26
lines changed

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
run: mvn --batch-mode clean test
3131

3232
- name: Test Coverage
33-
uses: codecov/codecov-action@v3
33+
uses: codecov/codecov-action@v4.0.1
34+
env:
35+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3436

3537
- name: SonarCloud Analyze
3638
run: >

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<maven.compiler.release>11</maven.compiler.release>
4747
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4848
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
49-
<lombok.version>1.18.28</lombok.version>
50-
<checkerframework.version>3.34.0</checkerframework.version>
49+
<lombok.version>1.18.30</lombok.version>
50+
<checkerframework.version>3.42.0</checkerframework.version>
5151
</properties>
5252

5353
<repositories>

src/main/java/org/spacious_team/broker/report_parser/api/AbstractTransaction.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public abstract class AbstractTransaction {
5151
protected final @Nullable BigDecimal value; // стоимость в валюте цены, null для зачисления и списания ЦБ
5252
@EqualsAndHashCode.Exclude
5353
protected final @Nullable BigDecimal fee;
54-
protected final String valueCurrency; // валюта платежа
55-
protected final String feeCurrency; // валюта комиссии
54+
protected final @Nullable String valueCurrency; // валюта платежа. Обязателен, если заполнен value
55+
protected final @Nullable String feeCurrency; // валюта комиссии. Обязателен, если заполнен fee
5656

5757

5858
@SuppressWarnings("unused")
@@ -76,7 +76,7 @@ public List<TransactionCashFlow> getTransactionCashFlows() {
7676
}
7777

7878
protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
79-
if (value != null && Math.abs(value.floatValue()) >= 0.0001) {
79+
if (value != null && valueCurrency != null && isNotZero(value)) {
8080
return Optional.of(TransactionCashFlow.builder()
8181
.transactionId(id)
8282
.eventType(type)
@@ -88,7 +88,7 @@ protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
8888
}
8989

9090
protected Optional<TransactionCashFlow> getFeeCashFlow() {
91-
if (fee != null && Math.abs(fee.floatValue()) >= 0.0001) {
91+
if (fee != null && feeCurrency != null && isNotZero(fee)) {
9292
return Optional.of(TransactionCashFlow.builder()
9393
.transactionId(id)
9494
.eventType(FEE)
@@ -99,6 +99,10 @@ protected Optional<TransactionCashFlow> getFeeCashFlow() {
9999
return Optional.empty();
100100
}
101101

102+
protected boolean isNotZero(BigDecimal value) {
103+
return Math.abs(value.floatValue()) > 0.000_000_99f;
104+
}
105+
102106
@EqualsAndHashCode.Include
103107
@SuppressWarnings("unused")
104108
private @Nullable BigDecimal getValueForEquals() {

src/main/java/org/spacious_team/broker/report_parser/api/DerivativeTransaction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ protected Optional<TransactionCashFlow> getValueInPointsCashFlow() {
6767

6868
@Override
6969
protected Optional<TransactionCashFlow> getValueCashFlow(CashFlowType type) {
70-
if (value != null) {
70+
if (value != null && valueCurrency != null) {
7171
return Optional.of(TransactionCashFlow.builder()
7272
.transactionId(id)
7373
.eventType(type)
74-
.value(value)
74+
.value(value) // zero value is permitted
7575
.currency(valueCurrency)
7676
.build());
7777
}

src/main/java/org/spacious_team/broker/report_parser/api/SecurityTransaction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@EqualsAndHashCode(callSuper = true, cacheStrategy = LAZY)
4040
public class SecurityTransaction extends AbstractTransaction {
4141
@EqualsAndHashCode.Exclude
42-
private final @Nullable BigDecimal accruedInterest; // НКД, в валюте бумаги
42+
private final @Nullable BigDecimal accruedInterest; // НКД, в валюте бумаги. Если задано, то поле valueCurrency обязательно
4343

4444
@Override
4545
public List<TransactionCashFlow> getTransactionCashFlows() {
@@ -52,7 +52,7 @@ public List<TransactionCashFlow> getTransactionCashFlows() {
5252

5353
private Optional<TransactionCashFlow> getAccruedInterestCashFlow() {
5454
// for securities accrued interest = 0
55-
if (accruedInterest != null && Math.abs(accruedInterest.floatValue()) >= 0.0001) {
55+
if (accruedInterest != null && valueCurrency != null && isNotZero(accruedInterest)) {
5656
return Optional.of(TransactionCashFlow.builder()
5757
.transactionId(id)
5858
.eventType(CashFlowType.ACCRUED_INTEREST)

src/test/java/org/spacious_team/broker/report_parser/api/DerivativeTransactionTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.time.Instant;
2929
import java.util.List;
3030

31+
import static java.util.Objects.requireNonNull;
3132
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
3233
import static org.junit.jupiter.api.Assertions.assertEquals;
3334
import static org.spacious_team.broker.pojo.CashFlowType.*;
@@ -105,6 +106,7 @@ void getTransactionCashFlows_valueIsZero() {
105106
void getTransactionCashFlows_valueIsNull() {
106107
DerivativeTransaction tr = this.tr.toBuilder()
107108
.value(null)
109+
.valueCurrency(null)
108110
.build();
109111
expectedCashFlows(tr,
110112
getValueInPointsCashFlow(tr),
@@ -125,6 +127,7 @@ void getTransactionCashFlows_feeIsZero() {
125127
void getTransactionCashFlows_feeIsNull() {
126128
DerivativeTransaction tr = this.tr.toBuilder()
127129
.fee(null)
130+
.feeCurrency(null)
128131
.build();
129132
expectedCashFlows(tr,
130133
getValueInPointsCashFlow(tr),
@@ -136,7 +139,7 @@ private TransactionCashFlow getValueInPointsCashFlow(DerivativeTransaction trans
136139
return TransactionCashFlow.builder()
137140
.transactionId(transaction.getId())
138141
.eventType(DERIVATIVE_QUOTE)
139-
.value(transaction.getValueInPoints())
142+
.value(requireNonNull(transaction.getValueInPoints()))
140143
.currency(DerivativeTransaction.QUOTE_CURRENCY)
141144
.build();
142145
}
@@ -146,8 +149,8 @@ private TransactionCashFlow getValueCashFlow(DerivativeTransaction transaction)
146149
return TransactionCashFlow.builder()
147150
.transactionId(transaction.getId())
148151
.eventType(DERIVATIVE_PRICE)
149-
.value(transaction.getValue())
150-
.currency(transaction.getValueCurrency())
152+
.value(requireNonNull(transaction.getValue()))
153+
.currency(requireNonNull(transaction.getValueCurrency()))
151154
.build();
152155
}
153156

@@ -156,8 +159,8 @@ private TransactionCashFlow getFeeCashFlow(DerivativeTransaction transaction) {
156159
return TransactionCashFlow.builder()
157160
.transactionId(transaction.getId())
158161
.eventType(FEE)
159-
.value(transaction.getFee())
160-
.currency(transaction.getFeeCurrency())
162+
.value(requireNonNull(transaction.getFee()))
163+
.currency(requireNonNull(transaction.getFeeCurrency()))
161164
.build();
162165
}
163166

src/test/java/org/spacious_team/broker/report_parser/api/ForeignExchangeTransactionTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.time.Instant;
2929
import java.util.List;
3030

31+
import static java.util.Objects.requireNonNull;
3132
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
3233
import static org.junit.jupiter.api.Assertions.assertEquals;
3334
import static org.spacious_team.broker.pojo.CashFlowType.FEE;
@@ -80,6 +81,7 @@ void getTransactionCashFlows_valueIsZero() {
8081
void getTransactionCashFlows_valueIsNull() {
8182
ForeignExchangeTransaction tr = this.tr.toBuilder()
8283
.value(null)
84+
.valueCurrency(null)
8385
.build();
8486
expectedCashFlows(tr, getFeeCashFlow(tr));
8587
}
@@ -96,6 +98,7 @@ void getTransactionCashFlows_feeIsZero() {
9698
void getTransactionCashFlows_feeIsNull() {
9799
ForeignExchangeTransaction tr = this.tr.toBuilder()
98100
.fee(null)
101+
.feeCurrency(null)
99102
.build();
100103
expectedCashFlows(tr, getValueCashFlow(tr));
101104
}
@@ -105,8 +108,8 @@ private TransactionCashFlow getValueCashFlow(ForeignExchangeTransaction transact
105108
return TransactionCashFlow.builder()
106109
.transactionId(transaction.getId())
107110
.eventType(PRICE)
108-
.value(transaction.getValue())
109-
.currency(transaction.getValueCurrency())
111+
.value(requireNonNull(transaction.getValue()))
112+
.currency(requireNonNull(transaction.getValueCurrency()))
110113
.build();
111114
}
112115

@@ -115,8 +118,8 @@ private TransactionCashFlow getFeeCashFlow(ForeignExchangeTransaction transactio
115118
return TransactionCashFlow.builder()
116119
.transactionId(transaction.getId())
117120
.eventType(FEE)
118-
.value(transaction.getFee())
119-
.currency(transaction.getFeeCurrency())
121+
.value(requireNonNull(transaction.getFee()))
122+
.currency(requireNonNull(transaction.getFeeCurrency()))
120123
.build();
121124
}
122125

src/test/java/org/spacious_team/broker/report_parser/api/SecurityTransactionTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.time.Instant;
2929
import java.util.List;
3030

31+
import static java.util.Objects.requireNonNull;
3132
import static nl.jqno.equalsverifier.Warning.STRICT_INHERITANCE;
3233
import static org.junit.jupiter.api.Assertions.assertEquals;
3334
import static org.spacious_team.broker.pojo.CashFlowType.*;
@@ -83,6 +84,7 @@ void getTransactionCashFlows_accruedInterestIsZero() {
8384
void getTransactionCashFlows_accruedInterestIsNull() {
8485
SecurityTransaction tr = this.tr.toBuilder()
8586
.accruedInterest(null)
87+
// can't set "valueCurrency(null)", "valueCurrency" is used by not null "value" field
8688
.build();
8789
expectedCashFlows(tr,
8890
getValueCashFlow(tr),
@@ -103,6 +105,7 @@ void getTransactionCashFlows_valueIsZero() {
103105
void getTransactionCashFlows_valueIsNull() {
104106
SecurityTransaction tr = this.tr.toBuilder()
105107
.value(null)
108+
// can't set "valueCurrency(null)", "valueCurrency" is used by not null "accruedInterest" field
106109
.build();
107110
expectedCashFlows(tr,
108111
getAccruedInterestCashFlow(tr),
@@ -123,6 +126,7 @@ void getTransactionCashFlows_feeIsZero() {
123126
void getTransactionCashFlows_feeIsNull() {
124127
SecurityTransaction tr = this.tr.toBuilder()
125128
.fee(null)
129+
.feeCurrency(null)
126130
.build();
127131
expectedCashFlows(tr,
128132
getValueCashFlow(tr),
@@ -134,8 +138,8 @@ private TransactionCashFlow getAccruedInterestCashFlow(SecurityTransaction trans
134138
return TransactionCashFlow.builder()
135139
.transactionId(transaction.getId())
136140
.eventType(ACCRUED_INTEREST)
137-
.value(transaction.getAccruedInterest())
138-
.currency(transaction.getValueCurrency())
141+
.value(requireNonNull(transaction.getAccruedInterest()))
142+
.currency(requireNonNull(transaction.getValueCurrency()))
139143
.build();
140144
}
141145

@@ -144,8 +148,8 @@ private TransactionCashFlow getValueCashFlow(SecurityTransaction transaction) {
144148
return TransactionCashFlow.builder()
145149
.transactionId(transaction.getId())
146150
.eventType(PRICE)
147-
.value(transaction.getValue())
148-
.currency(transaction.getValueCurrency())
151+
.value(requireNonNull(transaction.getValue()))
152+
.currency(requireNonNull(transaction.getValueCurrency()))
149153
.build();
150154
}
151155

@@ -154,8 +158,8 @@ private TransactionCashFlow getFeeCashFlow(SecurityTransaction transaction) {
154158
return TransactionCashFlow.builder()
155159
.transactionId(transaction.getId())
156160
.eventType(FEE)
157-
.value(transaction.getFee())
158-
.currency(transaction.getFeeCurrency())
161+
.value(requireNonNull(transaction.getFee()))
162+
.currency(requireNonNull(transaction.getFeeCurrency()))
159163
.build();
160164
}
161165

0 commit comments

Comments
 (0)