Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
1
1.03-formen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fortgeschrittene Programmierung
Aufgabenbuch
1.03-formen
Commits
78279dcb
Commit
78279dcb
authored
3 years ago
by
Martin Schmollinger
Browse files
Options
Downloads
Patches
Plain Diff
Setter throw SizeException and refactoring of test
parent
7b97e2e1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/io/fp/shapes/RectangleCircle.java
+12
-5
12 additions, 5 deletions
src/main/java/io/fp/shapes/RectangleCircle.java
src/test/java/io/fp/shapes/ShapesTest.java
+3
-12
3 additions, 12 deletions
src/test/java/io/fp/shapes/ShapesTest.java
with
15 additions
and
17 deletions
src/main/java/io/fp/shapes/RectangleCircle.java
+
12
−
5
View file @
78279dcb
...
...
@@ -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
();
}
}
This diff is collapsed.
Click to expand it.
src/test/java/io/fp/shapes/ShapesTest.java
+
3
−
12
View file @
78279dcb
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment