From 78279dcb3c554ee08f52eadf3a87859dd55d75ec Mon Sep 17 00:00:00 2001
From: Martin Schmollinger <martin.schmollinger@reutlingen-university.de>
Date: Wed, 13 Apr 2022 13:22:21 +0200
Subject: [PATCH] Setter throw SizeException and refactoring of test

---
 src/main/java/io/fp/shapes/RectangleCircle.java | 17 ++++++++++++-----
 src/test/java/io/fp/shapes/ShapesTest.java      | 15 +++------------
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/main/java/io/fp/shapes/RectangleCircle.java b/src/main/java/io/fp/shapes/RectangleCircle.java
index 93af919..e548377 100644
--- a/src/main/java/io/fp/shapes/RectangleCircle.java
+++ b/src/main/java/io/fp/shapes/RectangleCircle.java
@@ -6,8 +6,7 @@ public class RectangleCircle implements Shape {
 	private Rectangle r;
 	
 	public RectangleCircle(double radius, double width, double height) throws SizeException{
-		if (width<=2*radius||height<=2*radius)
-			throw new SizeException();
+		validate(radius, width, height);
 		c = new Circle(radius);
 		r = new Rectangle(width, height);
 	}
@@ -22,7 +21,8 @@ public class RectangleCircle implements Shape {
 		return r.circumference() + c.circumference();
 	}
 	
-	public void setRadius(double radius) {
+	public void setRadius(double radius) throws SizeException {
+		validate(radius, this.r.getWidth(), this.r.getHeight());
 		c.setRadius(radius);
 	}
 	
@@ -30,7 +30,8 @@ public class RectangleCircle implements Shape {
 		return c.getRadius();
 	}
 	
-	public void setWidth(double width) {
+	public void setWidth(double width) throws SizeException {
+		validate(c.getRadius(), width, r.getHeight());
 		r.setWidth(width);
 	}
 	
@@ -38,11 +39,17 @@ public class RectangleCircle implements Shape {
 		return r.getWidth();
 	}
 
-	public void setHeight(double height) {
+	public void setHeight(double height) throws SizeException {
+		validate(c.getRadius(), r.getWidth(), height);
 		r.setHeight(height);
 	}
 	
 	public double getHeight() {
 		return r.getHeight();
 	}
+
+	private void validate(double radius, double width, double height) throws SizeException {
+		if (width<=2*radius||height<=2*radius)
+			throw new SizeException();
+	} 
 }
diff --git a/src/test/java/io/fp/shapes/ShapesTest.java b/src/test/java/io/fp/shapes/ShapesTest.java
index 79ac978..d182cbe 100644
--- a/src/test/java/io/fp/shapes/ShapesTest.java
+++ b/src/test/java/io/fp/shapes/ShapesTest.java
@@ -1,24 +1,15 @@
 package io.fp.shapes;
 
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import java.util.ArrayList;
-
 import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-
 public class ShapesTest {
 
-
     @Test
-    void testSizeExpetion(){
+    void testSizeExpetion() {
 
-        Assertions.assertThrows(SizeException.class,() ->{ 
-            RectangleCircle rc = new RectangleCircle(2, 1, 1);
+        Assertions.assertThrows(SizeException.class, () -> {
+            new RectangleCircle(2, 1, 1);
         });
     }
-
- 
 }
\ No newline at end of file
-- 
GitLab