From ccb171c9ec1ebcf71e2a906e138e741cbc4691e2 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 19 Jun 2021 17:36:49 +0200 Subject: [PATCH] Implemented state-change logic --- .../payment/transfer/domain/Transfer.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java b/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java index cac0f19..86e5c03 100644 --- a/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java +++ b/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java @@ -8,6 +8,8 @@ import lombok.EqualsAndHashCode; import java.util.LinkedList; import java.util.List; +import static de.juplo.kafka.payment.transfer.domain.Transfer.State.*; + @Data @Builder @@ -42,6 +44,27 @@ public class Transfer public Transfer setState(State state) { + if (state == null) + throw new IllegalArgumentException("State must not be null!"); + + switch (state) + { + case CREATED: + if (this.state != null) + throw new IllegalArgumentException("Illegal state-change " + this.state + " -> CREATED"); + break; + + case CHECKED: + case INVALID: + if (this.state != CREATED) + throw new IllegalArgumentException("Illegal state-change " + this.state + " -> " + state); + break; + + default: + throw new IllegalArgumentException("State-change not yet considered:" + this.state + " -> " + state); + + } + this.state = state; return this; } -- 2.20.1