Skip to content
Snippets Groups Projects
Commit 78279dcb authored by Martin Schmollinger's avatar Martin Schmollinger
Browse files

Setter throw SizeException and refactoring of test

parent 7b97e2e1
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment