Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lab4-v23-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mattias.Nordahl
lab4-v23-1
Commits
8076021c
Commit
8076021c
authored
2 years ago
by
Torstein Strømme
Browse files
Options
Downloads
Patches
Plain Diff
tests now compile
parent
e59fe78b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/test/java/no/uib/inf101/gridview/TestCellPositionToPixelConverter.java
+22
-1
22 additions, 1 deletion
...uib/inf101/gridview/TestCellPositionToPixelConverter.java
src/test/java/no/uib/inf101/gridview/TestGridView.java
+9
-4
9 additions, 4 deletions
src/test/java/no/uib/inf101/gridview/TestGridView.java
with
31 additions
and
5 deletions
src/test/java/no/uib/inf101/gridview/TestCellPositionToPixelConverter.java
+
22
−
1
View file @
8076021c
...
...
@@ -10,6 +10,7 @@ import java.awt.*;
import
java.awt.geom.Rectangle2D
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -29,13 +30,33 @@ public class TestCellPositionToPixelConverter {
grid
,
new
Rectangle2D
.
Double
(
30
,
30
,
340
,
240
),
30
);
Rectangle2D
expected
=
new
Rectangle2D
.
Double
(
215
,
130
,
47.5
,
40
);
assertEquals
(
expected
,
converter
.
getBoundsForCell
(
new
CellPosition
(
1
,
2
)));
assertEquals
(
expected
,
getBoundsForCell
(
converter
,
new
CellPosition
(
1
,
2
)));
}
/////////////////////////////
// Helper methods
/////////////////////////////
static
Rectangle2D
getBoundsForCell
(
CellPositionToPixelConverter
converter
,
CellPosition
cp
)
{
try
{
Method
method
=
CellPositionToPixelConverter
.
class
.
getMethod
(
"getBoundsForCell"
,
CellPosition
.
class
);
// Check that the method is public
assertFalse
(
Modifier
.
isPrivate
(
method
.
getModifiers
()),
"The method getBoundsForCell(CellPosition) in the CellPositionToPixelConverter class should not be private"
);
Object
result
=
method
.
invoke
(
converter
,
cp
);
assertInstanceOf
(
Rectangle2D
.
class
,
result
,
"The method getBoundsForCell(CellPosition) in the CellPositionToPixelConverter class should return a Rectangle2D"
);
return
(
Rectangle2D
)
result
;
}
catch
(
NoSuchMethodException
e
)
{
fail
(
"Could not find the method getBoundsForCell(CellPosition) in the CellPositionToPixelConverter class"
);
}
catch
(
IllegalAccessException
|
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
e
);
}
throw
new
IllegalStateException
(
"Should not be possible to reach this point"
);
}
static
CellPositionToPixelConverter
getConverter
(
GridDimension
grid
,
Rectangle2D
rect
,
double
margin
)
{
try
{
Constructor
<?>
constructor
=
CellPositionToPixelConverter
.
class
.
getConstructor
(
...
...
This diff is collapsed.
Click to expand it.
src/test/java/no/uib/inf101/gridview/TestGridView.java
+
9
−
4
View file @
8076021c
...
...
@@ -14,6 +14,7 @@ package no.uib.inf101.gridview;
import
no.uib.inf101.colorgrid.*
;
import
org.junit.jupiter.api.Test
;
import
javax.swing.JPanel
;
import
java.awt.*
;
import
java.awt.geom.Rectangle2D
;
import
java.lang.reflect.Constructor
;
...
...
@@ -28,10 +29,14 @@ public class TestGridView {
@Test
public
void
preferredSize
()
{
GridView
view
=
newGridView
(
null
);
assertNotNull
(
view
,
"Unable to create a new GridView object"
);
assertNotNull
(
view
.
getPreferredSize
(),
"PreferredSize should not be null"
);
assertEquals
(
400
,
view
.
getPreferredSize
().
width
);
assertEquals
(
300
,
view
.
getPreferredSize
().
height
);
if
((
Object
)
view
instanceof
JPanel
panel
)
{
assertNotNull
(
panel
,
"Unable to create a new GridView object"
);
assertNotNull
(
panel
.
getPreferredSize
(),
"PreferredSize should not be null"
);
assertEquals
(
400
,
panel
.
getPreferredSize
().
width
);
assertEquals
(
300
,
panel
.
getPreferredSize
().
height
);
}
else
{
fail
(
"The GridView class should extend JPanel"
);
}
}
@Test
...
...
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