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
Admin message
La purge estivale des projets de gitlab-df sera réalisée jeudi 10 juillet vers 10h.
Show more breadcrumbs
BINTI TENGKU MASRULHISHAM Tengku Maryam Naqeesha
fip112-2025-g41
Commits
46b09cc5
Commit
46b09cc5
authored
1 month ago
by
MASSY FERNANDEZ Neva Aracely
Browse files
Options
Downloads
Patches
Plain Diff
doc: Improve comments on code
parent
25aa8f39
Branches
main
No related tags found
1 merge request
!5
Merge code for Iteration 2 with main
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/tests/AddItemBookTest.java
+37
-91
37 additions, 91 deletions
src/tests/AddItemBookTest.java
with
37 additions
and
91 deletions
src/tests/AddItemBookTest.java
+
37
−
91
View file @
46b09cc5
...
@@ -24,43 +24,27 @@ public class AddItemBookTest {
...
@@ -24,43 +24,27 @@ public class AddItemBookTest {
private
static
int
addItemBookBadEntryTest
(
ISocialNetwork
sn
,
String
login
,
private
static
int
addItemBookBadEntryTest
(
ISocialNetwork
sn
,
String
login
,
String
pwd
,
String
title
,
String
kind
,
String
author
,
int
nbPages
,
String
testId
,
String
errorMessage
)
{
String
pwd
,
String
title
,
String
kind
,
String
author
,
int
nbPages
,
String
testId
,
String
errorMessage
)
{
int
nbBooks
=
sn
.
nbBooks
();
// Number of books when starting to
int
nbBooks
=
sn
.
nbBooks
();
// Number of books when starting to run this method
// run this method
try
{
try
{
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book
// Reaching this point means that no exception was thrown by
System
.
out
.
println
(
"Err "
+
testId
+
" : "
+
errorMessage
);
// display error
// addItemBook()
System
.
out
.
println
(
"Err "
+
testId
+
" : "
+
errorMessage
);
// display
// the
// error
// message
return
1
;
// and return the "error" value
return
1
;
// and return the "error" value
}
catch
(
BadEntryException
e
)
{
// BadEntry exception was thrown by
}
catch
(
BadEntryException
e
)
{
// BadEntry exception was thrown
// addItemBook() : this is a good start!
// check if 'sn' was not impacted
// Let's now check if 'sn' was not
if
(
sn
.
nbBooks
()
!=
nbBooks
)
{
// impacted
if
(
sn
.
nbBooks
()
!=
nbBooks
)
{
// The number of members has
// changed : this is an error
// case.
System
.
out
System
.
out
.
println
(
"Err "
.
println
(
"Err "
+
testId
+
testId
+
" : BadEntry was thrown but the number of books was changed"
);
// Display
+
" : BadEntry was thrown but the number of books was changed"
);
// a
// Display error for the number of books
// specific
// error
// message
return
1
;
// return "error" value
return
1
;
// return "error" value
}
else
}
else
// The number of books hasn't changed, which is considered a
// The number of books hasn't changed,'sn' not modified
// good indicator that 'sn' was not modified
return
0
;
// everything seems OK
return
0
;
// return success value : everything seems OK, nothing
}
catch
(
Exception
e
)
{
// An exception was thrown by addItemBook(), Unexpected exception
// to display
}
catch
(
Exception
e
)
{
// An exception was thrown by addItemBook(), but
// it was not the expected exception BadEntry
System
.
out
.
println
(
"Err "
+
testId
+
" : unexpected exception. "
System
.
out
.
println
(
"Err "
+
testId
+
" : unexpected exception. "
+
e
);
// Display a specific error message
+
e
);
// Display a specific error message
e
.
printStackTrace
();
// Display contextual info about what happened
e
.
printStackTrace
();
return
1
;
// return error value
return
1
;
// return error value
}
}
}
}
...
@@ -81,40 +65,25 @@ public class AddItemBookTest {
...
@@ -81,40 +65,25 @@ public class AddItemBookTest {
private
static
int
addItemBookAlreadyExistsTest
(
ISocialNetwork
sn
,
private
static
int
addItemBookAlreadyExistsTest
(
ISocialNetwork
sn
,
String
login
,
String
pwd
,
String
title
,
String
kind
,
String
author
,
int
nbPages
,
String
testId
,
String
login
,
String
pwd
,
String
title
,
String
kind
,
String
author
,
int
nbPages
,
String
testId
,
String
errorMessage
)
{
String
errorMessage
)
{
int
nbBooks
=
sn
.
nbBooks
();
// Number of members when starting to
int
nbBooks
=
sn
.
nbBooks
();
// Number of members when starting to process this method
// process this method
try
{
try
{
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book that exists
// Reaching this point means that no exception was thrown by
System
.
out
.
println
(
"Err "
+
testId
+
" : "
+
errorMessage
);
// display error message
// addItemBook()
System
.
out
.
println
(
"Err "
+
testId
+
" : "
+
errorMessage
);
// display
// the
// error
// message
return
1
;
// and return the "error" value
return
1
;
// and return the "error" value
}
catch
(
ItemBookAlreadyExistsException
e
)
{
// AlreadyExists exception was
}
catch
(
ItemBookAlreadyExistsException
e
)
{
// AlreadyExists exception was launched
// thrown by addItemBook() :
//checking sn changes
// this is a good start!
// Let's now check if 'sn'
// was not impacted
if
(
sn
.
nbBooks
()
!=
nbBooks
)
{
if
(
sn
.
nbBooks
()
!=
nbBooks
)
{
System
.
out
System
.
out
.
println
(
"Err "
.
println
(
"Err "
+
testId
+
testId
+
" : ItemBookAlreadyExists was thrown, but the number of books was changed"
);
// Display
+
" : ItemBookAlreadyExists was thrown, but the number of books was changed"
);
// Display
// a
// error message
// specific
return
1
;
// error value assigned
// error
// message
return
1
;
// and return the "error" value
}
else
}
else
return
0
;
//
return success value : everything is OK, nothing to
return
0
;
//
OK value
// display
// display
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember(), but
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember()
// it was not the expected exception
System
.
out
.
println
(
"Err "
+
testId
+
" : unexpected exception. "
+
e
);
// Display unexpected exception
// AlreadyExists
System
.
out
.
println
(
"Err "
+
testId
+
" : unexpected exception. "
+
e
);
// Display a specific error message
e
.
printStackTrace
();
// Display contextual info about what happened
e
.
printStackTrace
();
// Display contextual info about what happened
return
1
;
// return error value
return
1
;
// return error value
}
}
...
@@ -135,27 +104,20 @@ public class AddItemBookTest {
...
@@ -135,27 +104,20 @@ public class AddItemBookTest {
*/
*/
private
static
int
addItemBookOKTest
(
ISocialNetwork
sn
,
String
login
,
private
static
int
addItemBookOKTest
(
ISocialNetwork
sn
,
String
login
,
String
pwd
,
String
title
,
String
kind
,
String
author
,
int
nbPages
,
String
testId
)
{
String
pwd
,
String
title
,
String
kind
,
String
author
,
int
nbPages
,
String
testId
)
{
int
nbBooks
=
sn
.
nbBooks
();
// Number of books when starting to
int
nbBooks
=
sn
.
nbBooks
();
// Number of books
// process this method
try
{
try
{
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book
// No exception was thrown. That's a good start !
if
(
sn
.
nbBooks
()
!=
nbBooks
+
1
)
{
// Number does not changed
if
(
sn
.
nbBooks
()
!=
nbBooks
+
1
)
{
// But the number of books
// hasn't changed
// accordingly
System
.
out
.
println
(
"Err "
+
testId
System
.
out
.
println
(
"Err "
+
testId
+
" : the number of books ("
+
nbBooks
+
" : the number of books ("
+
nbBooks
+
") was not incremented"
);
// Error message displayed
+
") was not incremented"
);
// Error message displayed
return
1
;
// return error code
return
1
;
// return error code
}
else
}
else
return
0
;
// return
success code : everything is OK, nothing to
return
0
;
// return
OK code
// display
// display
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember() : this
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember()
// is an error case
System
.
out
System
.
out
.
println
(
"Err "
+
testId
+
" : unexpected exception "
+
e
);
// Error
.
println
(
"Err "
+
testId
+
" : unexpected exception "
+
e
);
// Error message
// message
// displayed
e
.
printStackTrace
();
// Display contextual info about what happened
e
.
printStackTrace
();
// Display contextual info about what happened
return
1
;
// return error code
return
1
;
// return error code
}
}
...
@@ -181,31 +143,20 @@ public class AddItemBookTest {
...
@@ -181,31 +143,20 @@ public class AddItemBookTest {
// process this method
// process this method
try
{
try
{
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book
sn
.
addItemBook
(
login
,
pwd
,
title
,
kind
,
author
,
nbPages
);
// Try to add this book
// Reaching this point means that no exception was thrown by
// Reaching this point means that no exception was thrown by addItemBook()
// addItemBook()
System
.
out
.
println
(
"Err "
+
testId
+
" : "
+
errorMessage
);
// display error message
System
.
out
.
println
(
"Err "
+
testId
+
" : "
+
errorMessage
);
// display
// the
// error
// message
return
1
;
// and return the "error" value
return
1
;
// and return the "error" value
}
catch
(
NotMemberException
e
)
{
// AlreadyExists exception was
}
catch
(
NotMemberException
e
)
{
// AlreadyExists exception was thrown by addItemBook() :
// thrown by addItemBook() :
//check if 'sn' was not impacted
// this is a good start!
// Let's now check if 'sn'
// was not impacted
if
(
sn
.
nbBooks
()
!=
nbBooks
)
{
if
(
sn
.
nbBooks
()
!=
nbBooks
)
{
System
.
out
System
.
out
.
println
(
"Err "
.
println
(
"Err "
+
testId
+
testId
+
" : NotMember was thrown, but the number of books was changed"
);
// Display
+
" : NotMember was thrown, but the number of books was changed"
);
// Display
// a
// a error message launched
// specific
// error
// message
return
1
;
// and return the "error" value
return
1
;
// and return the "error" value
}
else
}
else
return
0
;
// return success value : everything is OK, nothing to
return
0
;
// return OK value
// display
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember(), but
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember(), but
// it was not the expected exception
// it was not the expected exception
// AlreadyExists
// AlreadyExists
...
@@ -241,14 +192,10 @@ public class AddItemBookTest {
...
@@ -241,14 +192,10 @@ public class AddItemBookTest {
+
") was not incremented"
);
// Error message displayed
+
") was not incremented"
);
// Error message displayed
return
1
;
// return error code
return
1
;
// return error code
}
else
}
else
return
0
;
// return success code : everything is OK, nothing to
return
0
;
// return success code
// display
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember() : error case
}
catch
(
Exception
e
)
{
// An exception was thrown by addMember() : this
// is an error case
System
.
out
System
.
out
.
println
(
"Err "
+
testId
+
" : unexpected exception "
+
e
);
// Error
.
println
(
"Err "
+
testId
+
" : unexpected exception "
+
e
);
// Error message
// message
// displayed
e
.
printStackTrace
();
// Display contextual info about what happened
e
.
printStackTrace
();
// Display contextual info about what happened
return
1
;
// return error code
return
1
;
// return error code
}
}
...
@@ -268,8 +215,7 @@ public class AddItemBookTest {
...
@@ -268,8 +215,7 @@ public class AddItemBookTest {
System
.
out
.
println
(
"Testing addItemBook()"
);
System
.
out
.
println
(
"Testing addItemBook()"
);
// <=> test n°1
// <=> test n°1
// check if incorrect parameters cause addItemBook() to throw BadEntry
// check if incorrect parameters cause addItemBook() to throw BadEntry exception
// exception
//populate 'sn' with 3 members
//populate 'sn' with 3 members
nbErrors
+=
addMemberOKTest
(
sn
,
"Paul"
,
"paul"
,
"Student"
,
"1.0a"
);
nbErrors
+=
addMemberOKTest
(
sn
,
"Paul"
,
"paul"
,
"Student"
,
"1.0a"
);
...
@@ -357,7 +303,7 @@ public class AddItemBookTest {
...
@@ -357,7 +303,7 @@ public class AddItemBookTest {
System
.
out
.
println
(
"AddItemBookTest : "
+
tr
);
System
.
out
.
println
(
"AddItemBookTest : "
+
tr
);
return
tr
;
return
tr
;
}
}
catch
(
NotTestReportException
e
){
//This shouldn't happen
catch
(
NotTestReportException
e
){
System
.
out
.
println
(
"Unexpected error in AddMemberTest test code - Can't return valuable test results"
);
System
.
out
.
println
(
"Unexpected error in AddMemberTest test code - Can't return valuable test results"
);
return
null
;
return
null
;
}
}
...
...
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