diff --git a/src/main/java/io/fp/shapes/RectangleCircle.java b/src/main/java/io/fp/shapes/RectangleCircle.java index 93af9194449025a152685bba75f558222469abfc..e5483772d1c8b369ccf1adc17fb42a304ea66281 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 79ac978649271da2f4a63cc0b8e6b9b96f0f4e7d..d182cbe882b47955fcf86fdb306c88a46c43e202 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