From 147eec160602082976c1303becf1886919020df4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 30 Aug 2016 12:09:56 +0200 Subject: [PATCH] Please cherry-pick: - more tests added on user instance (may prevent message-less NPE somewhere else which is harder to debug) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../model/user/PizzaUserSessionBean.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index a07eea9..6e8ab60 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -604,17 +604,35 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS // user should not be null if (null == user) { - // Abort here + // Throw NPE throw new NullPointerException("user is null"); //NOI18N } else if (user.getUserId() == null) { // Throw NPE again throw new NullPointerException("user.userId is null"); //NOI18N } else if (user.getUserId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N - } else if (user.getUserAccountStatus() == null) { + // Not valid number + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N + } else if (user.getUserName() == null) { // Throw NPE again + throw new NullPointerException("user.userName is null"); //NOI18N + } else if (user.getUserName().isEmpty()) { + // Empty string + throw new IllegalArgumentException("user.userName is empty"); //NOI18N + } else if (user.getUserAccountStatus() == null) { + // Throw NPE throw new NullPointerException("user.userAccountStatus is null"); //NOI18N + } else if (user.getUserContact() == null) { + // Throw it again + throw new NullPointerException("user.userContact is null"); //NOI18N + } else if (user.getUserContact().getContactId() == null) { + // .. and again + throw new NullPointerException("user.userContact.contactId is null"); //NOI18N + } else if (user.getUserContact().getContactId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N + } else if (user.getUserContact().getContactGender() == null) { + // Throw NPE again + throw new NullPointerException("user.userContact.contactGender is null"); //NOI18N } else if (!this.ifUserExists(user)) { // User does not exist throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N -- 2.39.5