From 8e47ab0d3472bc75ecfdebd55afed3a8d262f595 Mon Sep 17 00:00:00 2001 From: Desetude Date: Wed, 28 Oct 2015 17:10:49 +0000 Subject: [PATCH] Added different ways the potato can be not delicious! --- src/main/java/org/drtshock/NotDeliciousException.java | 11 ++++++++++- src/main/java/org/drtshock/NotDeliciousReason.java | 11 +++++++++++ src/main/java/org/drtshock/Potato.java | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/drtshock/NotDeliciousReason.java diff --git a/src/main/java/org/drtshock/NotDeliciousException.java b/src/main/java/org/drtshock/NotDeliciousException.java index 5ad13ec..8e9b5cf 100644 --- a/src/main/java/org/drtshock/NotDeliciousException.java +++ b/src/main/java/org/drtshock/NotDeliciousException.java @@ -1,8 +1,17 @@ package org.drtshock; +/** + * An exception to describe that the potato isn't delicious! + */ public class NotDeliciousException extends Exception { - public NotDeliciousException() { + /** + * The reason for non-deliciousness. + */ + private NotDeliciousReason notDeliciousReason; + public NotDeliciousException(NotDeliciousReason notDeliciousReason) { + this.notDeliciousReason = notDeliciousReason; } + } diff --git a/src/main/java/org/drtshock/NotDeliciousReason.java b/src/main/java/org/drtshock/NotDeliciousReason.java new file mode 100644 index 0000000..0687304 --- /dev/null +++ b/src/main/java/org/drtshock/NotDeliciousReason.java @@ -0,0 +1,11 @@ +package org.drtshock; + +/** + * Different ways the potato can be not delicious + */ +public enum NotDeliciousReason { + + NOT_BAKED, + NOT_DELICIOUS_CONDIMENT + +} diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index 83690c3..6c53aea 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -41,7 +41,7 @@ public class Potato implements Tuber { public void prepare() throws NotDeliciousException { this.addCondiments("sour cream", "chives", "butter", "crumbled bacon", "grated cheese", "ketchup", "salt", "tabasco"); this.listCondiments(); - if (!this.isDelicious()) throw new NotDeliciousException(); + if (!this.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.NOT_BAKED); } /** @@ -52,7 +52,7 @@ public class Potato implements Tuber { public void addCondiments(String... names) throws NotDeliciousException { for (String condimentName : names) { Condiment condiment = new Condiment(condimentName, true); - if (!condiment.isDelicious()) throw new NotDeliciousException(); + if (!condiment.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.NOT_DELICIOUS_CONDIMENT); this.getCondiments().add(condiment); } }