diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-03-15 23:52:58 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-03-15 23:52:58 -0400 |
commit | a3150b8a8e17c8a71f617745bb8588b397a75f47 (patch) | |
tree | 7c94dc98f9b1978f8ccf3c38bb3777237bf0788a /ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java | |
parent | 47501b0d9765e64eba370ba80bbc7b2cd5940170 (diff) | |
download | JellySolutions-a3150b8a8e17c8a71f617745bb8588b397a75f47.tar.gz JellySolutions-a3150b8a8e17c8a71f617745bb8588b397a75f47.tar.bz2 JellySolutions-a3150b8a8e17c8a71f617745bb8588b397a75f47.zip |
fix testCreateNeed()
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java index 6dd120c..78f8f85 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java @@ -29,22 +29,20 @@ public class CupboardService { * @throws DuplicateKeyException If there already exists a need with the same name */ public Need createNeed(String name, double maxGoal, Need.GoalType goalType) throws IOException, DuplicateKeyException { - - Need need = new Need(name, goalType, maxGoal); - if (need.getMaxGoal() <= 0) { + if (maxGoal <= 0) { throw new IllegalArgumentException("Max Goal must be greater than zero"); - } else { - if (cupboardDAO.getNeeds().length > 0) { - for (Need searchNeed : cupboardDAO.getNeeds()) { - if (need.getName().equalsIgnoreCase(searchNeed.getName())) { - throw new DuplicateKeyException("Duplicate names are not allowed"); - } - } + } + + for (Need searchNeed : cupboardDAO.getNeeds()) { + if (searchNeed.getName().equalsIgnoreCase(name)) { + throw new DuplicateKeyException("Duplicate names are not allowed"); } - return cupboardDAO.addNeed(need); } - + + Need need = new Need(name, goalType, maxGoal); + return cupboardDAO.addNeed(need); + } /** |