From: Roland Häder Date: Sun, 22 Jan 2023 00:15:35 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c52d14312d26d48082e792e7cbd74836cd3d3859;p=jcustomer-core.git Continued: - also compare account status so you can sort a list of customers by it - constructors, and they are private anyway, of enumerations should not throw exceptions and they cannot be unit-tested, too - check all parameters, like instances not being null and throw proper exceptions --- diff --git a/src/org/mxchange/jcustomercore/events/customer/created/CreatedCustomerEvent.java b/src/org/mxchange/jcustomercore/events/customer/created/CreatedCustomerEvent.java index 8d6b5dc..20e8320 100644 --- a/src/org/mxchange/jcustomercore/events/customer/created/CreatedCustomerEvent.java +++ b/src/org/mxchange/jcustomercore/events/customer/created/CreatedCustomerEvent.java @@ -16,11 +16,13 @@ */ package org.mxchange.jcustomercore.events.customer.created; +import java.text.MessageFormat; import org.mxchange.jcustomercore.model.customer.Customer; /** * An interface for observable events being fired when a customer instance has - * been successfully created. This may happen when a customer profile was called. + * been successfully created. This may happen when a customer profile was + * called. *

* @author Roland Häder */ @@ -42,6 +44,33 @@ public class CreatedCustomerEvent implements ObservableCreatedCustomerEvent { * @param createdCustomer Customer instance being created by helper */ public CreatedCustomerEvent (final Customer createdCustomer) { + // The instance should be valid + if (null == createdCustomer) { + // Throw NPE + throw new NullPointerException("createdCustomer is null"); //NOI18N + } else if (createdCustomer.getCustomerId() == null) { + // Throw NPE, again ... + throw new NullPointerException("createdCustomer.customerId is null"); //NOI18N + } else if (createdCustomer.getCustomerId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("createdCustomer.customerId={0} is not valid", createdCustomer.getCustomerId())); //NOI18N + } else if (createdCustomer.getCustomerNumber() == null) { + // Throw NPE, again ... + throw new NullPointerException("createdCustomer.customerNumber is null"); //NOI18N + } else if (createdCustomer.getCustomerNumber() == null) { + // Empty customer number + throw new IllegalArgumentException("createdCustomer.customerNumber is empty"); //NOI18N + } else if (createdCustomer.getCustomerContact() == null) { + // Throw again ... + throw new NullPointerException("createdCustomer.customerContact is null"); //NOI18N + } else if (createdCustomer.getCustomerContact().getContactId() == null) { + // ... and again ... + throw new NullPointerException("createdCustomer.customerContact.contactId is null"); //NOI18N + } else if (createdCustomer.getCustomerContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("createdCustomer.customerContact.contactId={0} is not valid", createdCustomer.getCustomerContact().getContactId())); //NOI18N + } + // Set customer instance this.createdCustomer = createdCustomer; } diff --git a/src/org/mxchange/jcustomercore/events/customer/update/AdminUpdatedCustomerDataEvent.java b/src/org/mxchange/jcustomercore/events/customer/update/AdminUpdatedCustomerDataEvent.java index d2dd4b1..9d48410 100644 --- a/src/org/mxchange/jcustomercore/events/customer/update/AdminUpdatedCustomerDataEvent.java +++ b/src/org/mxchange/jcustomercore/events/customer/update/AdminUpdatedCustomerDataEvent.java @@ -42,16 +42,31 @@ public class AdminUpdatedCustomerDataEvent implements ObservableAdminUpdatedCust * @param updatedCustomer Updated customer instance */ public AdminUpdatedCustomerDataEvent (final Customer updatedCustomer) { - // Is the customer instance valid? + // The instance should be valid if (null == updatedCustomer) { // Throw NPE throw new NullPointerException("updatedCustomer is null"); //NOI18N } else if (updatedCustomer.getCustomerId() == null) { - // Throw NPE again + // Throw NPE, again ... throw new NullPointerException("updatedCustomer.customerId is null"); //NOI18N } else if (updatedCustomer.getCustomerId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("updatedCustomer.customerId={0} is invalid.", updatedCustomer.getCustomerId())); //NOI18N + // Not valid + throw new IllegalArgumentException(MessageFormat.format("updatedCustomer.customerId={0} is not valid", updatedCustomer.getCustomerId())); //NOI18N + } else if (updatedCustomer.getCustomerNumber() == null) { + // Throw NPE, again ... + throw new NullPointerException("updatedCustomer.customerNumber is null"); //NOI18N + } else if (updatedCustomer.getCustomerNumber() == null) { + // Empty customer number + throw new IllegalArgumentException("updatedCustomer.customerNumber is empty"); //NOI18N + } else if (updatedCustomer.getCustomerContact() == null) { + // Throw again ... + throw new NullPointerException("updatedCustomer.customerContact is null"); //NOI18N + } else if (updatedCustomer.getCustomerContact().getContactId() == null) { + // ... and again ... + throw new NullPointerException("updatedCustomer.customerContact.contactId is null"); //NOI18N + } else if (updatedCustomer.getCustomerContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("updatedCustomer.customerContact.contactId={0} is not valid", updatedCustomer.getCustomerContact().getContactId())); //NOI18N } // Set it here diff --git a/src/org/mxchange/jcustomercore/model/customer/ContactCustomer.java b/src/org/mxchange/jcustomercore/model/customer/ContactCustomer.java index efbac01..593fe47 100644 --- a/src/org/mxchange/jcustomercore/model/customer/ContactCustomer.java +++ b/src/org/mxchange/jcustomercore/model/customer/ContactCustomer.java @@ -41,6 +41,7 @@ import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcontacts.model.utils.ContactUtils; import org.mxchange.jcoreutils.comparable.ComparableUtils; +import org.mxchange.jcoreutils.enums.EnumUtils; import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus; /** @@ -181,8 +182,10 @@ public class ContactCustomer implements Customer { ContactUtils.compare(this.getCustomerContact(), customer.getCustomerContact()), // ... then customer number StringUtils.compare(this.getCustomerNumber(), customer.getCustomerNumber()), - // ... last is confirmation key - StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey()) + // ... next is confirmation key + StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey()), + // ... next account status + EnumUtils.compare(this.getCustomerAccountStatus(), customer.getCustomerAccountStatus()) }; // Check all values diff --git a/src/org/mxchange/jcustomercore/model/customer/status/CustomerAccountStatus.java b/src/org/mxchange/jcustomercore/model/customer/status/CustomerAccountStatus.java index 220a205..8b401ef 100644 --- a/src/org/mxchange/jcustomercore/model/customer/status/CustomerAccountStatus.java +++ b/src/org/mxchange/jcustomercore/model/customer/status/CustomerAccountStatus.java @@ -57,21 +57,6 @@ public enum CustomerAccountStatus implements Serializable { * @param styleClass CSS style class */ private CustomerAccountStatus (final String messageKey, final String styleClass) { - // Validate parameter - if (null == messageKey) { - // Throw NPE - throw new NullPointerException("messageKey is null"); //NOI18N - } else if (messageKey.isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("messageKey is empty"); //NOI18N - } else if (null == styleClass) { - // Throw NPE - throw new NullPointerException("styleClass is null"); //NOI18N - } else if (styleClass.isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("styleClass is empty"); //NOI18N - } - // Set it here this.messageKey = messageKey; this.styleClass = styleClass;