Добавил тесты проведения, повторного проведения и изменения сумм операций
This commit is contained in:
1 parent
d264ed6583
commit
8af851a49a
18 files changed
+303
-35
No files matched your search
@@ -0,0 +1,62 @@
|
||||
package service;
|
||||
|
||||
import model.Operation;
|
||||
import model.OperationJournal;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class OperationService {
|
||||
|
||||
private final OperationJournal journal;
|
||||
private final Ledger ledger;
|
||||
|
||||
public OperationService(OperationJournal journal, Ledger ledger) {
|
||||
|
||||
this.journal = Objects.requireNonNull(
|
||||
journal, "Не указан журнал операций"
|
||||
);
|
||||
this.ledger = Objects.requireNonNull(
|
||||
ledger, "Не указан регистр движений"
|
||||
);
|
||||
}
|
||||
|
||||
public void save(Operation operation) {
|
||||
journal.saveOperation(operation);
|
||||
}
|
||||
|
||||
public void post(Long operationId) {
|
||||
post(requiredOperation(operationId));
|
||||
}
|
||||
|
||||
public void post(Operation operation) {
|
||||
ledger.post(operation);
|
||||
journal.saveOperation(operation);
|
||||
}
|
||||
|
||||
public void unpost(Long operationId) {
|
||||
ledger.unpost(requiredOperation(operationId).getId());
|
||||
}
|
||||
|
||||
public boolean isPosted(Operation operation) {
|
||||
if (operation == null) {
|
||||
throw new IllegalArgumentException("Не указан документ");
|
||||
}
|
||||
return ledger.isPosted(operation.getId());
|
||||
}
|
||||
|
||||
private Operation requiredOperation(Long operationId) {
|
||||
|
||||
if (operationId == null) {
|
||||
throw new IllegalArgumentException("Не указан ID операции");
|
||||
}
|
||||
|
||||
Operation operation = journal.getOperationById(operationId);
|
||||
|
||||
if (operation == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Операция не найдена: " + operationId
|
||||
);
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user