Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fip112-2025-g41
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BINTI TENGKU MASRULHISHAM Tengku Maryam Naqeesha
fip112-2025-g41
Commits
077bde2e
Commit
077bde2e
authored
1 month ago
by
tmnaqeesha
Browse files
Options
Downloads
Patches
Plain Diff
fix: Fix reviewItemFilm test file
parent
73be244b
No related branches found
No related tags found
1 merge request
!9
Merge code for iteration3 with main
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/tests/ReviewItemFilmTest.java
+89
-30
89 additions, 30 deletions
src/tests/ReviewItemFilmTest.java
with
89 additions
and
30 deletions
src/tests/ReviewItemFilmTest.java
+
89
−
30
View file @
077bde2e
package
tests
;
package
tests
;
import
opinion.ISocialNetwork
;
import
opinion.SocialNetwork
;
import
exceptions.BadEntryException
;
import
exceptions.BadEntryException
;
import
exceptions.NotMemberException
;
import
exceptions.NotItemException
;
import
exceptions.NotItemException
;
import
exceptions.NotMemberException
;
import
exceptions.NotTestReportException
;
import
opinion.ISocialNetwork
;
import
opinion.SocialNetwork
;
/**
/**
* Tests for the SocialNetwork.reviewItemFilm() method.
* Tests for the SocialNetwork.
<i>
reviewItemFilm()
</i>
method.
*/
*/
public
class
ReviewItemFilmTest
{
public
class
ReviewItemFilmTest
{
private
static
int
reviewItemFilmCheck
(
ISocialNetwork
sn
,
String
login
,
String
password
,
String
title
,
/**
float
mark
,
String
comment
,
String
testId
,
String
errorMessage
)
{
* Checks that reviewItemFilm() returns the expected average after adding a review.
*/
private
static
int
checkReviewItemFilmAverage
(
ISocialNetwork
sn
,
String
login
,
String
password
,
String
title
,
float
mark
,
String
comment
,
float
expectedAverage
,
String
testId
)
{
try
{
try
{
float
avg
=
sn
.
reviewItemFilm
(
login
,
password
,
title
,
mark
,
comment
);
float
avg
=
sn
.
reviewItemFilm
(
login
,
password
,
title
,
mark
,
comment
);
System
.
out
.
println
(
"Test "
+
testId
+
" passed. Avg mark: "
+
avg
);
if
(
Math
.
abs
(
avg
-
expectedAverage
)
<
0.01
)
{
return
0
;
return
0
;
}
catch
(
BadEntryException
|
NotMemberException
|
NotItemException
e
)
{
}
else
{
System
.
out
.
println
(
"Test "
+
testId
+
" threw expected exception: "
+
e
.
getMessage
());
System
.
out
.
println
(
"Err "
+
testId
+
" : Expected average "
+
expectedAverage
+
" but got "
+
avg
);
return
0
;
return
1
;
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Test "
+
testId
+
" failed: "
+
errorMessage
+
" Unexpected exception: "
+
e
);
System
.
out
.
println
(
"Err "
+
testId
+
" : Unexpected exception "
+
e
);
e
.
printStackTrace
();
return
1
;
return
1
;
}
}
}
}
public
static
void
main
(
String
[]
args
)
{
/**
* Checks that reviewItemFilm() throws the expected exception.
*/
private
static
int
checkReviewItemFilmException
(
ISocialNetwork
sn
,
String
login
,
String
password
,
String
title
,
float
mark
,
String
comment
,
Class
<?>
expectedException
,
String
testId
)
{
try
{
sn
.
reviewItemFilm
(
login
,
password
,
title
,
mark
,
comment
);
System
.
out
.
println
(
"Err "
+
testId
+
" : Expected exception "
+
expectedException
.
getSimpleName
()
+
" was not thrown"
);
return
1
;
}
catch
(
Exception
e
)
{
if
(
e
.
getClass
().
equals
(
expectedException
))
{
return
0
;
}
else
{
System
.
out
.
println
(
"Err "
+
testId
+
" : Unexpected exception "
+
e
);
e
.
printStackTrace
();
return
1
;
}
}
}
/**
* Launch all tests for reviewItemFilm().
*/
private
static
TestReport
test
()
{
ISocialNetwork
sn
=
new
SocialNetwork
();
ISocialNetwork
sn
=
new
SocialNetwork
();
int
nbTests
=
0
;
int
nbTests
=
0
;
int
nbErrors
=
0
;
int
nbErrors
=
0
;
try
{
try
{
sn
.
addMember
(
"alice"
,
"strongpass"
,
"cinema lover"
);
sn
.
addMember
(
"Neva"
,
"pass123"
,
"casual reader"
);
sn
.
addItemFilm
(
"alice"
,
"strongpass"
,
"The Matrix"
,
"Sci-Fi"
,
"Wachowski"
,
"Wachowski"
,
136
);
sn
.
addMember
(
"Maryam"
,
"1234pass"
,
"fantasy reader"
);
sn
.
addItemFilm
(
"Neva"
,
"pass123"
,
"Inception"
,
"Sci-Fi"
,
"Nolan"
,
"Nolan"
,
120
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Setup failed: "
+
e
);
System
.
out
.
println
(
"Setup failed: "
+
e
);
return
;
e
.
printStackTrace
();
return
null
;
}
}
// Valid test
System
.
out
.
println
(
"Testing reviewItemFilm()"
);
// Test 4.7: login is null
nbTests
++;
nbErrors
+=
checkReviewItemFilmException
(
sn
,
null
,
"pass123"
,
"Inception"
,
4.0f
,
"Great!"
,
BadEntryException
.
class
,
"4.7"
);
// Test 4.8: password is too short
nbTests
++;
nbErrors
+=
checkReviewItemFilmException
(
sn
,
"Maryam"
,
"12"
,
"Inception"
,
4.0f
,
"Nice!"
,
BadEntryException
.
class
,
"4.8"
);
// Test 4.9: title is null
nbTests
++;
nbErrors
+=
checkReviewItemFilmException
(
sn
,
"Maryam"
,
"1234pass"
,
null
,
4.0f
,
"Awesome!"
,
NotItemException
.
class
,
"4.9"
);
// Test 4.10: member does not exist
nbTests
++;
nbTests
++;
nbErrors
+=
r
eviewItemFilm
Check
(
sn
,
"alice"
,
"strongpass"
,
"The Matrix
"
,
4.
5
f
,
"
Amazing film!
"
,
nbErrors
+=
checkR
eviewItemFilm
Exception
(
sn
,
"unknown"
,
"password"
,
"Inception
"
,
4.
0
f
,
"
Not bad
"
,
"4.1"
,
"Valid review rejected
"
);
NotMemberException
.
class
,
"4.10
"
);
// Test
out of range
// Test
4.11: item does not exist
nbTests
++;
nbTests
++;
nbErrors
+=
r
eviewItemFilm
Check
(
sn
,
"alice"
,
"strongpass"
,
"The Matrix
"
,
6
.0f
,
"
Too high
!"
,
nbErrors
+=
checkR
eviewItemFilm
Exception
(
sn
,
"Maryam"
,
"1234pass"
,
"Unknown Film
"
,
4
.0f
,
"
Great
!"
,
"4.2"
,
"Accepted invalid mark > 5
"
);
NotItemException
.
class
,
"4.11
"
);
// Test
with invalid title
// Test
4.12: first valid review, expect average 4.0
nbTests
++;
nbTests
++;
nbErrors
+=
r
eviewItemFilm
Check
(
sn
,
"alice"
,
"strongpass"
,
"Unknown Film
"
,
3
.0f
,
"
Not found
"
,
nbErrors
+=
checkR
eviewItemFilm
Average
(
sn
,
"Maryam"
,
"1234pass"
,
"Inception
"
,
4
.0f
,
"
Great film!
"
,
"
4.
3"
,
"
Accepted review for nonexistent film
"
);
4.
0f
,
"
4.12
"
);
// Test
with no registered user
// Test
4.13: second review, expect average 3.0
nbTests
++;
nbTests
++;
nbErrors
+=
reviewItemFilmCheck
(
sn
,
"bob"
,
"1234"
,
"The Matrix"
,
3.0f
,
"Hacked!"
,
nbErrors
+=
checkReviewItemFilmAverage
(
sn
,
"Neva"
,
"pass123"
,
"Inception"
,
2.0f
,
"Okay film"
,
"4.4"
,
"Accepted review from non-member"
);
3.0f
,
"4.13"
);
// Print a summary of the tests and return test results
try
{
TestReport
report
=
new
TestReport
(
nbTests
,
nbErrors
);
System
.
out
.
println
(
"ReviewItemBookTest : "
+
report
);
return
report
;
}
catch
(
NotTestReportException
e
)
{
System
.
out
.
println
(
"Failed to create TestReport"
);
return
null
;
}
}
// Resumen
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"\nReviewItemFilmTest summary: "
+
nbErrors
+
" error(s) out of "
+
nbTests
+
"
test(
s)."
);
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