Skip to content

Commit 9e47280

Browse files
committed
Incorporating custom exception
1 parent 3bacb8c commit 9e47280

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

exercises/practice/two-bucket/.meta/src/reference/java/TwoBucket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private void checkIfImpossible(int desiredLiters, int bucketOneCap, int bucketTw
104104
boolean invalidDivision = desiredLiters % gcd(bucketOneCap, bucketTwoCap) != 0;
105105

106106
if (exceedsCapacity || invalidDivision) {
107-
throw new IllegalArgumentException("impossible");
107+
throw new UnreachableGoalException("impossible");
108108
}
109109
}
110110

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class UnreachableGoalException extends RuntimeException {
2+
3+
public UnreachableGoalException() {
4+
super();
5+
}
6+
7+
public UnreachableGoalException(String message) {
8+
super(message);
9+
}
10+
11+
public UnreachableGoalException(String message, Throwable cause) {
12+
super(message, cause);
13+
}
14+
}

exercises/practice/two-bucket/src/main/java/Result.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ public String getFinalBucket() {
2121
public int getOtherBucket() {
2222
return otherBucket;
2323
}
24-
2524
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class UnreachableGoalException extends RuntimeException {
2+
3+
public UnreachableGoalException() {
4+
super();
5+
}
6+
7+
public UnreachableGoalException(String message) {
8+
super(message);
9+
}
10+
11+
public UnreachableGoalException(String message, Throwable cause) {
12+
super(message, cause);
13+
}
14+
}

exercises/practice/two-bucket/src/test/java/TwoBucketTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void testBucketOneSizeTwoBucketTwoSizeThreeStartWithOne() {
8181
@Test
8282
public void testReachingGoalIsImpossible() {
8383

84-
assertThatExceptionOfType(IllegalArgumentException.class)
84+
assertThatExceptionOfType(UnreachableGoalException.class)
8585
.isThrownBy(() -> new TwoBucket(6, 15, 5, "one"))
8686
.withMessage("impossible");
8787

@@ -103,7 +103,7 @@ public void testBucketOneSizeSixBucketTwoSizeFifteenStartWithOne() {
103103
@Test
104104
public void testGoalLargerThanBothBucketsIsImpossible() {
105105

106-
assertThatExceptionOfType(IllegalArgumentException.class)
106+
assertThatExceptionOfType(UnreachableGoalException.class)
107107
.isThrownBy(() -> new TwoBucket(5, 7, 8, "one"))
108108
.withMessage("impossible");
109109

0 commit comments

Comments
 (0)